1 Star 0 Fork 0

MerlotRain/m2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
trionvideothread.h 3.01 KB
一键复制 编辑 原始数据 按行查看 历史
MerlotRain 提交于 2024-05-11 09:59 . add trionvideothread.h.
#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();
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/merlotrain/m2.git
git@gitee.com:merlotrain/m2.git
merlotrain
m2
m2
master

搜索帮助