我目前正在開發使用Basler相機acA1300-30gc的機器視覺應用程序。爲此,我正在使用Basler Pylon 4和OPENCV 2.4.9版,並且出現了一些問題。我正在嘗試使用Pylon SDK捕捉圖像並將其轉換爲Mat格式以供進一步分析。由於處理時間限制,我的目標是避免將圖像保存到硬盤驅動器,但要實時分析它。Basler Pylon 4 SDK和OPENCV 2.4.9,CPylonImage到Mat
在下面的代碼中,我嘗試捕獲圖像,將其轉換爲Mat格式並將其顯示在新窗口中,但我得到的窗口是空白的。如果有人能幫助我,請確認我的錯誤或解釋我怎樣才能以不同的方式達到我的目標,我將不勝感激。 (我可能應該補充說,相機正常工作,我已經能夠保存圖像到硬盤驅動器)。
謝謝。
這裏是我的代碼:
PylonAutoInitTerm autoInitTerm;
try
{
CInstantCamera camera(CTlFactory::GetInstance().CreateFirstDevice());
cout << "Dispositivo usado:"<<camera.GetDeviceInfo().GetModelName()<<endl;
CGrabResultPtr ptrGrabResult;
camera.GrabOne(500,ptrGrabResult,TimeoutHandling_ThrowException);
if(ptrGrabResult->GrabSucceeded())
{
CPylonImage target;
CImageFormatConverter converter;
converter.OutputPixelFormat=PixelType_RGB8packed;
converter.OutputBitAlignment=OutputBitAlignment_MsbAligned;
converter.Convert(target,ptrGrabResult);
Mat image(target.GetWidth(),target.GetHeight(),CV_8UC1,target.GetBuffer(),Mat::AUTO_STEP);
if(image.empty())
{
cout << "No se pudo cargar la imagen Mat" << endl;
return -1;
}
cout << "La imagen se presenta en la ventana *Captura*" << endl;
namedWindow("Captura",WINDOW_AUTOSIZE);
imshow("Captura", image);
}
else
{
cout<<"Error: "<<ptrGrabResult->GetErrorCode()<<" "<<ptrGrabResult->GetErrorDescription()<<endl;
}
}
這工作,因爲我現在能夠轉換圖像,因爲我需要它,但我有一個額外的問題。我得到的圖像是它應該是什麼的一個重複片段,出了什麼問題? – Eric
我不知道我明白你的意思。也許你可以發佈圖片? –
這是我從程序 https://www.dropbox.com/s/dyeeyv0cnj4ovq1/CapturaError.JPG 獲得的圖像這是我想捕捉的圖像(掛架觀衆獲得) HTTPS:/ /www.dropbox.com/s/vnb9wcpee73ko8z/testImage.tiff – Eric