基于Qt的图像采集系统
硬件
Point Gray Camera
型号:FL3-U3-13S2C-CS
参数
Sony IMX035 CMOS, 1/3", 3.63 µm
Rolling Shutter
1328x1048 at 120 FPS
USB3.0
系统及环境
Windows 7 64bit
Qt 5.1
驱动:FlyCapture v2.5 Release 4 - Windows 64bit
硬件连接
将相机直接接到电脑的USB3.0接口上就可以了。
程序功能
调用摄像头拍照,并在窗口中显示结果拍照结果。
开发的过程中主要是参考官方的文档,在sdk安装的文件夹里就有。
代码清单
代码结构
很简单,就一个类。
首先要在.pro文件中包含头文件和库
INCLUDEPATH += "C:/Program Files/Point Grey Research/FlyCapture2/include" LIBS += "C:\Program Files\Point Grey Research\FlyCapture2\lib64\FlyCapture2.lib"
main.cpp
#include "mainwindow.h"
#include <QApplication> int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
初始化一个MainWindow,然后显示,没什么好说的。
mainwindows.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H #include <QMainWindow>
#include <FlyCapture2.h>
#include <iostream>
#include <QLabel>
#include <QAction>
#include <QStatusBar>
#include <QMessageBox>
#include <QMenu>
#include <QMenuBar>
using namespace std;
using namespace FlyCapture2;
class MainWindow : public QMainWindow
{
Q_OBJECT public:
MainWindow(QWidget *parent = 0);
void printCameraInfo();
~MainWindow();
private:
QLabel *imageLabel;
QMenu *operationMenu;
QMenu *aboutMenu;
QMenu *cameraMenu;
QAction *startAction;
QAction *stopAction;
QAction *aboutAction;
QAction *cameraInfoAction;
QLabel *msgLabel;
QLabel *about; void createActions();
void createMenus();
void printError(Error e);
void getCameraInfo(); PGRGuid guid;
Error error;
Camera cam;
CameraInfo camInfo; public slots:
void slotAbout();
int slotStart();
void slotStop();
void slotShowCameraInfo(); }; #endif // MAINWINDOW_H
首先要包含 FlyCapture2.h 这个头文件,然后定义好窗体的menu,action等等,还有操作相机的几个相关的私有成员。
main.cpp
#include "mainwindow.h" MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
this->setGeometry(100,100,1000,768);
this->setWindowTitle(tr("FlyCapture View")); //状态栏设定
msgLabel=new QLabel;
msgLabel->setMinimumSize(msgLabel->sizeHint());
this->statusBar()->addWidget(msgLabel); this->createActions();
this->createMenus(); imageLabel = new QLabel;
imageLabel->setBackgroundRole(QPalette::Base);
imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
imageLabel->setScaledContents(true); QPixmap image(":/images/images/monster.png");
imageLabel->setPixmap(image);
this->setCentralWidget(imageLabel); //Initialization of camera
BusManager busMgr; error = busMgr.GetCameraFromIndex(0, &guid);
if (error != PGRERROR_OK)
{
printError( error );
//return -1;
} const int k_numImages = 10; // Connect to a camera
error = cam.Connect(&guid);
if (error != PGRERROR_OK)
{
printError( error );
// return -1;
}
// Get the camera information error = cam.GetCameraInfo(&camInfo);
if (error != PGRERROR_OK)
{
printError( error );
//return -1;
} } MainWindow::~MainWindow()
{ } void MainWindow::createActions()
{
this->aboutAction = new QAction(tr("&About"), this);
this->aboutAction->setStatusTip(tr("About author."));
this->connect(aboutAction, SIGNAL(triggered()), this, SLOT(slotAbout())); this->startAction = new QAction(tr("&Start"), this);
this->startAction->setStatusTip(tr("Start capture."));
this->connect(startAction, SIGNAL(triggered()), this, SLOT(slotStart())); this->stopAction = new QAction(tr("&Stop"), this);
this->stopAction->setStatusTip(tr("Stop capture."));
this->connect(stopAction, SIGNAL(triggered()), this, SLOT(slotStop())); this->cameraInfoAction = new QAction(tr("&CameraInfo"), this);
this->cameraInfoAction->setStatusTip(tr("Camera Information."));
this->connect(cameraInfoAction, SIGNAL(triggered()), this, SLOT(slotShowCameraInfo())); } void MainWindow::createMenus()
{
this->operationMenu = this->menuBar()->addMenu(tr("&Operation"));
this->operationMenu->addAction(startAction);
this->operationMenu->addAction(stopAction); this->aboutMenu = this->menuBar()->addMenu(tr("&About"));
this->aboutMenu->addAction(aboutAction); this->cameraMenu = this->menuBar()->addMenu(tr("&Camera"));
this->cameraMenu->addAction(cameraInfoAction);
} void MainWindow::slotAbout()
{
QMessageBox msg(this);
msg.setWindowTitle("About");
msg.setText(tr("Version:1.0 Author:silangquan@gmail.com"));
msg.exec();
} int MainWindow::slotStart()
{ // Start capturing images
error = cam.StartCapture();
if (error != PGRERROR_OK)
{
printError( error );
return -1;
} Image rawImage; error = cam.RetrieveBuffer( &rawImage );
if (error != PGRERROR_OK)
{
printError( error );
// continue;
} // Create a converted image
Image convertedImage; // Convert the raw image
error = rawImage.Convert( PIXEL_FORMAT_RGB, &convertedImage );
if (error != PGRERROR_OK)
{
printError( error );
return -1;
} // Save the image. If a file format is not passed in, then the file
// extension is parsed to attempt to determine the file format.
error = convertedImage.Save( "Test.jpg");
if (error != PGRERROR_OK)
{
printError( error );
return -1;
}
// } // Stop capturing images
error = cam.StopCapture();
if (error != PGRERROR_OK)
{
printError( error );
return -1;
} // Disconnect the camera
error = cam.Disconnect();
if (error != PGRERROR_OK)
{
printError( error );
return -1;
} QPixmap image("Test.jpg");
imageLabel->setPixmap(image);
cout<<"Captured!"<<endl;
return 0; } void MainWindow::slotStop()
{
cout<<"Stop!"<<endl;
} void MainWindow::slotShowCameraInfo()
{
QMessageBox msg(this);
msg.setWindowTitle("Camera Informations");
msg.setText(QString("Serial number - %1\nCamera model - %2\nCamera vendor - %3\nSensor - %4\nResolution - %5\nFirmware version - %6\nFirmware build time - %7\n\n")
.arg(camInfo.serialNumber).arg(camInfo.modelName).arg(camInfo.vendorName).arg(camInfo.sensorInfo).arg(camInfo.sensorResolution)
.arg(camInfo.firmwareVersion).arg(camInfo.firmwareBuildTime)); msg.exec();
} void MainWindow::printError(Error e)
{
e.PrintErrorTrace();
}
主要是函数,槽,界面布局的实现。
最终效果:
基于Qt的图像采集系统的更多相关文章
- 一、基于Qt的图像矩形区域改色
Qt环境下图像的打开和涂色 一.设计目标 能够在 Qt QtCreator 环境下打开常用图像格式文件,诸如 bmp.jpg.png 图像等,然后将他们转化为 Qt 中的 QImage 类,并进行矩形 ...
- 基础的基于QT的图像查看程序
代码来自<QT5.9c++开发指南>,因为实现了图片的遍历显示,对于将来编写ImageShop一类的图像程序来说将非常有用(这个程序目前存在一定问题,在研究过程中进行解决) 一.基本功能 ...
- 基于Xilinx FPGA的视频图像采集系统
本篇要分享的是基于Xilinx FPGA的视频图像采集系统,使用摄像头采集图像数据,并没有用到SDRAM/DDR.这个工程使用的是OV7670 30w像素摄像头,用双口RAM做存储,显示窗口为320x ...
- 基于FPGA的线阵CCD实时图像采集系统
基于FPGA的线阵CCD实时图像采集系统 2015年微型机与应用第13期 作者:章金敏,张 菁,陈梦苇2016/2/8 20:52:00 关键词: 实时采集 电荷耦合器件 现场可编程逻辑器件 信号处理 ...
- 基于AXI VDMA的图像采集系统
基于AXI VDMA的图像采集系统 转载 2017年04月18日 17:26:43 标签: framebuffer / AXIS / AXI VDMA 2494 本课程将对Xilinx提供的一款IP核 ...
- 基于SDRAM的视频图像采集系统
本文是在前面设计好的简易SDRAM控制器的基础上完善,逐步实现使用SDRAM存储视频流数据,实现视频图像采集系统,CMOS使用的是OV7725. SDRAM控制器的完善 1. 修改SDRAM的时钟到1 ...
- 基于QT的一个简易的安防
工程描述 opencv2.4.8 QT5 背景建模后,当有异物入侵时,把入侵的帧写到视频文件 使用BackgroundSubtractorMOG2背景建模 程序基于QT对话框 .pro #------ ...
- 基于QT的webkit与ExtJs开发CB/S结构的企业应用管理系统
一:源起 1.何为CB/S的应用程序 C/S结构的应用程序,是客户端/服务端形式的应用程序,这种应用程序要在客户电脑上安装一个程序,客户使用这个程序与服务端通信,完成一定的 ...
- 基于clahe的图像去雾
基于clahe的图像去雾 通过阅读一些资料,我了解到clahe算法对图像去雾有所价值,正好opencv中有了实现,拿过来看一看. 但是现在实现的效果还是有所差异 #); clahe] ...
随机推荐
- MySQL的三层架构之一----连接层
1.mysql的服务端可以分为三层,分别是连接层,SQL层,存储层. 2.架构图 3.连接层定义了通信server端与client协议:
- Oracle EBS-SQL (WIP-1):检查非标任务没挂需求.sql
SELECT WE.WIP_ENTITY_NAME, MSI.SEGMENT1, MSI.DESCRIPTION, WDJ.CLASS_CODE, WDJ.START_QUANTITY, WDJ.SC ...
- Linux学习之十六、文件的格式化与相关处理
原文地址:http://vbird.dic.ksu.edu.tw/linux_basic/0330regularex_4.php 文件的格式化与相关处理 接下来让我们来将文件进行一些简单的编排吧!底下 ...
- JavaScript单线程
首先浏览器的js引擎是单线程的,执行一个耗时操作必定阻碍线程后续代码的执行(比如等待网络请求的响应).一些语言采用了开一个子线程并把耗时操作放到子线程去执行的办法解决了这个问题.js引擎本身不支持多线 ...
- UICollectionView基础学习
相信了解UICollectionView的也一定听过瀑布流吧,开始之前先提供两个瀑布流,有时间的可以深入研究研究 https://github.com/dingpuyu/WaterFall https ...
- Flash,一次Bug的思考
我绝对不算是F黑,大部分时候,我还是很挺Flash平台的,Flash提供了很好的跨平台特性以及Flash Player11后的GPU加速.Stage3D等等,对于开发者来说,绝对让人欣喜若狂(对我是这 ...
- UNIX网络编程---传输层:TCP、UDP、SCTP(二)
UNIX网络编程----传输层:TCP.UDP.SCTP 一.概述 本章的焦点是传输层:包括TCP.UDP.和SCTP(流控制传输协议).SCTP是一个较新的协议,最初设计用于跨因特网传输电话信令. ...
- AlertDialog.Builder中的setMultiChoiceItems中的事件处理
因为实习项目中涉及到类似于时钟设置闹钟反复时间的原因须要使用对话框的方式呈现.因为DialogFragment眼下还没实验出嵌套Fragment的方法.所以临时先用AlertDialog.Builde ...
- Android平台音频信号FFT的实现
转载请标明出处:http://blog.csdn.net/sctu_vroy/article/details/45871823 功能:加载本地SD卡中moveDsp文件夹中的音频文件(包括录音获取文件 ...
- 开发汉澳即时通信网,2006年上线,QQ死期到了
为汉澳sinox用户打造即时通信网让大家用上即时通信软件 近期腾讯关闭了linuxQQ登录,汉澳 sinox也登陆不上.非windows用户再也不能用上即时通信软件了! 这是多么可悲的事,可是我们必须 ...