OpenCV和MFC的完美结合

来源:互联网 发布:java代码动态分析工具 编辑:程序博客网 时间:2024/05/18 03:27

Mat depthImage;

IplImage ipl_img = depthImage;

//将OpenCV格式的图像直接显示在MFC对话框上

void CXXXDlg::OnShowImage(IplImage* img, UINT ID)

{
    CDC* pDC = GetDlgItem(ID)->GetDC(); // 获得显示控件的DC
    HDC hdc = pDC->GetSafeHdc(); // 获取 HDC(设备句柄) 来进行绘图操作
    CRect rect;
    GetDlgItem(ID)->GetClientRect( &rect );
    int rw = rect.right - rect.left; // 求出图片控件的宽和高
    int rh = rect.bottom - rect.top;
    int iw = img->width; // 读取图片的宽和高
    int ih = img->height;
    int tx = (int)(rw - iw)/2; // 使图片的显示位置正好在控件的正中
    int ty = (int)(rh - ih)/2;
    SetRect( rect, tx, ty, tx+iw, ty+ih );
    CvvImage cimg;
    cimg.CopyOf( img ); // 复制图片
    cimg.DrawToHDC( hdc, &rect ); // 将图片绘制到显示控件的指定区域内
    ReleaseDC( pDC );

}

需要在工程中使用CvvImage类!

原创粉丝点击