How to display a cv::Mat in a Windows Form application?

前端 未结 1 1429
情歌与酒
情歌与酒 2020-12-10 20:47

I tried to use imwrite to successfully to display an image on a Windows Form, but it damages the disk, so I need a better way to do this.

Below, is my c

相关标签:
1条回答
  • 2020-12-10 21:07

    It is definitely a good idea to get away from writing the image to a file and then immediately reading back onto a control. It is quite inefficient as the hard drive is the slowest memory device in the system usually.

    I do not believe you are using the correct Bitmap constructor in your example above. You should probably be using this constructor definition. Also, telling the Bitmap object that the PixelFormat is undefined is probably not helping things either. I'm assuming you have a color camera that is returning a CV_8UC3 matrix (i.e., your PixelFormat == Format24bppRgb).

    How about try a call like this:

    this->panel1->BackgroundImage = gcnew System::Drawing::Bitmap(frame.size().width,
                                                                  frame.size().height,
                                                                  frame.step,
                                                                  PixelFormat::Format24bppRgb,
                                                                  (IntPtr)frame.data);
    

    Also, remember that OpenCV natively stores color in BGR format. So, you may need to swap the red and blue channels to get the data to look right.

    Hopefully, that will get you started!

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题