基于Qt的图像采集系统
来源:互联网 发布:步步高录音电话软件 编辑:程序博客网 时间:2024/04/29 21:04
硬件
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的图像采集系统
- 基于AXI VDMA的图像采集系统
- 基于TMS320F2812的视频图像采集系统的设计
- 基于OV6630图像传感器和DSP的图像采集系统设计
- 基于ARM的图像采集和数据传输系统
- 基于ARM的图像采集和数据传输系统
- [转]基于AXI VDMA的图像采集系统
- 基于Video4Linux的图像采集
- 基于Qt Quick与opencv实现的图像处理系统
- 基于BF533 的 图像采集与显示
- 基于V4L2的摄像头图像采集
- 基于USB的嵌入式CCD图像数据采集系统的实现
- 基于PCI总线的嵌入式实时DSP图像采集系统-MIPS分析
- 基于PCI总线的嵌入式实时DSP图像采集系统(转)
- 基于ARM9的视频采集传输系统
- 基于DSP的视频采集系统设计
- 基于ARM的脑电信号采集系统
- 基于ARM9的视频采集传输系统
- Android 不同应用通过SharedPreference实现共享数据
- JAVA性能测试初体验
- 使用Robotium & UIAutomator构建基于twitter的测试
- Hibernate中用hql查询部分字段 可解决异常java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to
- delphi copy 字符串部分复制
- 基于Qt的图像采集系统
- 基于MVC设计模式的WEB应用框架研究
- 设计模式(命令模式)
- asp.net返回json 动态生成jQuery Easyui tree
- C++ AMP: 在C++中Lambda表达式
- Android获取手机屏幕分辨率
- matlab 函数零散记录
- iOS学习之UINavigationController详解与使用(一)
- 让VisualSVN可以在客户端修改密码