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

一、准备工作

相机型号: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 guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsTARGET = 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.0SOURCES += \main.cpp \mainwindow.cpp \Listener.cppHEADERS += \mainwindow.h \Listener.hFORMS += \mainwindow.uiINCLUDEPATH += 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 <QDebug>
#include <QLabel>
#include <QObject>#include <tisudshl.h>
#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 <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>#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_OBJECTpublic:// Overwrite the GrabberListener methods we needvirtual void overlayCallback( DShowLib::Grabber& caller, smart_ptr<DShowLib::OverlayBitmap> pBitmap, const DShowLib::tsMediaSampleDesc& MediaSampleDesc );virtual void frameReady( DShowLib::Grabber& caller, smart_ptr<DShowLib::MemBuffer> pBuffer, DWORD FrameNumber );virtual void deviceLost( Grabber& caller );// Save one image and mark it as saved//void saveImage( smart_ptr<DShowLib::MemBuffer> pBuffer, DWORD currFrame );// Setup the buffersize.void setBufferSize( unsigned long NumBuffers );std::vector<bool> 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 <iostream>
#include "Listener.h"//
/*! The overlayCallback() method draws the number of the current frame. Theframe count is a member of the tsMediaSampleDesc structure that is passedto overlayCallback() by the Grabber.*/
void CListener::overlayCallback( Grabber& caller, smart_ptr<OverlayBitmap> 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<MemBuffer> pBuffer, DWORD currFrame)
{UNREFERENCED_PARAMETER(caller);//Grabber callertmp = caller;//std::cout << "Buffer " << currFrame << " processed in CListener::frameReady()." << std::endl;//saveImage( pBuffer, currFrame ); // Do the buffer processing.//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.htmBYTE* pImageData = pBuffer->getPtr();pImage=pImageData;//Calculate the size of the image.//int iImageSize = pInf->biWidth * pInf->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 inthe 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<MemBuffer> 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() 函数取图。

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

  1. Qt下Tcp传输文件

    Qt下Tcp传输文件 文章目录 Qt下Tcp传输文件 1.服务端 2.客户端 1.服务端 //ServerWidgets.h #ifndef SERVERWIDGET_H #define SERVER ...

  2. Games202,作业1(QT下实现PCSS)

    文章目录 作业1框架下实现PCF 作业1框架下实现PCSS 在QT下使用PCF 代码 结果 在QT下使用PCSS 代码 结果 采用低通采样 PCF使用低通采样 代码 结果 PCSS 代码 结果 采样数 ...

  3. QT下视频通话的实现

    ** 1 QT下视频通话的实现 ** 本文使用QT完成了两个不同终端的视频通话,笔记本电脑+Linux开发板. 1.1 硬件资源介绍 带摄像头的电脑 + 正点原子Alpha Linux开发板(由于Li ...

  4. Qt下使用OpenCV3打开摄像头并把图像显示到QLabel上

    前言 1.Qt5有自己摄像头的类QCamera,但是图像处理相关还是要使用OpenCV来做,这里我演示在Qt下使用OpenCV打开摄像头. 2.Qt的版本是5.9,Qt Creator 4.4.1,O ...

  5. Baumer工业相机堡盟工业相机如何通过BGAPISDK显示彩色相机和黑白相机的图像(C#)

    Baumer工业相机堡盟工业相机如何通过BGAPISDK里显示彩色相机和黑白相机的图像(C#) Baumer工业相机 Baumer工业相机的彩色和黑白成像的技术背景 Baumer工业相机通过BGAPI ...

  6. Qt下使用vs编译的库文件

    Qt下调用VS制作的静态库    1.制作静态库的编译器和Qt版本的编译器是一样     如果是使用Visual Studio 制作的静态库,比如使用Visual Studio 2013制作的,而要使 ...

  7. 工业相机——黑白相机像素格式排列解析

    了解图像格式,首先要了解图像的常用属性: 像素(Pixel):人眼直接感受到的图像 位图(bitmap):通过记录每一个像素值来存储和表达的图像 位深度:位图中每个像素点用多少个二进制位来表示 bmp ...

  8. linux+Qt 下利用D-Bus进行进程间高效通信的三种方式

    linux+Qt 下利用D-Bus进行进程间高效通信的三种方式 原文链接: https://www.cnblogs.com/wwang/archive/2010/10/27/1862552.html ...

  9. Qt下一行代码就可以使用的稳定易用的日志log类

    Qt下一行代码就可以使用的稳定易用的日志类 此日志类是基于Qt 自带的 扩展的一个易用的日志类, 使用的是Qt自带的日志输出形式, 已长期运行在许多实际项目中,稳定可靠,而且跨平台, 在windows ...

  10. Qt下使用Shader绘制三角形

    在Qt下使用可编程管线编写OpenGL的流程是怎样的呢? 下面演示了Qt下使用可编程管线的基本代码:(绘制三个不同的三角形,并做些旋转变换) 在Qt中,我们从QGLWidget继承,来实现OpenGL ...

最新文章

  1. mysql 上亿记录_一入职!就遇到上亿(MySQL)大表的优化....
  2. 程序实现:由给定几个数确定凸组合系数,组成一个给定的数
  3. 无监督学习和监督学习的区别
  4. 硬件:电脑DNS出现错误对应的解决方案
  5. 【ArcGIS风暴】ArcGIS创建栅格数据集色彩映射表案例--以GlobeLand30土地覆盖数据为例
  6. Orika:将JAXB对象映射到业务/域对象
  7. 【转】java反射--注解
  8. linux安装-bin.rpm,Linux离线安装jdk,bin、rpm和tar.gz三种方式及配置jdk环境变量
  9. Oracle回退不小心drop掉得表
  10. Jquery之append()和html()的区别
  11. 熟悉scrapy的基本使用(创建与运行,目录结构)---爬虫项目
  12. 新手如何Reverces(3自动化逆向篇)
  13. 电子产品检验-检验中心
  14. 英雄联盟龙的传人皮肤爬虫
  15. Caffe base_lr递减
  16. fullcalendar的使用教程
  17. 【强化学习】Actor-Critic算法详解
  18. 理想低通滤波器(频率域滤波)
  19. Android适配器方法,android – 当创建自己的自定义适配器时,getView()方法如何工作?...
  20. 主机与Dynamips相连的折中解决方法

热门文章

  1. 锐捷交换机基本功能配置
  2. qt中c语言运行中文字体乱码,QString 与中文问题/Qt界面中文字体及大小设置
  3. 联想a30微型计算机,联想A30测评,硬件部分。是电脑哦。
  4. ubuntu软件包详解
  5. .bin文件的反汇编记录
  6. 政务型CMS内容管理系统
  7. 病毒分析一:恶意下载软件
  8. web网页设计与开发____婚纱网站(5页 汉堡菜单 响应式)
  9. python 爬虫 美女_使用Python爬虫爬取网络美女图片
  10. qc中的流程图怎么画_QC流程图