void FillBitmapInfo( BITMAPINFO *bmi, int width, int height, int bpp )
{
ASSERT( bmi && width > 0 && height > 0 &&
(bpp == 8 || bpp == 24 || bpp == 32) );
BITMAPINFOHEADER* bmih = &(bmi->bmiHeader);
memset( bmih, 0, sizeof(*bmih));
bmih->biSize = sizeof(BITMAPINFOHEADER);
bmih->biWidth = width;
bmih->biHeight = -abs(height);
bmih->biPlanes = 1;
bmih->biBitCount = bpp;
bmih->biCompression = BI_RGB;
if( bpp == 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;
}
}
}
void ShowImage(IplImage *pImg, CWnd *wnd, BITMAPINFO &bmi)
{
CDC *pDC = wnd->GetDC();
HDC hDC = pDC->GetSafeHdc();
CRect rect;
wnd->GetClientRect(&rect);
printf("rect:%d %d %d %d\n",rect.top
,rect.left,rect.bottom,rect.right);
if(bmi.bmiHeader.biBitCount== 8)
{
CPalette pal;
HPALETTE hpal=NULL;
HPALETTE hOldPal=NULL;
::SetPaletteEntries(hpal,0,256,(LPPALETTEENTRY)bmi.bmiColors);
hOldPal = ::SelectPalette(pDC->GetSafeHdc(), hpal, TRUE);
}
//显示
::SetStretchBltMode(pDC->m_hDC, COLORONCOLOR);
::StretchDIBits(pDC->GetSafeHdc(),rect.left,rect.top,rect.right,rect.bottom,0,0,
pImg->width,pImg->height,pImg->imageData,&bmi,DIB_RGB_COLORS,SRCCOPY);
}
DWORD WINAPI LPR_VideoFile_thread(LPVOID data)
{
IplImage *pFrame=NULL;
BITMAPINFO bmi;
IplImage *full_img = NULL;
full_img = cvCreateImage(cvSize(360,288),8,3);
CWnd *CW = CWnd::FromHandle(dlg->VideoAnalysis.m_Screen.m_wndVideo[0].m_hWnd);
FillBitmapInfo(&bmi, full_img->width, full_img->height, full_img->depth*full_img-
>nChannels);
while(1)
{
pFrame = cvQueryFrame( capture );
if (pFrame == NULL)
{
printf("pFrame == NULL\n");
return -1;
}
cvResize(pFrame,full_img);
ShowImage(full_img,CW, bmi);
Sleep(10);
}
cvReleaseImage(&full_img);
return 0;
}
3 个解决方案
#1
根据opencv的错误提示去opencv源代码中找
#2
::SetStretchBltMode(pDC->m_hDC, COLORONCOLOR);
::StretchDIBits(pDC->GetSafeHdc(),rect.left,rect.top,rect.right,rect.bottom,0,0,
pImg->width,pImg->height,pImg->imageData,&bmi,DIB_RGB_COLORS,SRCCOPY);
错误就在这两句上面,我同时屏蔽这两句时程序可以持久运行,但只要加了这两句中的任何一句程序在执行一段时间后都会内存错误
::StretchDIBits(pDC->GetSafeHdc(),rect.left,rect.top,rect.right,rect.bottom,0,0,
pImg->width,pImg->height,pImg->imageData,&bmi,DIB_RGB_COLORS,SRCCOPY);
错误就在这两句上面,我同时屏蔽这两句时程序可以持久运行,但只要加了这两句中的任何一句程序在执行一段时间后都会内存错误
#3
我也在使用这两个函数时遇到了同样的问题,http://topic.csdn.net/u/20120511/11/f5c824d9-9389-4727-8fc3-ff330309dc8b.html,垂直不同步就算了,旦我用任务管理器查看,内存急剧增长,不出一会就回错误
#1
根据opencv的错误提示去opencv源代码中找
#2
::SetStretchBltMode(pDC->m_hDC, COLORONCOLOR);
::StretchDIBits(pDC->GetSafeHdc(),rect.left,rect.top,rect.right,rect.bottom,0,0,
pImg->width,pImg->height,pImg->imageData,&bmi,DIB_RGB_COLORS,SRCCOPY);
错误就在这两句上面,我同时屏蔽这两句时程序可以持久运行,但只要加了这两句中的任何一句程序在执行一段时间后都会内存错误
::StretchDIBits(pDC->GetSafeHdc(),rect.left,rect.top,rect.right,rect.bottom,0,0,
pImg->width,pImg->height,pImg->imageData,&bmi,DIB_RGB_COLORS,SRCCOPY);
错误就在这两句上面,我同时屏蔽这两句时程序可以持久运行,但只要加了这两句中的任何一句程序在执行一段时间后都会内存错误
#3
我也在使用这两个函数时遇到了同样的问题,http://topic.csdn.net/u/20120511/11/f5c824d9-9389-4727-8fc3-ff330309dc8b.html,垂直不同步就算了,旦我用任务管理器查看,内存急剧增长,不出一会就回错误