I am currently developing a machine vision application using Basler camera acA1300-30gc. For this I am working with Basler Pylon 4 and OPENCV version 2.4.9 and some problems have shown up. I am trying to capture an image using the Pylon SDK and convert it to Mat format for further analysis. Due to processing time restrictions my goal is to avoid saving the image to the hard drive but to analyze it on-the-fly.
In the following code I try to capture the image, convert it to Mat format and display it on a new window, but the window I get is blank. I will be very grateful if some one could help me please identifying my mistake(s), or explaining how could I reach my goal in a different way. (I probably should add that the camera is properly working and that I have been able to save images to the hard drive).
Thanks.
here is my code:
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;
}
}