概述
void COpenCvVoiceMatDlg::BitMatToWnd(CDC *pDC, Mat &img, RECT* pRect)
{
if( pDC && pRect && !img.empty() )
{
uchar buffer[sizeof(BITMAPINFOHEADER) + 1024];
BITMAPINFO* bmi = (BITMAPINFO*)buffer;
int bmp_w = img.cols, bmp_h = img.rows;
BITMAPINFOHEADER* bmih = &(bmi->bmiHeader);
memset( bmih, 0, sizeof(*bmih));
bmih->biSize = sizeof(BITMAPINFOHEADER);
bmih->biWidth = bmp_w;
bmih->biHeight = -bmp_h;// : -abs(height);
bmih->biPlanes = 1;
bmih->biBitCount = IPL_DEPTH_8U*img.channels();
bmih->biCompression = BI_RGB;
if( IPL_DEPTH_8U*img.channels() == 8 )
{
RGBQUAD* palette = bmi->bmiColors;
int i;
for( i = 0; i < 256; i++ )
{
palette[i].rgbBlue = palette[i].rgbGreen = palette[i].rgbRed = (BYTE)i;
palette[i].rgbReserved = 0;
}
}
if(pRect->right - pRect->left +1 < bmp_w )
{
SetStretchBltMode(
pDC->m_hDC, // handle to device context
HALFTONE );
}
else
{
SetStretchBltMode(
pDC->m_hDC, // handle to device context
COLORONCOLOR );
}
if(img.cols % 4 != 0 && img.isContinuous())
{
IplImage *tempimg = cvCreateImage(img.size(), 8, img.channels());
img.copyTo(Mat(tempimg));
::StretchDIBits(
pDC->m_hDC,
pRect->left, pRect->top, pRect->right - pRect->left+1, pRect->bottom - pRect->top+1,
0, 0, bmp_w, bmp_h,
tempimg->imageData, bmi, DIB_RGB_COLORS, SRCCOPY );
cvReleaseImage(&tempimg);
}
else
{
::StretchDIBits(
pDC->m_hDC,
pRect->left, pRect->top, pRect->right - pRect->left+1, pRect->bottom - pRect->top+1,
0, 0, bmp_w, bmp_h,
img.data, bmi, DIB_RGB_COLORS, SRCCOPY );
}
}
return;
}
最后
以上就是霸气皮卡丘为你收集整理的实现MFC显示CV::Mat的函数的全部内容,希望文章能够帮你解决实现MFC显示CV::Mat的函数所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复