@@ -7,17 +7,21 @@ using namespace std;
7
7
8
8
OCVDecoder::OCVDecoder (QObject *parent): QObject(parent)
9
9
{
10
- m_detector = makePtr<wechat_qrcode::WeChatQRCode>(" " , " " , " " , " " );
10
+ QString path = QStandardPaths::writableLocation (QStandardPaths::AppLocalDataLocation);
11
+
12
+ m_detector = makePtr<wechat_qrcode::WeChatQRCode>(" " , " " ,
13
+ " " , " " );
11
14
}
12
15
13
16
void OCVDecoder::setFrame (const QVideoFrame &frame)
14
17
{
15
- if (!isDecoding () && m_processThread.isFinished ()) {
18
+ if (m_run && !isDecoding () && m_processThread.isFinished ()) {
19
+ qDebug () << " DECODING1\n " ;
16
20
m_decoding = true ;
17
21
QImage image = frame.toImage ().convertToFormat (QImage::Format_RGB32).rgbSwapped ();
18
22
19
23
m_processThread = QtConcurrent::run ([=]() {
20
-
24
+ qDebug () << " DECODING2 \n " ;
21
25
if (image.isNull ()) {
22
26
m_decoding = false ;
23
27
return ;
@@ -30,6 +34,8 @@ void OCVDecoder::setFrame(const QVideoFrame &frame)
30
34
for (const auto & value : res) {
31
35
qDebug () << " opencv " << QString (value.c_str ());
32
36
emit decoded (QString (value.c_str ()));
37
+ m_run = false ;
38
+ break ;
33
39
}
34
40
}
35
41
m_decoding = false ;
@@ -48,6 +54,10 @@ void OCVDecoder::setVideoSink(QObject *videoSync)
48
54
}
49
55
}
50
56
57
+ void OCVDecoder::setRun (bool run)
58
+ {
59
+ m_run = run;
60
+ }
51
61
52
62
// https://asmaloney.com/2013/11/code/converting-between-cvmat-and-qimage-or-qpixmap/
53
63
@@ -134,3 +144,14 @@ static cv::Mat QImageToCvMat(QImage inImage, bool inCloneImageData = true)
134
144
135
145
return cv::Mat ();
136
146
}
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
+ }
0 commit comments