windows程序显示opencv的IplImage

先贴下关键代码,后面来完善

void ShowMFC( IplImage *img, CDC *pDC,CRect dets_rect, CVideoPlayDlg* video_tmp )
{
	DWORD height=img->height;	
	DWORD width=img->width;

	int widNew = width - width % 4; //  凑成4的倍数,否则宽度不是4的倍数导致播放不正常
	IplImage *realBgrImg = cvCreateImage(cvSize(widNew, height), IPL_DEPTH_8U, 3);
	cvResize(img, realBgrImg);

	BITMAPINFO bi;
	memset(&bi.bmiHeader, 0, sizeof(BITMAPINFOHEADER));
	bi.bmiHeader.biBitCount=24;

	bi.bmiHeader.biCompression= BI_RGB;
	bi.bmiHeader.biHeight= -height;
	bi.bmiHeader.biPlanes=1;
	bi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);

	bi.bmiHeader.biWidth=widNew;


	if(video_tmp->FLAG_C){
		::SetStretchBltMode(pDC->m_hDC, COLORONCOLOR);
		::StretchDIBits(pDC->GetSafeHdc(), 0, 0, dets_rect.Width(),dets_rect.Height(), 
			0, 0, widNew, height, realBgrImg->imageData,
			(BITMAPINFO*)&bi,DIB_RGB_COLORS,SRCCOPY);
	}

}


你可能感兴趣的:(C++,数字图像处理)