基于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] ...
随机推荐
- Python下的机器学习工具sklearn--数据预处理
1.数据标准化(Standardization or Mean Removal and Variance Scaling) 进行标准化缩放的数据均值为0,具有单位方差. from sklearn im ...
- C语言 —— 括号配对问题(不使用栈)
最近在南阳理工的OJ上刷题,看到一个有点意思的题目 网上的答案大多都使用了栈,可惜我还没有学习数据结构,所以只能用简单的方法来解决 题目的链接在这 http://acm.nyist.net/Judge ...
- openjpa框架入门_项目框架搭建(二)
Openjpa2.2+Mysql+Maven+Servlet+JSP 首先说明几点,让大家更清楚整体结构: 官方source code 下载:http://openjpa.apache.org/dow ...
- Struts 2.3.4.1完整示例
[系统环境]Windows 7 Ultimate 64 Bit [开发环境]JDK1.6.21,Tomcat6.0.35,MyEclipse10 [其他环境]Struts2.3.4.1 [项目描述]S ...
- Android中API建议的方式实现SQLite数据库的增、删、改、查的操作
package com.examp.use_SQLite.dao; import java.util.ArrayList; import java.util.List; import android. ...
- 兼容所有浏览器的CSS3圆角
兼容所有浏览器的CSS3圆角 解决CSS3圆角兼容所有浏览器的方法.本文提到了一种很不错的实现跨浏览器圆角的解决方案,但是说的不够全面,前端观察最近将整理更多更全面的资源给大家,敬请期待. ...
- 理解JS闭包
从事web开发工作,尤其主要是做服务器端开发的,难免会对客户端语言JavaScript一些概念有些似懂非懂的,甚至仅停留在实现功能的层面上,接下来的文章,是记录我对JavaScript的一些概念的理解 ...
- 剑指offier77页
/* * 输入字母判断第几列 */ import java.util.Scanner; public class JudgeClumns { public static void main(Strin ...
- Euclid gcd规则的证明
Euclid 规则:如果x和y都是正整数,而且x>=y,那么gcd(x,y)=gcd(x mod y, y) 假设x和y的gcd为a,那么必然有 x=a*n1 y=a*n2(gcd(n1,n2) ...
- IS--A与 Has-a 区别