FlyCapture to IplImage
- Library/opencv
- 2013. 10. 5.
FlyCapture to IplImage로 저장하는 방법.
UINT CFlyCapThrDlg::GrabLoop(void) { int i,j; // bbumblebee2 해상도 int width=1024; int height=768; FlyCaptureError error; error = flycaptureCreateContext(&pContext); error = flycaptureInitialize(pContext, 0); //error = flycaptureStart(pContext,FLYCAPTURE_VIDEOMODE_640x480Y16,FLYCAPTURE_FRAMERATE_30); // 두개의 이미지를 받으려면 custom image 모드(mode 3,raw16) 사용 error=flycaptureStartCustomImage(pContext,3,0,0,width,height,100.0f,FLYCAPTURE_RAW16); pImageBGR.pixelFormat = FLYCAPTURE_BGRU; pImageBGR.pData = new unsigned char[2248*2048*3]; CDC *pDC; BITMAPINFO bitmapInfo; pDC=GetDC(); bitmapInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); bitmapInfo.bmiHeader.biPlanes=1; bitmapInfo.bmiHeader.biCompression=BI_RGB; bitmapInfo.bmiHeader.biXPelsPerMeter=100; bitmapInfo.bmiHeader.biYPelsPerMeter=100; bitmapInfo.bmiHeader.biClrUsed=0; bitmapInfo.bmiHeader.biClrImportant=0; bitmapInfo.bmiHeader.biBitCount=32; bitmapInfo.bmiHeader.biSizeImage=0; cvNamedWindow("left"); cvNamedWindow("right"); IplImage* pImageLeft=cvCreateImage(cvSize(width,height),8,3); IplImage* pImageRight=cvCreateImage(cvSize(width,height),8,3); while(m_ThreadContinue) { flycaptureGrabImage2(pContext,&pImage); flycaptureConvertImage(pContext,&pImage,&pImageBGR); for(i=0;iimageDataOrigin[(i*width+j)*3]=pImageBGR.pData[(i*width*2+j)*4]; pImageLeft->imageDataOrigin[(i*width+j)*3+1]=pImageBGR.pData[(i*width*2+j)*4+1]; pImageLeft->imageDataOrigin[(i*width+j)*3+2]=pImageBGR.pData[(i*width*2+j)*4+2]; pImageRight->imageDataOrigin[(i*width+j)*3]=pImageBGR.pData[(i*width*2+width+j)*4]; pImageRight->imageDataOrigin[(i*width+j)*3+1]=pImageBGR.pData[(i*width*2+width+j)*4+1]; pImageRight->imageDataOrigin[(i*width+j)*3+2]=pImageBGR.pData[(i*width*2+width+j)*4+2]; } } cvShowImage("left",pImageLeft); cvWaitKey(1); cvShowImage("right",pImageRight); cvWaitKey(1); bitmapInfo.bmiHeader.biWidth=pImageBGR.iCols; bitmapInfo.bmiHeader.biHeight=-pImageBGR.iRows; //::StretchDIBits( pDC->GetSafeHdc(),0, 0, pImageBGR.iCols, pImageBGR.iRows, 0, 0, pImageBGR.iCols, pImageBGR.iRows, pImageBGR.pData, &bitmapInfo, DIB_RGB_COLORS, SRCCOPY ); } cvDestroyWindow("left"); cvDestroyWindow("right"); cvReleaseImage(&pImageLeft); cvReleaseImage(&pImageRight); delete[] pImageBGR.pData; SetEvent(m_heventThreadDone); return 0; }
UINT CFlyCapThrDlg::GrabLoop(void) { FlyCaptureError error; error = flycaptureCreateContext(&pContext); error = flycaptureInitialize(pContext, 0); error = flycaptureStart(pContext,FLYCAPTURE_VIDEOMODE_ANY,FLYCAPTURE_FRAMERATE_ANY); //error=flycaptureStartCustomImage(pContext,3,0,0,width,height,100.0f,FLYCAPTURE_RAW16); pImageBGR.pixelFormat = FLYCAPTURE_BGR; pImageBGR.pData = new unsigned char[2248*2048*3]; cvNamedWindow("image"); while(m_ThreadContinue) { flycaptureGrabImage2(pContext,&pImage); flycaptureConvertImage(pContext,&pImage,&pImageBGR); // OpenCV IplImage에 image data 복사 IplImage* pcvImage=cvCreateImage(cvSize(pImageBGR.iCols,pImageBGR.iRows),8,3); memcpy(pcvImage->imageDataOrigin,pImageBGR.pData,pImageBGR.iRowInc*pImageBGR.iRows); ShowFPS(pcvImage); cvShowImage("image",pcvImage); cvWaitKey(1); cvReleaseImage(&pcvImage); } cvDestroyWindow("image"); flycaptureStop(pContext); flycaptureDestroyContext(pContext); delete[] pImageBGR.pData; SetEvent(m_heventThreadDone); return 0; }
float CFlyCapThrDlg::ShowFPS( IplImage *image ) { int new_time, delay_time; float fps; char cfps[20]; CvFont *font = new CvFont; memset( &cfps, 0, sizeof(cfps)); cvInitFont(font, CV_FONT_VECTOR0, 1.0f, 1.0f, 0, 3); // test fps new_time = GetTickCount(); delay_time = new_time - m_old_time; fps = 1000.f / (float)delay_time; m_old_time = new_time; sprintf_s(cfps, "%5.2lf", fps); cvPutText( image, cfps, cvPoint(100,100),font, CV_RGB(255,0,0) ); delete font; return fps; }
'Library > opencv' 카테고리의 다른 글
openCV ROI 영역에 관해 (0) | 2013.11.13 |
---|---|
opencv2.4.6 버전 Problem (0) | 2013.10.24 |
opencv Video Videowriter (0) | 2013.05.11 |
[opencv 2.4.3] Image ROI (0) | 2013.04.15 |
lib svm (0) | 2013.01.25 |