近红外摄像头Point-Grey开发日志

来源:互联网 发布:德语助手 mac 注册码 编辑:程序博客网 时间:2024/04/28 09:01

近红外摄像头的sdk在官网下载:
Point Grey SDK

安装好sdk后,在Point Grey Research文件夹下(下面称为根目录),找到example程序:根目录/FlyCapture2/src/FlyCapture2Test

src文件夹下大部分都是示例程序,这里用Vs2010加载FlyCapture2Test工程,工程配置文件在根目录/FlyCapture2/src/vsprops下,选择对应的配置文件加载到项目中。

由于sdk是x64版本的,在VS中选择release, x64平台。

分析项目中FlyCapture2Test.cpp中的代码,发现摄像头的操作(打开摄像头,保存图像)其实很简单。

const int k_numImages = 10;    Error error;    Camera cam;    // Connect to a camera    error = cam.Connect(&guid);//连接摄像头,如果连接成功,返回PGRERROR_OK    if (error != PGRERROR_OK)    {        PrintError( error );        return -1;    }    // Get the camera information    CameraInfo camInfo;    error = cam.GetCameraInfo(&camInfo);//获取摄像头信息    if (error != PGRERROR_OK)    {        PrintError( error );        return -1;    }    PrintCameraInfo(&camInfo);            // Start capturing images    error = cam.StartCapture();//启动摄像头,如果成功启动,返回PGRERROR_OK    if (error != PGRERROR_OK)    {        PrintError( error );        return -1;    }    Image rawImage;        for ( int imageCnt=0; imageCnt < k_numImages; imageCnt++ )    {                        // Retrieve an image        error = cam.RetrieveBuffer( &rawImage );//获取帧,存储在Image rawImage里面        if (error != PGRERROR_OK)        {            PrintError( error );            continue;        }        cout << "Grabbed image " << imageCnt << endl;         // Create a converted image        Image convertedImage;        // Convert the raw image        error = rawImage.Convert( PIXEL_FORMAT_MONO8, &convertedImage );//转换图像,转换原因有待研究        if (error != PGRERROR_OK)        {            PrintError( error );            return -1;        }          // Create a unique filename        ostringstream filename;        filename << "FlyCapture2Test-" << camInfo.serialNumber << "-" << imageCnt << ".jpg";        // Save the image. If a file format is not passed in, then the file        // extension is parsed to attempt to determine the file format.        error = convertedImage.Save( filename.str().c_str() );//将转换后的图像存储起来,文件名为filename字符串的内容,以.jpg格式存储。        if (error != PGRERROR_OK)        {            PrintError( error );            return -1;        }      }                // Stop capturing images    error = cam.StopCapture();//停用摄像头    if (error != PGRERROR_OK)    {        PrintError( error );        return -1;    }          // Disconnect the camera    error = cam.Disconnect();    if (error != PGRERROR_OK)    {        PrintError( error );        return -1;    }    return 0;
0 0