我正在将现有代码库从 IplImage* 更新到较新的 cv::Mat。我想知道如何向 MFC 显示我的 cv::Mat 对象。我们当前使用的解决方案基于旧的 CvvImage 类:
void DrawPicToHDC(IplImage *img, UINT ID, bool bOnPaint)
{
CDC *pDC = GetDlgItem(ID)->GetDC();
HDC hDC= pDC->GetSafeHdc();
CRect rect;
GetDlgItem(ID)->GetClientRect(&rect);
CvvImage cimg;
cimg.CopyOf( img );
cimg.DrawToHDC( hDC, &rect );
ReleaseDC( pDC );
}
Run Code Online (Sandbox Code Playgroud)
我遇到了这个线程,但不幸的是,提供的答案不能满足我的需求,因为答案仍然要求您在显示之前将 Mat 转换为 IplImage* 。
有没有办法只使用 cv::Mat 来做到这一点?任何帮助深表感谢。
更新: 在 Kornel 答案的帮助下,我将上述函数调整为使用 cv::Mat 。我现在不需要包含 CvvImage 类:
void DrawPicToHDC(cv::Mat cvImg, UINT ID, bool bOnPaint)
{
// Get the HDC handle information from the ID passed
CDC *pDC = …Run Code Online (Sandbox Code Playgroud)