Basler相机Bayer格式转Qt RGB888

无论什么品牌的相机,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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章