基于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++ 實(shí)現(xiàn)帶監(jiān)視哨的順序查找算法
這篇文章主要介紹了C++ 實(shí)現(xiàn)帶監(jiān)視哨的順序查找算法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03
一篇文章教你自己動(dòng)手實(shí)現(xiàn)C語(yǔ)言庫(kù)函數(shù)
這篇文章主要介紹了C語(yǔ)言庫(kù)函數(shù)的相關(guān)資料,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2021-09-09
C語(yǔ)言實(shí)現(xiàn)JSON解析器的方法步驟
JSON是一種非常流行的數(shù)據(jù)格式,本文主要介紹了C語(yǔ)言實(shí)現(xiàn)JSON解析器的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2024-08-08
C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單回聲服務(wù)器
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單回聲服務(wù)器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03
C語(yǔ)言遞歸應(yīng)用實(shí)現(xiàn)掃雷游戲
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言遞歸應(yīng)用實(shí)現(xiàn)掃雷游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-06-06

