Eri*_*ric 3 c++ opencv computer-vision
我目前正在使用Basler相机acA1300-30gc开发机器视觉应用程序.为此,我正在使用Basler Pylon 4和OPENCV版本2.4.9,并且出现了一些问题.我正在尝试使用Pylon SDK捕获图像并将其转换为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;
}
}
Run Code Online (Sandbox Code Playgroud)
您必须确保像素类型匹配.在您的代码示例中,您使用PixelType_RGB8packed
的是相机图像,以及CV_8UC1
Mat像素类型.你应该用CV_8UC3
.我也会使用PixelType_BGR8packed
而不是PixelType_RGB8packed
,因为BGR与Windows位图兼容.我假设你使用Windows.
归档时间: |
|
查看次数: |
9475 次 |
最近记录: |