基于Qt OpenCV實(shí)現(xiàn)圖像數(shù)據(jù)采集軟件
效果圖
示例代碼
#ifndef WIDGET_H #define WIDGET_H #include <QWidget> #include<QTimer> #include<QDebug> #include<QDateTime> #include<opencv2/opencv.hpp> using namespace cv; using namespace std; QT_BEGIN_NAMESPACE namespace Ui { class Widget; } QT_END_NAMESPACE class Widget : public QWidget { Q_OBJECT public: Widget(QWidget *parent = nullptr); ~Widget(); private slots: void updateLabel();//刷新label void on_button_getimage_start_clicked(); void on_button_getimage_end_clicked(); void on_button_opencapture_clicked(); private: Ui::Widget *ui; VideoCapture capture; QTimer *updatetimer;//視頻刷新定時(shí)器 Mat src; QImage image_src; bool saveflag; int i=0; }; #endif // WIDGET_H
#include "widget.h" #include "ui_widget.h" Widget::Widget(QWidget *parent) : QWidget(parent) , ui(new Ui::Widget) { ui->setupUi(this); saveflag=false; this->setWindowTitle("image capturer"); //關(guān)于刷新 updatetimer=new QTimer(this); connect(updatetimer,&QTimer::timeout,this,&Widget::updateLabel); } Widget::~Widget() { delete ui; } //視頻刷新 void Widget::updateLabel() { if(!capture.isOpened()) { qDebug()<<"capture error!"; return; } else { capture>>src; if(src.empty()) { qDebug()<<"src is empty!"; return; } else { if(saveflag) { QDateTime now_time = QDateTime::currentDateTime(); QString file_n_qstr="D:\\image_get\\cup\\"+now_time.toString("yyyyMMddhhmmss")+QString::number(i)+".jpg"; string file_n_str=file_n_qstr.toStdString(); imwrite(file_n_str,src); qDebug()<<file_n_qstr; i++; //save } //原圖 image_src =QImage((const unsigned char*)(src.data),src.cols,src.rows,src.cols*src.channels(),QImage::Format_BGR888); ui->label_show->setPixmap(QPixmap::fromImage(image_src)); } } } void Widget::on_button_getimage_start_clicked() { qDebug()<<"on_button_getimage_start_clicked"; saveflag=true; } void Widget::on_button_getimage_end_clicked() { qDebug()<<"on_button_getimage_end_clicked"; saveflag=false; } void Widget::on_button_opencapture_clicked() { qDebug()<<"start button is clicked"; capture.open(0); if(!capture.isOpened()) { qDebug()<<"open capture failed!"; } else { updatetimer->start(30); qDebug()<<"open capture success!"; } }
到此這篇關(guān)于基于Qt OpenCV實(shí)現(xiàn)圖像數(shù)據(jù)采集軟件的文章就介紹到這了,更多相關(guān)Qt OpenCV圖像數(shù)據(jù)采集軟件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家
相關(guān)文章
C語(yǔ)言經(jīng)典例程100例(經(jīng)典c程序100例)
這篇文章主要介紹了C語(yǔ)言經(jīng)典例程100例,經(jīng)典c程序100例,學(xué)習(xí)c語(yǔ)言的朋友可以參考一下2018-03-03c++10進(jìn)制轉(zhuǎn)換為任意2-16進(jìn)制數(shù)字的實(shí)例
下面小編就為大家?guī)?lái)一篇c++10進(jìn)制轉(zhuǎn)換為任意2-16進(jìn)制數(shù)字的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-06-06C語(yǔ)言完整實(shí)現(xiàn)12種排序算法(小結(jié))
本文主要介紹了C語(yǔ)言完整實(shí)現(xiàn)12種排序算法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05C++?AVL樹(shù)插入新節(jié)點(diǎn)后的四種調(diào)整情況梳理介紹
AVL樹(shù)是高度平衡的而二叉樹(shù),它的特點(diǎn)是AVL樹(shù)中任何節(jié)點(diǎn)的兩個(gè)子樹(shù)的高度最大差別為1,本文主要給大家介紹了C++如何實(shí)現(xiàn)AVL樹(shù),需要的朋友可以參考下2022-08-08C++實(shí)現(xiàn)LeetCode(56.合并區(qū)間)
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(56.合并區(qū)間),本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07C++實(shí)現(xiàn)LeetCode(55.跳躍游戲)
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(55.跳躍游戲),本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07Linux下控制(統(tǒng)計(jì))文件的生成的C代碼實(shí)現(xiàn)
這篇文章主要介紹了Linux下控制(統(tǒng)計(jì))文件的生成的C代碼實(shí)現(xiàn),感興趣的小伙伴們可以參考一下2016-01-01