Skip to content

Commit dea74ec

Browse files
author
Nicola
committed
Add decoder
1 parent 7a0ec6e commit dea74ec

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

ocvdecoder.cpp

+24-3
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@ using namespace std;
77

88
OCVDecoder::OCVDecoder(QObject *parent): QObject(parent)
99
{
10-
m_detector = makePtr<wechat_qrcode::WeChatQRCode>("", "", "", "");
10+
QString path = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
11+
12+
m_detector = makePtr<wechat_qrcode::WeChatQRCode>("" , "" ,
13+
"", "");
1114
}
1215

1316
void OCVDecoder::setFrame(const QVideoFrame &frame)
1417
{
15-
if(!isDecoding() && m_processThread.isFinished()) {
18+
if (m_run && !isDecoding() && m_processThread.isFinished()) {
19+
qDebug() << "DECODING1\n";
1620
m_decoding = true;
1721
QImage image = frame.toImage().convertToFormat(QImage::Format_RGB32).rgbSwapped();
1822

1923
m_processThread = QtConcurrent::run([=]() {
20-
24+
qDebug() << "DECODING2\n";
2125
if(image.isNull()) {
2226
m_decoding = false;
2327
return;
@@ -30,6 +34,8 @@ void OCVDecoder::setFrame(const QVideoFrame &frame)
3034
for (const auto& value : res) {
3135
qDebug() << " opencv " << QString(value.c_str());
3236
emit decoded(QString(value.c_str()));
37+
m_run = false;
38+
break;
3339
}
3440
}
3541
m_decoding = false;
@@ -48,6 +54,10 @@ void OCVDecoder::setVideoSink(QObject *videoSync)
4854
}
4955
}
5056

57+
void OCVDecoder::setRun(bool run)
58+
{
59+
m_run = run;
60+
}
5161

5262
// https://asmaloney.com/2013/11/code/converting-between-cvmat-and-qimage-or-qpixmap/
5363

@@ -134,3 +144,14 @@ static cv::Mat QImageToCvMat(QImage inImage, bool inCloneImageData = true)
134144

135145
return cv::Mat();
136146
}
147+
148+
OCVDecoder::~OCVDecoder()
149+
{
150+
if(!m_processThread.isFinished()) {
151+
m_processThread.cancel();
152+
m_processThread.waitForFinished();
153+
}
154+
if (m_detector) {
155+
delete m_detector;
156+
}
157+
}

ocvdecoder.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ class OCVDecoder: public QObject
1515
Q_OBJECT
1616
QML_ELEMENT
1717
Q_PROPERTY(QObject* videoSink WRITE setVideoSink)
18-
18+
Q_PROPERTY(bool run READ run WRITE setRun)
1919
public:
2020
OCVDecoder(QObject *parent = nullptr);
21+
~OCVDecoder();
2122
void setVideoSink(QObject *videoSink);
2223
bool isDecoding() {return m_decoding; }
24+
bool run() {return m_run;}
25+
void setRun(bool run);
2326

2427
public slots:
2528
void setFrame(const QVideoFrame &frame);
@@ -34,6 +37,7 @@ public slots:
3437
Ptr<wechat_qrcode::WeChatQRCode> m_detector;
3538
QFuture<void> m_processThread;
3639
bool m_decoding;
40+
bool m_run;
3741
};
3842

3943
#endif // OCVDECODER_H

0 commit comments

Comments
 (0)