OPENCV in the MFC framework, it is unavoidable to use the picture control to display pictures, but the picture control displays the image's basic unit is the screen coordinate system, if you need to get a pixel coordinate system, only one simple step to convert. Of course, if it is opencv2.0 and above, you need to use cvvimage this class, online can be downloaded to.
The core idea of coordinate transformation is to make a simple conversion according to the ratio between the size of the client area of the picture space and the actual size of the image that needs to be displayed, the code is as follows:
1 /*get customer Area coordinates2 */3 CRect rect_ctr; 4(GetDlgItem (Idc_imgshow))->getwindowrect (&rect_ctr);5 screentoclient (RECT_CTR); 6Point.x = Point.x-Rect_ctr.left; 7Point.y = Point.y-Rect_ctr.top; 8 9 /*Convert screen coordinates to pixel coordinatesTen * Point.x and POINT.Y the client area screen coordinates for the current mouse One * m_icoordinate_pixel_x, such as converted pixel coordinates, the use of image and customer area coordinate relationship transformation A */ -m_icoordinate_pixel_x = Point.x * M_iimage_width/(Rect_ctr.right-rect_ctr.left); -m_icoordinate_pixel_y = Point.y * M_iimage_height/(rect_ctr.bottom-rect_ctr.top);
Where Idc_imgshow is the picture control's id,m_iimage_width and m_iimage_height are two shaping variables, representing the original width and height (that is, the number of columns and rows) of the image to be displayed.
Picture control coordinate transformation in MFC