There was a class named cvvimage before opencv 2.2 that can display iplimage in MFC, but this class has disappeared since Version 2.2, and some people continue to use the code of previous versions, however, this is not very convenient. For example, you have to convert mat to iplimage in C ++. For this reason, I found some materials and finally solved the problem of displaying CV: mat in various windows forms, which makes it much easier to use. Here, we will share it with anyone who needs it. This article is original. Please enter the address for reprinting. Thank you ~
Address: http://blog.csdn.net/houston11235/article/details/7678088
The following function is used to display the mat function in the form of MFC or C #. The reason is that no matter what the programming language is, windows Forms all have something called a handle (corresponding to handle in C #). Just pass this as the second parameter of the function.
This function uses the cimage class in ATL and must reference the header file atlimage. h. Note that this should be placed in CV. h. It is best to put it in front of Shenma on Windows. otherwise, 'Min' and 'Max' undefined errors will occur during compilation.
In addition, this function only enables 3-channel image display. For 1-channel images, see the final link of this article.
Int showmat (CV: mat IMG, hwnd hwnddisplay) {If (IMG. channels () <3) {return-1;} rect; getclientrect (hwnddisplay, & rect); CV: mat imgshow (ABS (rect. top-rect. bottom), ABS (rect. right-rect. left), cv_8uc3); resize (IMG, imgshow, imgshow. size (); ATL: cimage ci; int W = imgshow. cols; // width int H = imgshow. rows; // high int channels = imgshow. channels (); // number of channels CI. create (W, h, 8 * channels); uchar * pS; uchar * pimg = (uchar *) CI. getbits (); // obtain the cimage data zone address int step = CI. getpitch (); For (INT I = 0; I
Reference link: http://www.opencv.org.cn/forum/viewtopic.php? F = 1 & t = 15224