映美精(IMAGINGSOURCE)相机与OPENCV库

来源:互联网 发布:无间行者 知乎 编辑:程序博客网 时间:2024/05/22 03:50

硕士期间本人主要研究基于机器视觉多目标在线识别技术,用到的相机为映美精相机,用到的图像处理库为开源的Opencv3,在实际的应用中,如何将该相机的数据流转换成Opencv的Mat类(该类具有自动申请内存和释放内存的功能),进而通过调用Opencv3中相应的图像处理函数,很好的实现在线处理,由于在博客中没有见到该方面的介绍,为此写下该文章,供大家学习研究……

本人直接用的该款相机提供的平台做的MFC

关键代码如下在Listener.cpp中:

   void CListener::DoImageProcessing( smart_ptr<MemBuffer> pBuffer){    // Get the bitmap info header from the membuffer. It contains the bits per pixel,    // width and height.    smart_ptr<BITMAPINFOHEADER> pInf = pBuffer->getBitmapInfoHeader();    // Now retrieve a pointer to the image. For organization of the image data, please    // refer to:    // http://www.imagingcontrol.com/ic/docs/html/class/Pixelformat.htm    BYTE* pImageData = pBuffer->getPtr();    // Calculate the size of the image.    int iImageSize = pInf->biWidth * pInf->biHeight * pInf->biBitCount / 8 ;    //将映美精相机的数据流转化为Mat类,进而进行后续的图像处理    Mat srcImage(480,640,CV_8UC1,pImageData);    blur(srcImage,srcImage,Size(7,7));    threshold(srcImage,srcImage,120,255,CV_THRESH_BINARY_INV);    Canny(srcImage,srcImage,40,20);}

实际效果

1 0
原创粉丝点击