-
大小: 5.77MB文件類型: .rar金幣: 2下載: 0 次發布日期: 2023-09-26
- 語言: 其他
- 標簽:
資源簡介
當有攝像頭接入時,則采集實時視頻顯示到界面并且使用子線程保存視頻,并且當檢測到有服務器連接時,則發送每幀圖像到服務器,并且實時顯示。當沒有檢測到攝像頭時,可以打開保存的錄像視頻,顯示到界面播放的同時通過tcp協議發送到服務器端顯示。

代碼片段和文件信息
#include?“camaraget.h“
#include?“ui_camaraGet.h“
camaraGet::camaraGet(QWidget?*parent)?:
????QWidget(parent)
????ui(new?Ui::camaraGet)
{
????ui->setupUi(this);
????op=0;
????ui->label->setScaledContents(true);
????ui->label_2->setScaledContents(true);
????video=0;
????timer=new?QTimer();
????camthread=new?Camthread();
????tcpSocket=new?QTcpSocket();
????/*信號和槽*/
????//message=QString(“OK“);
????connect(tcpSocketSIGNAL(readyRead())thisSLOT(readMessage()));
????connect(camthreadSIGNAL(sig_GetOneframe(QImage))thisSLOT(readFarme(QImage?)));
????//connect(timer?SIGNAL(timeout())?this?SLOT(readFarme()));??//?時間到,讀取當前攝像頭信息
????connect(ui->open?SIGNAL(clicked())?this?SLOT(openCamara()));
????connect(ui->pic?SIGNAL(clicked())?this?SLOT(takingPictures()));
????connect(ui->closeCam?SIGNAL(clicked())?this?SLOT(closeCamara()));
??//??connect(tcpSocketSIGNAL(error(QAbstractSocket::SocketError))this
??//??????????SLOT(displayerror(QAbstractSocket::SocketError)));
}
void?camaraGet::openCamara()
{
????if(op==1)
????{
????????return?;
????}
????connect(camthreadSIGNAL(sig_err(QString))thisSLOT(?openvideo()));
????camthread->startPlay();
????op=1;
}
void?camaraGet::openvideo()
{
????op=0;
????QMessageBox::warning(this“Warning““Cameras?are?not?found.“);
????//connect(ui->open?SIGNAL(clicked())?this?SLOT(openvideo()));
????QString?filename?=?QFileDialog::getOpenFileName(thistr(“action“)
???????????????????????“./“
????????????????????????“Image?file(*.AVI?*.MP4)“0)?;
????if?(!filename.isEmpty())
????{
????????cap.open(filename.toLatin1().data());
?????}
????if(!cap.isOpened()){
????????QMessageBox::information(thistr(“提示“)tr(“視頻沒有打開“));
????????video=0;
????}
????else
???????video=1;
????timer->start(50);
????connect(timer?SIGNAL(timeout())?this?SLOT(readFarme()));
????connect(ui->open?SIGNAL(clicked())?this?SLOT(openCamara()));
????connect(ui->pic?SIGNAL(clicked())?this?SLOT(takingPictures()));
????connect(ui->closeCam?SIGNAL(clicked())?this?SLOT(closeCamara()));
????connect(tcpSocketSIGNAL(readyRead())thisSLOT(readMessage()));
}
void?camaraGet::readMessage()
{
?????qDebug()<<4;
?????qDebug()?<????QDataStream?in(tcpSocket);
?????//in.setVersion(QDataStream::Qt_4_6);
?????if?(blockSize?==?0)?{
????????????//判斷接收的數據是否大于兩字節,也就是文件的大小信息所占的空間
????????????//如果是則保存到blockSize變量中,否則直接返回,繼續接收數據
????????????if(tcpSocket->bytesAvailable()?(int)sizeof(quint16))?return;??//bytesAvailable()返回字節數
????????????in?>>?blockSize;
????????}
?????if(tcpSocket->bytesAvailable()?????????//?將接收到的數據存放到變量中
?????????in?>>?message;
?????????//?顯示接收到的數據*/
????????//?qDebug()?<
}
void?camaraGet::readFarme()
{
????blockSize=0;//數據大小初始化為0
????tcpSocket->abort();//取消已有鏈接
????//連接到某個ip的某個端口,
????tcpSocket->connectToHost(QHostAddress::LocalHost8888);
????if(video)
????{
????????qDebug()<<“baofang?shipin?!“;
????????Mat?frame;
????????//cap>>frame;
????????if(cap.read(frame))
???????{
????????????cvt
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????174??2017-02-16?16:38??server\main.cpp
?????文件???????1592??2017-05-10?22:34??server\main.o
?????文件???????8382??2017-02-16?16:45??server\Makefile
?????文件???????3133??2017-05-10?22:34??server\moc_server.cpp
?????文件???????7532??2017-05-10?22:34??server\moc_server.o
?????文件??????30811??2017-05-10?22:34??server\server
?????文件???????3641??2017-05-10?22:33??server\server.cpp
?????文件????????710??2017-05-10?22:34??server\server.h
?????文件???????9984??2017-05-10?22:34??server\server.o
?????文件????????311??2017-02-16?16:45??server\server.pro
?????文件??????27251??2017-05-10?22:34??server\server.pro.user
?????文件????????700??2017-02-16?16:46??server\server.ui
?????文件???????1554??2017-02-16?16:46??server\ui_server.h
?????文件???????6684??2017-05-10?23:07??paizhao\camaraget.cpp
?????文件???????1087??2017-05-10?22:00??paizhao\camaraget.h
?????文件??????23904??2017-05-10?23:08??paizhao\camaraget.o
?????文件???????1803??2017-05-09?10:45??paizhao\camaraGet.ui
?????文件???????1841??2017-05-10?23:10??paizhao\camthread.cpp
?????文件????????866??2017-05-09?11:03??paizhao\camthread.h
?????文件???????4640??2017-05-10?23:08??paizhao\camthread.o
?????文件????????180??2016-04-27?11:19??paizhao\main.cpp
?????文件???????2088??2017-05-10?22:00??paizhao\main.o
?????文件???????8998??2017-05-09?10:54??paizhao\Makefile
?????文件???????3346??2017-05-10?22:00??paizhao\moc_camaraget.cpp
?????文件???????8540??2017-05-10?22:00??paizhao\moc_camaraget.o
?????文件???????3471??2017-05-09?11:04??paizhao\moc_camthread.cpp
?????文件???????5468??2017-05-09?11:04??paizhao\moc_camthread.o
?????文件??????52021??2017-05-10?23:08??paizhao\paizhao
?????文件????????367??2017-05-09?10:53??paizhao\paizhao.pro
?????文件??????27221??2017-05-10?22:34??paizhao\paizhao.pro.user
............此處省略7個文件信息
- 上一篇:電子線路謝嘉奎編第四版答案
- 下一篇:hibernate3.6.7
評論
共有 條評論