I intent to use OpenCV into MFC app, when to render images and videos ... I have used cv::Mat to load images into app, but when I draw image into CView, here is the result:
opened with any viewer, the image are look like this:
I have used this code:
void CTestOpenView::OnDraw(CDC* pDC)
{
CTestOpenDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(NULL == pDoc || NULL == pDoc->m_pMat)
return;
// TODO: add draw code for native data here
// Create BitmapInfo
BITMAPINFO bmi;
BITMAPINFOHEADER* pHeader= &bmi.bmiHeader;
pHeader->biSize = sizeof(BITMAPINFOHEADER);
pHeader->biPlanes = 1;
pHeader->biCompression = BI_RGB;
pHeader->biXPelsPerMeter = 100;
pHeader->biYPelsPerMeter = 100;
pHeader->biClrUsed = 0;
pHeader->biClrImportant = 0;
pHeader->biWidth = pDoc->m_pMat->cols;
pHeader->biHeight = -pDoc->m_pMat->rows;
pHeader->biBitCount = 24;
bmi.bmiHeader.biSizeImage = 0;
CRect rect;
GetClientRect(&rect);
StretchDIBits(pDC->m_hDC, 0, 0, rect.Width(), rect.Height(),
0, 0, rect.Width(), rect.Height(), pDoc->m_pMat->data, &bmi, DIB_RGB_COLORS, SRCCOPY);
}
and in CTestOpenDoc I have
cv::Mat* m_pMat;
nothing special ... why this image are not show correctly as color and size, and other show correctly ?