基于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] ...
随机推荐
- 在windows下,git webhook使用php拉取代码的学习总结
原来上传代码到测试服务器都是用ftp,我觉得这种方式很低效,而且容易出错,比如忘记传某个修改过文件. 现在项目的代码放在了git@osc上了,想使用他webhook,每当有push的时候,git@os ...
- #CI的MVC实现
CI的MVC实现 CI被标榜为一款简单易用的框架,经过一段时间的了解后,它的小而精给让我印象深刻.麻雀虽小五脏俱全,一个框架产品包含太多的特性,这篇文章就说说CI中是如何实现MVC的? 执行流程 根据 ...
- Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Chinese_PRC_CI_AS" in the equal to operation.
Scenario : 这个问题是我的存储过程中用到临时表时发生的. 应该是sql server 服务器的排序规则 (SQL_Latin1_General_CP1_CI_AS ) 与数据库的排序规则(C ...
- Linux查看网卡状态
观看网卡传送.接收数据包的状态 $ netstat -i Kernel Interface table Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK ...
- DLL中传递STL参数,vector对象作为dll参数传递等问题(转)
STL跨平台调用会出现很多异常,你可以试试. STL使用模板生成,当我们使用模板的时候,每一个EXE,和DLL都在编译器产生了自己的代码,导致模板所使用的静态成员不同步,所以出现数据传递的各种问题,下 ...
- java 泛型深入之Set有用工具 各种集合泛型深入使用演示样例,匿名内部类、内部类应用于泛型探讨
java 泛型深入之Set有用工具 各种集合泛型深入使用演示样例,匿名内部类.内部类应用于泛型探讨 //Sets.java package org.rui.generics.set; import j ...
- C#DataTable学习心得
C#DataTable学习心得 一.DataSet.DataTable.DataRow.DataColumn 1] 在DataSet中添加DataTable DataSet.Tables.Add(Da ...
- iOS - SQLite Database 操作数据库
iOS - SQLite Database 操作数据库 Sqlite 能被用在ios上做数据处理用,只要你懂得一点sql 就很容易使用sqlite 1:创建一个简单的View based appl ...
- mantis 中文统计报表乱码问题解决办法
mantis 中文报表乱码问题 1.安装mantisTB 1.2.17:a.安装插件:管理-->插件管理-->安装MantisGraph(Mantis图表 1.0) 插件b.修改配置文件: ...
- getopt()函数
在讨论这个函数之前我们先理解两个概念:选项及其参数 gcc -o program program.c 在上述命令中 -o 就是其选项 program就是参数. getopt(): 头文件: #incl ...