Displaying webcam feed in cv::Mat format in a picturebox

后端 未结 1 704
长情又很酷
长情又很酷 2020-12-06 19:12

I am using OpenCV to take a live stream from a webcam and after detecting faces. I am resizing them so that only my face is displayed.

But the problem is that I am

相关标签:
1条回答
  • 2020-12-06 19:28

    Here is a C++ CLR function to draw OpenCV mat on any Windows Form Control:

    void DrawCVImage(System::Windows::Forms::Control^ control, cv::Mat& colorImage)
    {
        System::Drawing::Graphics^ graphics = control->CreateGraphics();
        System::IntPtr ptr(colorImage.ptr());
        System::Drawing::Bitmap^ b  = gcnew System::Drawing::Bitmap(colorImage.cols,colorImage.rows,colorImage.step,System::Drawing::Imaging::PixelFormat::Format24bppRgb,ptr);
        System::Drawing::RectangleF rect(0,0,control->Width,control->Height);
        graphics->DrawImage(b,rect);
        delete graphics;
    }
    

    This function can only draw 8 bit 3 channel images.

    Try experimenting with Pixel Format of the bitmap for other image types.

    0 讨论(0)
提交回复
热议问题