FlyCapture to IplImage

Author : 퓨림노 / Date : 2013.10.05 16:03 / Category : before/Develop

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;
}





저작자 표시 비영리 동일 조건 변경 허락
신고

Tags :

Blog Information

퓨림노

앞으로 블로그에 markdown+dropbox를 이용하여 포스팅 예정중!!

Search

Statistics

  • Total : 455,012
  • Today : 41
  • Yesterday : 120

Archives

Copyright © http://vbflash.net All Rights Reserved
Designed by CMSFactory.NET