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

 

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