unsignd char*(Bayer)转opencv mat

使用海康工业相机sdk开发。语言C++,环境Qt,Ubuntu16.04

1.海康相机官网标称帧率为22fps,实际应用时发现只有4fps左右。后来确定为图像位深造成。

   官方sdk,8位图像只支持mono 和bayer bg8 格式输出。所以,要修改官方图像转换

   的Demo.

2.实验证明,并不用自己写bayer图像转换的函数。opencv就可以完成转换。但一定注意Bayer

  图像是单通道图像。

Mat Convert2Mat(MV_FRAME_INFO_EX* psImageInfo,unsigned char* pData)
{

    Mat retImg;
    if(psImageInfo->enPixelType==PixelType_Gvsp_Mono8)
    {
        retImg = cv::Mat(pstImageInfo->nHeight,pstImageInfo->nWidth,CV_8UC1,pData);
    }
    else if(psImageInfo->enPixelType == PixelType_Gvsp_BayerBG8)
    {
        retImg = cv::Mat(pstImageInfo->nHeight,pstImageInfo->nWidth,CV_8UC1,pData);
        cvtColor(retImg,retImg,COLOR_BayerBG2BGR);
    }
    else if(psImageInfo->enPixelType == PixelType_RGB8_Packed)
    {
        retImg = cv::Mat(pstImageInfo->nHeight,pstImageInfo->nWidth,CV_8UC3,pData);
    }
    else
    {
        //print something
    }
    return retImg;

}
发布了12 篇原创文章 · 获赞 0 · 访问量 1720

猜你喜欢

转载自blog.csdn.net/zxcvb036/article/details/103689184
今日推荐