讀取灰點相機圖像C++

配置:V2015 Debug x64

1.新建項目Win32控制檯應用程序Point_Grey.sln

2.配置庫文件

Point_Grey項目-屬性-VC++目錄-包含目錄-添加E:\FlyCapture\include(每人存放在位置不同)

Point_Grey項目-屬性-VC++目錄-庫目錄-添加E:\FlyCapture\lib64(每人存放在位置不同)

Point_Grey項目-屬性-鏈接器-輸入-附加依賴項-添加FlyCapture2.lib

3.編寫Point_Gray.cpp

#include "stdafx.h"
#include <FlyCapture2.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
using namespace FlyCapture2;
int main()
{
FlyCapture2::Error error;
Camera camera;
CameraInfo camInfo;
error = camera.Connect(0);
if (error != PGRERROR_OK)
{
std::cout << "Failed to connect to camera" << std::endl;
system("pause");
return false;
}
error = camera.GetCameraInfo(&camInfo);
if (error != PGRERROR_OK)
{
std::cout << "Failed to get camera info from camera" << std::endl;
return false;
}
std::cout << camInfo.vendorName << " "
<< camInfo.modelName << " "
<< camInfo.serialNumber << std::endl;


error = camera.StartCapture();
if (error == PGRERROR_ISOCH_BANDWIDTH_EXCEEDED)
{
std::cout << "Bandwidth exceeded" << std::endl;
return false;
}
else if (error != PGRERROR_OK)
{
std::cout << "Failed to start image capture" << std::endl;
return false;
}
Image rawImage;
Image rgbImage;
while (1)
{
FlyCapture2::Error error = camera.RetrieveBuffer(&rawImage);
if (error != PGRERROR_OK)
{
std::cout << "capture error" << std::endl;
continue;
}
rawImage.Convert(FlyCapture2::PIXEL_FORMAT_BGR, &rgbImage);
unsigned int rowBytes = (double)rgbImage.GetReceivedDataSize() / (double)rgbImage.GetRows();
cv::Mat frame = cv::Mat(rgbImage.GetRows(), rgbImage.GetCols(), CV_8UC3, rgbImage.GetData(), rowBytes);
resize(frame, frame, Size(0.3*frame.cols, 0.3*frame.rows));
imshow("顯示", frame);
waitKey(10);
}
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章