无论什么品牌的相机,Bayer转RGB都涉及到插值,因此建议使用官方SDK里的函数进行转换。针对Basler相机,代码如下:
void BaslerCamera::toQImage(CGrabResultPtr ptrGrabResult, QImage &OutImage) { int width = static_cast<int>(ptrGrabResult->GetWidth()); int height = static_cast<int>(ptrGrabResult->GetHeight()); if (ptrGrabResult->GetPixelType() == Pylon::PixelType_Mono8) { uchar* buffer = (uchar*)ptrGrabResult->GetBuffer(); OutImage = QImage(buffer, width, height, QImage::Format_Grayscale8); } else //bayer格式等 { CImageFormatConverter fc; //CPylonImage* img = new CPylonImage(); //注意必须为指针,否则 GetBuffer()不正确。注意在合适的地方new/delete //CPylonImage img; //通过官方函数先转为 RGB8 fc.OutputPixelFormat = PixelType_RGB8packed; fc.Convert(*img, ptrGrabResult); uchar* buffer = (uchar*)img->GetBuffer(); OutImage = QImage(buffer, width, height, QImage::Format_RGB888); } }
【多余的话】
官方有下图函数,但是貌似没用。因此使用 CImageFormatConverter
标签:Qt,ptrGrabResult,uchar,Basler,img,相机,buffer,Bayer,QImage From: https://www.cnblogs.com/xixixing/p/16650915.html