現階段做雙目立體視覺工作,前幾天剛配置好開發環境,随筆記錄下。
采用的相機是basler acA1920-155um 型号。本人選擇opencv3.2.0基于Windows平台。
opencv官方下載下傳連結
http://opencv.org/releases.html#。
pylon5.0.10官方下載下傳連結https://www.baslerweb.com/cn/support/downloads/software-downloads/pylon-5-0-10-windows/
配置過程:
1:安裝opencv3.2.0和pylon5.0.10,pylon5.0.10需要選擇開發者模式,同時選擇相機接口類型,本人采用的usb3.0接口。
2:添加opencv的環境變量,

pylon安裝過程中會自動配置環境變量。
3:vs2017中建立一個空項目的控制台程式,然後添加一個cpp檔案,再打開屬性管理器
在debugx64 中建立一張屬性表然後進行編輯。
4:先在通用屬性VC++目錄中 的包含目錄
添加四個路徑:
opencv\build\include
opencv\build\include\opencv
opencv\build\include\opencv2
basler\Development\include
取決于你的具體安裝位置
5:在庫目錄添加
basler\Development\lib\x64
opencv3.2.0\build\x64\vc14\lib
6:在連結器輸入選項中輸入
輸入opencv_world320d.lib 對應的是debug 模式
輸入opencv_world320.lib 不帶d的是release 模式
注意編譯器要選擇 x64
7: 将配置好的屬性表儲存出來,以後每次建立工程添加一次
測試代碼
#include"stdafx.h"
#include"opencv2/opencv.hpp"
#include <pylon/PylonIncludes.h>
#include<iostream>
#ifdef PYLON_WIN_BUILD
#include <pylon/PylonGUI.h>
#endif
/*-----------------------------命名空間-------------------------------------*/
using namespace Pylon;
using namespace cv;
using namespace std;
int main()
{
//pylon 類型圖檔定義
CPylonImage pylonImage;
//pylon 格式轉換定義
CImageFormatConverter formatConverter;
formatConverter.OutputPixelFormat = PixelType_BGR8packed;
//指向拍攝結果的結構體指針
CGrabResultPtr ptrGrabResult;
//opencv 類型圖檔定義
Mat openCvImage_left;
Mat openCvImage_right;
/*-----------------------------pylon相機初始化-----------------------------------*/
//pylon相機自動初始化和終止
PylonAutoInitTerm autoInitTerm;
//建立傳輸工程
CTlFactory& tlFactory = CTlFactory::GetInstance();
//擷取相機資訊
DeviceInfoList_t devices;
if (tlFactory.EnumerateDevices(devices) == )
{
cout << "監測到兩個相機" << endl;
}
//建立相機序列并辨別資訊
CInstantCameraArray cameras();
for (size_t i = ; i < cameras.GetSize(); ++i)
{
cameras[i].Attach(tlFactory.CreateDevice(devices[i]));
}
/*-----------------------------pylon相機開始抓取-----------------------------------*/
//開始拍攝
cameras.StartGrabbing();
while(cameras.IsGrabbing())
{
// 設定指針重載間隔,20ms
cameras.RetrieveResult(, ptrGrabResult, TimeoutHandling_ThrowException);
intptr_t cameraContextValue = ptrGrabResult->GetCameraContext();
//顯示實時圖像
DisplayImage(cameraContextValue, ptrGrabResult);
/*-----------------------------pylon圖像到opencv圖像的轉換-----------------------------------*/
if (ptrGrabResult->GetCameraContext() == )
{
formatConverter.Convert(pylonImage, ptrGrabResult);
openCvImage_left = cv::Mat(pylonImage.GetHeight(), pylonImage.GetWidth(), CV_8UC3, (uint8_t *)pylonImage.GetBuffer());
}
if (ptrGrabResult->GetCameraContext() == )
{
formatConverter.Convert(pylonImage, ptrGrabResult);
openCvImage_right = cv::Mat(ptrGrabResult->GetHeight(), ptrGrabResult->GetWidth(), CV_8UC3, (uint8_t *)pylonImage.GetBuffer());
}
}
system("pause");
return ;
}
這段代碼 實作了打開雙目相機,并将pylon格式圖檔轉換為opencv Mat 類型,便于後續處理。
測試結果。