近紅外攝像頭Point-Grey開發日誌

近紅外攝像頭的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;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章