代码拉取完成,页面将自动刷新
#ifndef TRIONVIDEOTHREAD_H
#define TRIONVIDEOTHREAD_H
#include <QElapsedTimer>
#include <QThread>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <QDateTime>
using namespace cv;
class TrionVideoThread : public QThread
{
Q_OBJECT
public:
TrionVideoThread(const chaar *filename);
void run();
void releaseCap();
int getVideoAllFramecount();
int getFps();
int getVideoTotalSeconds() const;
void setCurrentFrame(int value);
bool getStop() const;
void setStop(bool value);
bool getIsrun() const;
void setIsrun(bool value);
void pauseThread();
void resumeThread();
void stopThread();
signals:
void totalTimeChanged(qint64 total);
void currentTimeChanged(qint64 cur);
void sendFrame(int currentFrame, Mat frame);
private:
VideoCapture cap;
Mat frame;
int currentFramecount;
int allFramecount;
int fps;
int videoWriterFrame;
bool stop;
bool isrun;
int tatalTime;
};
#include "trionvideothread.h"
TrionVideoThread::TrionVideoThread(const char *filename)
{
this->stop = false;
this->isrun = false;
this->currentFramecount = 0;
this->videoWriterFrame = 0;
if (cap.open(filename))
{
this->allFramecount = cap.get(CAP_PROP_FRAME_COUNT);
this->fps = int(round(cap.get(CAP_PROP_FPS)));
this->tatalTime = allFramecount / fps;
}
}
void TrionVideoThread::run()
{
while (stop == false)
{
while (isrun == true)
{
if (cap.read(frame))
{
this->currentFramecount++;
cvtColor(frame, frame, COLOR_BGR2RGB);
emit sendFrame(currentFramecount, frame);
}
msleep(40);
}
}
cap.release();
}
int TrionVideoThread::getVideoAllFramecount() { return allFramecount; }
int TrionVideoThread::getFps() { return fps; }
int TrionVideoThread::getVideoTotalSeconds() const { return tatalTime; }
void TrionVideoThread::setStop(bool value) { stop = value; }
void TrionVideoThread::setCurrentFrame(int value)
{
this->currentFramecount = value;
cap.set(CAP_PROP_POS_FRAMES, currentFramecount);
}
bool TrionVideoThread::getIsrun() const { return isrun; }
void TrionVideoThread::setIsrun(bool value) { isrun = value; }
void TrionVideoThread::pauseThread()
{
if (this->isRunning() && this->isrun == true)
{
this->isrun = false;
}
}
void TrionVideoThread::resumeThread()
{
if (this->isRunning() && this->isrun == false)
{
this->isrun = true;
}
}
void TrionVideoThread::stopThread()
{
if (this->isRunning())
{
this->stop = true;
releaseCap();
this->terminate();
}
}
bool TrionVideoThread::getStop() const { return stop; }
void TrionVideoThread::releaseCap()
{
if (cap.isOpened())
{
cap.release();
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。