如题:
附转换代码(加上工业相机拍照函数):
QImage Camera::VideoCamera(){
Mat openCvImage;
try {
// 开始抓取c_countOfImagesToGrab images.
//相机默认设置连续抓取模式
cameraM.StartGrabbing(c_countOfImagesToGrab, GrabStrategy_LatestImageOnly);
//抓取结果数据指针
Pylon::CGrabResultPtr ptrGrabResult;
Pylon::CPylonImage pylonImage;
// 等待接收和恢复图像,超时时间设0置为5000 ms.
cameraM.RetrieveResult(5000, ptrGrabResult, Pylon::TimeoutHandling_ThrowException);
if (cameraM.IsGrabbing())
{
//如果图像抓取成功
if (ptrGrabResult->GrabSucceeded())
{
//将抓取的缓冲数据转化成pylon image.
formatConverterM.Convert(pylonImage, ptrGrabResult);
// 将 pylon image转成OpenCV image.
openCvImage = cv::Mat(ptrGrabResult->GetHeight(), ptrGrabResult->GetWidth(), CV_8UC3, (uint8_t *)pylonImage.GetBuffer());
}
}
Mat rgb;
cvtColor(openCvImage, rgb, CV_BGR2RGB);
QImage img = QImage((const unsigned char*)(rgb.data),