Error error;
Camera camera;
// Get the imageerror=camera.Connect(NULL);//灰点的库函数调用,检测相机error=camera.StartCapture();//开启相机
char key = 0;
int i=0;
while(1)
{
Image rawImage;
error = camera.RetrieveBuffer( &rawImage );//捕获帧if (error!=PGRERROR_OK)
{
AfxMessageBox("Capture error!");捕获失败弹出错误
continue;
}
// convert to rgb Kevin的例子,图像格式转换
Image rgbImage;
rawImage.Convert( FlyCapture2::PIXEL_FORMAT_BGR, &rgbImage );
// convert to OpenCV Mat
unsigned int rowBytes = (double)rgbImage.GetReceivedDataSize()/(double)rgbImage.GetRows();
cv::Mat image = cv::Mat(rgbImage.GetRows(), rgbImage.GetCols(), CV_8UC3, rgbImage.GetData(),rowBytes);
//cv::imshow("image", image);
IplImage *pImg=cvLoadImage("Lre.bmp");//在MFC中定义了一个显示控件,m_picture为控件的成员变量*pImg=IplImage(image);
CDC* pDC = m_picture.GetWindowDC();
CvvImage limg;
CRect rect;
m_picture.GetClientRect(&rect);
limg.CopyOf(pImg);
limg.DrawToHDC(pDC -> m_hDC,&rect);
key = cv::waitKey(30);
}
if (error!=PGRERROR_OK)
{
}
camera.Disconnect();
打开双目PointGrey相机
Error error;
BusManager busMgr;
unsigned int numCameras=0;
error=busMgr.GetNumOfCameras(&numCameras);//检测相机个数if (error!=PGRERROR_OK)
{
AfxMessageBox("Insufficient number of cameras");
}
Camera** ppCameras = new Camera*[numCameras];
// Connect to all detected cameras and attempt to set them to// a common video mode and frame ratefor (unsigned int i = 0; i < numCameras; i++)
{
ppCameras[i] = new Camera();
PGRGuid guid;
error = busMgr.GetCameraFromIndex( i, &guid );//获取每个相机的唯一ID// Connect to a cameraerror = ppCameras[i]->Connect( &guid );//连接相机if (error != PGRERROR_OK)
{
AfxMessageBox("GUID=NO!");
}
// Set all cameras to a specific mode and frame rate so they// can be synchronized
CameraInfo camInfo;
error = ppCameras[i]->GetCameraInfo( &camInfo );//获取相机的基本信息,可以忽略if (error != PGRERROR_OK)
{
AfxMessageBox("INFORMATION ERROR");
}
// error = ppCameras[i]->SetVideoModeAndFrameRate( VIDEOMODE_1600x1200Y8,FRAMERATE_15 );//if (error!=PGRERROR_OK)// {// AfxMessageBox("MODEL error!");// }
}
//Camera cameras;//error = cameras.StartSyncCapture( numCameras, (const Camera**)ppCameras,NULL,NULL );//works for FireWire cameras,not work for USB cameraserror=ppCameras[0]->StartCapture();//开始拍照error=ppCameras[1]->StartCapture();
if (error!=PGRERROR_OK)
{
AfxMessageBox("Startcapture error!");
}
char key = 0;
int i=0;
while(1)
{
//Image rawImage;
Image image0,image1;
error=ppCameras[0]->RetrieveBuffer( &image0 );//获取下一帧图像error=ppCameras[1]->RetrieveBuffer( &image1 );
if (error!=PGRERROR_OK)
{
AfxMessageBox("RetrieveBuffer error!");
}
// convert to rgb
Image rgbImage0,rgbImage1;
//BMPOption option;//指定存储的图像
image0.Convert( FlyCapture2::PIXEL_FORMAT_BGR, &rgbImage0 );
image1.Convert( FlyCapture2::PIXEL_FORMAT_BGR, &rgbImage1 );
// convert to OpenCV Mat对图像进行压缩,转换成CV矩阵
unsigned int rowBytes0 = (double)rgbImage0.GetReceivedDataSize()/(double)rgbImage0.GetRows();
cv::Mat imageR = cv::Mat(rgbImage0.GetRows(), rgbImage0.GetCols(), CV_8UC3, rgbImage0.GetData(),rowBytes0);
unsigned int rowBytes1 = (double)rgbImage1.GetReceivedDataSize()/(double)rgbImage1.GetRows();
cv::Mat imageL = cv::Mat(rgbImage1.GetRows(), rgbImage1.GetCols(), CV_8UC3, rgbImage1.GetData(),rowBytes1);
//cv::imshow("image", imageR);//将cv::Mat转换成IplImage格式
IplImage *pImgR=cvCreateImage(cvSize(1600,1200),8,3);//简单的初始化Lre.bmp,工程中任意的一张图像。*pImgR=IplImage(imageR);
//MFC图像显示控件
CDC* pDC = m_picture2.GetWindowDC();
CvvImage limg;
CRect rect;
m_picture2.GetClientRect(&rect);
limg.CopyOf(pImgR);
limg.DrawToHDC(pDC -> m_hDC,&rect);
cvSaveImage("RIGHT.BMP",pImgR);
IplImage *pImgL=cvCreateImage(cvSize(1600,1200),8,3);
*pImgL=IplImage(imageL);
CDC* pDC1 = m_picture.GetWindowDC();
CvvImage limg1;
CRect rect1;
m_picture.GetClientRect(&rect1);
limg1.CopyOf(pImgL);
limg1.DrawToHDC(pDC1 -> m_hDC,&rect1);
cvSaveImage("LEFT.BMP",pImgL);
key = cv::waitKey(50);
资料汇总
Example
Language
Description
AsyncTriggerEx
C++
Demonstrates some of the basic asynchronous trigger capabilities of compatible PGR Imaging Products.
AsyncTriggerExCSharp
C#
Equivalent to AsnycTriggerEx, except written in C#.
BusEvents_CSharp
C#
Demonstrates how to handle bus events such as bus arrivals, removals and resets through the Managed interface.
CustomImageEx
C++
Demonstrates how to configure a PGR Imaging Product to output custom sized images.
CustomImageExCSharp
C#
Equivalent to CustomImageEx, except written in C#.
ExtendedShutterEx
C++
Demonstrates how to enable and calculate extended integration times for applicable Point Grey Imaging Products.
FlyCap2
C++
The main Point Grey Research application used to work with single lens cameras.
FlyCap2MFC
C++
Equivalent to FlyCap2, except uses features of the Microsoft Foundation Class Library.
FlyCapture2GUI
C++
This example contains the same source code that is used for the Camera Selection and Camera Control dialogs in FlyCapture.
FlyCapture2Test
C++
Tests basic functionality of a single camera and reports information related to all compatible cameras attached to the host system.
FlyCapture2Test_C
C
Equivalent to FlyCapture2Test, except written in C.
FlyCapture2Test_CSharp
C#
Equivalent to FlyCapture2Test, except written in C#.
GigEGrabEx
C++
Demonstrates how to grab images with GigE Vision cameras.
GigEGrabEx_C
C
Equivalent to GigEGrabEx, except written in C.
GigEGrabEx_CSharp
C#
Equivalent to GigEGrabEx, except written in C#.
GrabCallbackEx
C++
Demonstrates how to use the image callback functionality to receive images instead of using RetrieveBuffer().
GrabCallbackEx_CSharp
C#
Equivalent to GrabCallbackEx, except written in C#.
HighDynamicRangeEx
C++
Demonstrates the use of High Dynamic Range (HDR) functionality.
ImageEventEx
C++
Demonstrates how to implement partial image event notification. Partial image event notification is a mechanism that provides the user with access to image data as it arrives in the PC’s memory, before the entire image is available.
MultipleCameraEx
C++
Synchronizes image grabbing across multiple cameras.
SaveImageToAviEx
C++
Demonstrates saving a series of images to an AVI file.
SaveImageToFlashEx
C++
Demonstrates saving images to the data flash on the camera.
SerialPortEx
C++
Demonstrates how to transmit and receive characters by using the camera’s serial buffer system.