VS 2017 + OpenCV + Spinnaker SDK(PointGrey) 配置
1. OpenCV 配置
1.1 下载 opencv 源码,并将其添加至环境变量
D:\opencv4.1\build\x64\vc15\bin
注:vs2015 选 vc14,vs2017 选 vc15
1.2 创建 C++ 项目,选择 “视图” -> “属性页”,配置:活动(Debug),平台:活动(x64)
- VC++目录:包含目录和库目录
包含目录:D:\opencv4.1\build\include; D:\opencv4.1\build\include\opencv2
库目录:D:\opencv4.1\build\x64\vc15\lib
- “链接器” -> “输入” -> “附加依赖项”
opencv_world410.lib opencv_world410d.lib
注:
- opencv_world410d.lib 中的 'd' 表示 "debug",若没有 'd',表示 "release";
- 这两个文件在 "D:\opencv4.1\build\x64\vc15\lib" 目录下。
1.3 测试
注:运行前,选择 Debug,x64
#include <opencv2/opencv.hpp> #include <iostream> using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
Mat src = imread("path/to/image");
if (src.empty())
{
cout << "Could not load image..." << endl;
return -1;
}
nameWindow("Test", WINDOW_AUTOSIZE);
imshow("", src);
waitkey(1000);
return 0;
}
2. Spinnaker SDK 配置
Spinnaker SDK 是灰点公司(PointGrey)提供的 SDK,是之前 FlyCapture SDK 的升级版。
2.1 下载 SDK,并安装
https://flir.app.boxcn.net/v/SpinnakerSDK/folder/68522911814
2.2 项目属性配置
- 加载头文件:"C/C++" -> “常规” -> “附加包含目录”
- 加载 lib 库文件:“链接器” -> “常规” -> “附加库目录”
D:\Spinnaker\lib64\vs2015
- “链接器” -> “输入” -> “附加依赖项”
Spinnakerd_v140.lib
Spinnaker_v140.lib
注:Spinnakerd_v140.lib(Debug), Spinnaker_v140.lib(Release)
3. Spinnaker SDK 采集的图像转成 OpenCV mat 格式
#include <opencv2/opencv.hpp> cv::Mat cvMat; int cvFormat = CV_8UC1; unsigned int XPadding = convertedImage->GetXPadding(); unsigned int YPadding = convertedImage->GetYPadding(); unsigned int rowsize = convertedImage->GetWidth(); unsigned int colsize = convertedImage->GetHeight(); cvMat = cv::Mat(colsize + YPadding, rowsize + XPadding, cvFormat, convertedImage->GetData(), convertedImage->GetStride());
参考:https://github.molgen.mpg.de/MPIBR/SpinnakerCapture/blob/master/SpinnakerCapture.cpp