您的位置:首页 > 运维架构

OpenCV和MFC的完美结合

2013-03-21 23:48 489 查看
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类!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: