在Qt下使用映美精黑白相机:Qt 5.12 + ImagingSource(映美精)+ vs2017 Community + OpenCV 3.3

您所在的位置:网站首页 imagingsource相机参数 在Qt下使用映美精黑白相机:Qt 5.12 + ImagingSource(映美精)+ vs2017 Community + OpenCV 3.3

在Qt下使用映美精黑白相机:Qt 5.12 + ImagingSource(映美精)+ vs2017 Community + OpenCV 3.3

2024-01-21 22:34| 来源: 网络整理| 查看: 265

最近应做一个视觉项目需要用到映美精相机,在网上搜索了很多资料没有找到相关内容,因此只能自己一步一步的摸索。

 

一、准备工作

相机型号:ImagingSource DMK 23G445

相机软件:ic_setup_3.4.0,gigecam_setup_3.6.0

其它软件:Qt 5.12.1, vs2017 Community, OpenCV 3.3.0

操作系统:Windows 10 1909 18363.592

 

Qt .pro配置文件如下(配置文件xxx换上电脑用户名):

QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = imagingSource_CallBack TEMPLATE = app # The following define makes your compiler emit warnings if you use # any feature of Qt which has been marked as deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp \ mainwindow.cpp \ Listener.cpp HEADERS += \ mainwindow.h \ Listener.h FORMS += \ mainwindow.ui INCLUDEPATH += D:\Projects\opencv\build\include INCLUDEPATH += D:\Projects\opencv\build\include\opencv INCLUDEPATH += D:\Projects\opencv\build\include\opencv2 INCLUDEPATH += $$quote(C:\Users\xxx\Documents\IC Imaging Control 3.4\classlib\include) LIBS += D:\Projects\opencv\build\x64\vc14\lib\opencv_world330.lib LIBS += D:\Projects\opencv\build\x64\vc14\lib\opencv_world330d.lib LIBS += $$quote(C:\Users\xxx\Documents\IC Imaging Control 3.4\classlib\x64\release\TIS_UDSHL11_x64.lib) LIBS += $$quote(C:\Users\xxx\Documents\IC Imaging Control 3.4\classlib\x64\debug\TIS_UDSHL11d_x64.lib)

Listener.h: 配置如下:

#ifndef LISTENER_H #define LISTENER_H // Listener.h: interface for the CListener class. // // The CListener class is derived from GrabberListener. It overwrites // the "frameReady()" method. In the frameReady method the member method // "saveImage()" is called. // "saveImage()" saves the specified buffer to a BMP file and calls a "Sleep(250)" // to simulate a time expensive image processing. "saveImage()" is also called // by the main() function of this example to save all buffers, that have // not been processed in the frameReady method.# // // This class also overwrites the overlayCallback method to draw a // frame counter. // // The CListener object is registered to a Grabber with the parameter // eFRAMEREADY|eOVERLAYCALLBACK . // // If your camera resolution is not 1280 × 960, you should modify the // macro definition "CAM_SIZE_X" and "CAM_SIZE_Y". // // You should change the "cmdhelper.h" path. // #pragma once #include #include #include #include #include "../cmdhelper.h" // TODO: You need change the path, the file path is usually as follows: // C:/Users/xxx/Documents/IC Imaging Control 3.4/samples/vc10/Common/cmdhelper.h #include #include #include #define NUM_BUFFERS 2 #define CAM_SIZE_X 1280 // TODO: Maybe you need modify the value. #define CAM_SIZE_Y 960 // TODO: Maybe you need modify the value. using namespace cv; using namespace DShowLib; class CListener : public QObject, public DShowLib::GrabberListener { Q_OBJECT public: // Overwrite the GrabberListener methods we need virtual void overlayCallback( DShowLib::Grabber& caller, smart_ptr pBitmap, const DShowLib::tsMediaSampleDesc& MediaSampleDesc ); virtual void frameReady( DShowLib::Grabber& caller, smart_ptr pBuffer, DWORD FrameNumber ); virtual void deviceLost( Grabber& caller ); // Save one image and mark it as saved //void saveImage( smart_ptr pBuffer, DWORD currFrame ); // Setup the buffersize. void setBufferSize( unsigned long NumBuffers ); std::vector m_BufferWritten; // array of flags which buffers have been saved. cv::Mat srcImage_CListener; BYTE* pImage; signals: void frameReady_Event(); void deviceLost_Event(); // You can add the slot to process the device lost event. }; #endif // LISTENER_H

Listener.cpp 配置如下

// // Listener.cpp: implementation of the CListener class. // //#define _WIN32_WINNT 0x0500 #include #include "Listener.h" // /*! The overlayCallback() method draws the number of the current frame. The frame count is a member of the tsMediaSampleDesc structure that is passed to overlayCallback() by the Grabber.*/ void CListener::overlayCallback( Grabber& caller, smart_ptr pBitmap, const tsMediaSampleDesc& MediaSampleDesc) { UNREFERENCED_PARAMETER(caller); //Grabber callertmp = caller; char szText[25]; if( pBitmap->getEnable() == true ) // Draw only, if the overlay bitmap is enabled. { sprintf( szText,"%05d ", MediaSampleDesc.FrameNumber+1); pBitmap->drawText( RGB(255,255,255), 0, 0, szText ); } } // /*! The frameReady() method calls the saveImage method to save the image buffer to disk.*/ void CListener::frameReady( Grabber& caller, smart_ptr pBuffer, DWORD currFrame) { UNREFERENCED_PARAMETER(caller); //Grabber callertmp = caller; //std::cout biHeight * pInf->biBitCount / 8 ; //将映美精相机的数据流转化为Mat类,进而进行后续的图像处理 cv::Mat tempImage(CAM_SIZE_Y, CAM_SIZE_X, CV_8UC1, pImageData); srcImage_CListener=tempImage; frameReady_Event(); // TODO: You need add the slot the process the signal. //saveToFileBMP( *pBuffer, "C:/Users/xxx/Desktop/pic/001.bmp" ); //::Sleep(250); // Simulate a time expensive processing. } void CListener::deviceLost(Grabber &caller) { UNREFERENCED_PARAMETER(caller); emit deviceLost_Event(); // TODO: You need add the slot the process the signal. } // /*! Initialize the array of bools that is used to memorize, which buffers were processed in the frameReady() method. The size of the array is specified by the parameter NumBuffers. It should be equal to the number of buffers in the FrameHandlerSink. All members of m_BufferWritten are initialized to false. This means that no buffers have been processed.*/ void CListener::setBufferSize( unsigned long NumBuffers ) { m_BufferWritten.resize( NumBuffers, false ); } // /*! The image passed by the MemBuffer pointer is saved to a BMP file.*/ //void CListener::saveImage( smart_ptr pBuffer, DWORD currFrame) //{ // char filename[MAX_PATH]; // if( currFrame < m_BufferWritten.size() ) // { // sprintf( filename, "image%02i.bmp", currFrame ); // saveToFileBMP( *pBuffer, filename ); // m_BufferWritten.at( currFrame ) = true; // } //}

在Qt项目中只要添加上面两个文件就可以啦,同时在要开始检测的地方要加入

addListener(pListener, GrabberListener::eALL); // 用法参见映美精参考文档

这样每次相机内存中有图片时,就能通过下面信号函数发送消息,在要处理图像的源文件中添加对应的槽就可以了。

frameReady_Event();

如果采用软触发建议使用 snapImage() 函数取图。

 

 

 

 

 

 

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3