首页 技术 正文
技术 2022年11月14日
0 收藏 895 点赞 4,326 浏览 5179 个字

硬件

Point Gray Camera

型号:FL3-U3-13S2C-CS

参数

Sony IMX035 CMOS, 1/3″, 3.63 µm
Rolling Shutter
1328×1048 at 120 FPS

USB3.0

系统及环境

Windows 7 64bit

Qt 5.1

驱动:FlyCapture v2.5 Release 4 – Windows 64bit

硬件连接

将相机直接接到电脑的USB3.0接口上就可以了。

程序功能

调用摄像头拍照,并在窗口中显示结果拍照结果。

开发的过程中主要是参考官方的文档,在sdk安装的文件夹里就有。

代码清单

代码结构

很简单,就一个类。

基于Qt的图像采集系统

首先要在.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_OBJECTpublic:
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的图像采集系统

源码下载

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,497
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,910
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,744
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,498
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,136
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,301