I'm trying to use pictureBox->Image (Windows Forms) to display a cv::Mat image (openCV). I want to do that without saving the Image as a file ('cause i want to reset the image every 100ms). I just found that topic here: How to display a cv::Mat in a Windows Form application?
When i use this solution the image appears to be white only. I guess i took the wrong PixelFormat. So how do figure out the PixelFormat i need? Haven't seen any Method in cv::Mat to get info about that. Or does this depend on the image Source i use to create this cv::Mat? Thanks so far :)
Here i took a screen. Its not completely white. So i guess there is some color info. But maybe i'm wrong. Screen
cv::Mat.depth() returns the pixel type, eg. CV_8U for 8bit unsigned etc. and cv::Mat.channels() returns the number of channels, typically 3 for a colour image
For 'regular images' opencv generally uses 8bit BGR colour order which should map directly onto a Windows bitmap or most Windows libs.
SO you probably want system.drawing.imaging.pixelformat.Format24bppRgb, I don't know what order ( RGB or BGR) it uses but you can use the opencv cv::cvtColor() with CV_BGR2RGB to convert to RGB
Thanks for the help! The problem was something else.
I just did not allocate memory for the Image Object. So there was nothing to really display.
Using cv::Mat img;
in the headerFile and img = new cv::Mat(120,160,0);
in Constructor (ocvcamimg Class) got it to work. (ocvcamimg->captureCamMatImg()
returns img
).
来源:https://stackoverflow.com/questions/10850492/cvmat-detect-pixelformat