Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Qt UI Viewer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Design Studio
QML Viewer Projects
Qt UI Viewer
Commits
323ff16d
Verified
Commit
323ff16d
authored
8 months ago
by
Burak Hançerli
Browse files
Options
Downloads
Patches
Plain Diff
enh: fix qr scanner issues and speed it up
parent
1b4446e0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!56
QDS-13458 Small fixes
Pipeline
#76313
passed
8 months ago
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/backend/backend.cpp
+4
-1
4 additions, 1 deletion
src/backend/backend.cpp
src/backend/backend.h
+2
-2
2 additions, 2 deletions
src/backend/backend.h
src/backend/qrscanner.cpp
+24
-38
24 additions, 38 deletions
src/backend/qrscanner.cpp
src/backend/qrscanner.h
+6
-1
6 additions, 1 deletion
src/backend/qrscanner.h
with
36 additions
and
42 deletions
src/backend/backend.cpp
+
4
−
1
View file @
323ff16d
...
@@ -217,9 +217,12 @@ void Backend::scanQrCode()
...
@@ -217,9 +217,12 @@ void Backend::scanQrCode()
m_qrScanner
.
reset
(
new
QrScanner
);
m_qrScanner
.
reset
(
new
QrScanner
);
connect
(
m_qrScanner
.
get
(),
&
QrScanner
::
qrCodeScanned
,
this
,
[
&
](
const
QString
&
qrCode
)
{
connect
(
m_qrScanner
.
get
(),
&
QrScanner
::
qrCodeScanned
,
this
,
[
&
](
const
QString
&
qrCode
)
{
qDebug
()
<<
"QR code scanned:"
<<
qrCode
;
qDebug
()
<<
"QR code scanned:"
<<
qrCode
;
parseDesignViewerUrl
(
QUrl
(
qrCode
));
m_qrScanner
.
reset
();
m_qrScanner
.
reset
();
parseDesignViewerUrl
(
QUrl
(
qrCode
));
});
});
connect
(
m_qrScanner
.
get
(),
&
QrScanner
::
windowClosed
,
this
,
[
&
]()
{
m_qrScanner
.
reset
();
});
m_qrScanner
->
scanQrCode
();
m_qrScanner
->
scanQrCode
();
}
}
...
...
This diff is collapsed.
Click to expand it.
src/backend/backend.h
+
2
−
2
View file @
323ff16d
...
@@ -42,8 +42,8 @@ public:
...
@@ -42,8 +42,8 @@ public:
private:
private:
// Other members
// Other members
std
::
unique_pt
r
<
ProjectManager
>
m_projectManager
;
QScopedPointe
r
<
ProjectManager
>
m_projectManager
;
std
::
unique_pt
r
<
QrScanner
>
m_qrScanner
;
QScopedPointe
r
<
QrScanner
>
m_qrScanner
;
// DS Connector
// DS Connector
QScopedPointer
<
DesignStudioManager
>
m_dsManager
;
QScopedPointer
<
DesignStudioManager
>
m_dsManager
;
...
...
This diff is collapsed.
Click to expand it.
src/backend/qrscanner.cpp
+
24
−
38
View file @
323ff16d
...
@@ -82,65 +82,54 @@ void QrScanner::openCamera()
...
@@ -82,65 +82,54 @@ void QrScanner::openCamera()
m_captureSession
.
reset
(
new
QMediaCaptureSession
(
this
));
m_captureSession
.
reset
(
new
QMediaCaptureSession
(
this
));
m_captureSession
->
setCamera
(
new
QCamera
(
this
));
m_captureSession
->
setCamera
(
new
QCamera
(
this
));
m_captureSession
->
setVideoOutput
(
new
CustomVideoWidget
);
m_captureSession
->
setVideoOutput
(
new
CustomVideoWidget
);
m_captureSession
->
camera
()
->
setFocusMode
(
QCamera
::
FocusModeAuto
);
m_captureSession
->
camera
()
->
setFocusMode
(
QCamera
::
FocusModeAuto
);
CustomVideoWidget
*
videoWidget
=
qobject_cast
<
CustomVideoWidget
*>
(
m_videoWidget
=
qobject_cast
<
CustomVideoWidget
*>
(
m_captureSession
->
videoOutput
());
m_captureSession
->
videoOutput
());
m_processing
=
0
;
ZXing
::
ReaderOptions
readerOptions
;
readerOptions
.
setTryRotate
(
false
);
readerOptions
.
setTryHarder
(
false
);
readerOptions
.
setTryInvert
(
false
);
readerOptions
.
setDownscaleFactor
(
2
);
connect
(
m_captureSession
->
videoSink
(),
connect
(
m_captureSession
->
videoSink
(),
&
QVideoSink
::
videoFrameChanged
,
&
QVideoSink
::
videoFrameChanged
,
this
,
this
,
[
&
](
const
QVideoFrame
&
frame
)
{
[
&
,
readerOptions
](
const
QVideoFrame
&
frame
)
{
static
QAtomicInt
i
=
0
;
static
QAtomicInt
running
=
0
;
if
(
i
++
<
20
||
running
>
0
)
{
return
;
}
i
=
0
;
if
(
!
frame
.
isValid
())
if
(
!
frame
.
isValid
())
return
;
return
;
if
(
!
m_processing
.
testAndSetOrdered
(
0
,
1
))
{
return
;
// Another task is already running
}
QtConcurrent
::
run
([
=
]
{
QtConcurrent
::
run
([
=
]
{
if
(
!
m_captureSession
)
if
(
!
m_captureSession
)
return
QList
<
Result
>
();
return
QList
<
Result
>
();
// lock the thread so that only one barcode can be read at a time
running
++
;
QElapsedTimer
timer
;
QElapsedTimer
timer
;
timer
.
start
();
timer
.
start
();
QList
<
Result
>
results
=
ReadBarcodes
(
frame
.
toImage
());
QList
<
Result
>
results
=
ReadBarcodes
(
frame
.
toImage
()
,
readerOptions
);
qDebug
()
<<
"Barcode detection took"
<<
timer
.
elapsed
()
<<
"ms"
;
qDebug
()
<<
"Barcode detection took"
<<
timer
.
elapsed
()
<<
"ms"
;
if
(
!
results
.
size
())
m_processing
=
0
;
return
results
;
return
results
;
}).
then
([
=
](
const
QList
<
Result
>
&
results
)
{
}).
then
([
=
](
const
QList
<
Result
>
&
results
)
{
if
(
results
.
isEmpty
()
||
!
m_captureSession
)
if
(
results
.
isEmpty
()
||
!
m_captureSession
)
return
;
return
;
qDebug
()
<<
"Stopping camera"
;
qobject_cast
<
CustomVideoWidget
*>
(
m_captureSession
->
videoOutput
())
->
close
();
qDebug
()
<<
"Camera stopped"
;
Result
result
=
results
.
first
();
Result
result
=
results
.
first
();
qDebug
()
<<
"Text: "
<<
result
.
text
();
qDebug
()
<<
"Text: "
<<
result
.
text
();
qDebug
()
<<
"Format: "
<<
result
.
format
();
qDebug
()
<<
"Format: "
<<
result
.
format
();
qDebug
()
<<
"Content:"
<<
result
.
contentType
();
qDebug
()
<<
"Content:"
<<
result
.
contentType
();
qDebug
()
<<
"Position:"
<<
result
.
position
().
bottomLeft
()
<<
result
.
position
().
bottomRight
()
<<
result
.
position
().
topLeft
()
<<
result
.
position
().
topRight
();
// we have to use invokeMethod because we are in a different thread
// then where the serviceConnector is created
// QMetaObject::invokeMethod(this,
// "parseDesignViewerUrl",
// Qt::QueuedConnection,
// Q_ARG(QUrl, result.text()));
emit
qrCodeScanned
(
result
.
text
());
emit
qrCodeScanned
(
result
.
text
());
// release the lock so that another barcode can be read
running
--
;
});
});
});
});
...
@@ -155,15 +144,12 @@ void QrScanner::openCamera()
...
@@ -155,15 +144,12 @@ void QrScanner::openCamera()
});
});
// stop camera when video widget is closed
// stop camera when video widget is closed
connect
(
videoWidget
,
&
CustomVideoWidget
::
closed
,
this
,
[
&
]
{
connect
(
m_videoWidget
,
&
CustomVideoWidget
::
closed
,
this
,
[
&
]
{
qDebug
()
<<
"Video widget closed. Clearing capture session"
;
qDebug
()
<<
"Video widget closed."
;
m_captureSession
->
camera
()
->
stop
();
emit
windowClosed
();
m_captureSession
->
camera
()
->
deleteLater
();
m_captureSession
->
videoOutput
()
->
deleteLater
();
m_captureSession
.
clear
();
});
});
videoWidget
->
setWindowFlags
(
Qt
::
Window
|
Qt
::
WindowStaysOnTopHint
);
m_
videoWidget
->
setWindowFlags
(
Qt
::
Window
|
Qt
::
WindowStaysOnTopHint
);
videoWidget
->
show
();
m_
videoWidget
->
show
();
m_captureSession
->
camera
()
->
start
();
m_captureSession
->
camera
()
->
start
();
}
}
This diff is collapsed.
Click to expand it.
src/backend/qrscanner.h
+
6
−
1
View file @
323ff16d
...
@@ -25,7 +25,9 @@
...
@@ -25,7 +25,9 @@
#pragma once
#pragma once
#include
<QList>
#include
<QMediaCaptureSession>
#include
<QMediaCaptureSession>
#include
<QRect>
#include
<QVideoWidget>
#include
<QVideoWidget>
class
CustomVideoWidget
:
public
QVideoWidget
class
CustomVideoWidget
:
public
QVideoWidget
...
@@ -35,8 +37,8 @@ public:
...
@@ -35,8 +37,8 @@ public:
explicit
CustomVideoWidget
(
QWidget
*
parent
=
nullptr
)
explicit
CustomVideoWidget
(
QWidget
*
parent
=
nullptr
)
:
QVideoWidget
(
parent
)
:
QVideoWidget
(
parent
)
{}
{}
~
CustomVideoWidget
()
override
{}
~
CustomVideoWidget
()
override
{}
void
closeEvent
(
QCloseEvent
*
)
override
{
emit
closed
();
}
void
closeEvent
(
QCloseEvent
*
)
override
{
emit
closed
();
}
signals
:
signals
:
...
@@ -52,9 +54,12 @@ public:
...
@@ -52,9 +54,12 @@ public:
private:
private:
QSharedPointer
<
QMediaCaptureSession
>
m_captureSession
;
QSharedPointer
<
QMediaCaptureSession
>
m_captureSession
;
CustomVideoWidget
*
m_videoWidget
;
QAtomicInt
m_processing
;
void
openCamera
();
void
openCamera
();
signals:
signals:
void
qrCodeScanned
(
const
QString
&
qrCode
);
void
qrCodeScanned
(
const
QString
&
qrCode
);
void
windowClosed
();
};
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment