Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
1fb7ee0e
Commit
1fb7ee0e
authored
Aug 07, 2018
by
Alexander Nesterov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimiaztion search template lines and added sample
parent
d7885ed8
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
172 additions
and
2 deletions
+172
-2
qrcode.cpp
modules/objdetect/src/qrcode.cpp
+0
-0
test_qrcode.cpp
modules/objdetect/test/test_qrcode.cpp
+2
-2
live_detect_qrcode.cpp
samples/cpp/live_detect_qrcode.cpp
+170
-0
No files found.
modules/objdetect/src/qrcode.cpp
View file @
1fb7ee0e
This diff is collapsed.
Click to expand it.
modules/objdetect/test/test_qrcode.cpp
View file @
1fb7ee0e
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
namespace
opencv_test
{
namespace
{
namespace
opencv_test
{
namespace
{
std
::
string
qrcode_images_name
[]
=
{
std
::
string
qrcode_images_name
[]
=
{
"20110817_030.jpg"
,
//
"20110817_030.jpg",
"20110817_048.jpg"
,
"20110817_048.jpg"
,
"img_20120226_161648.jpg"
,
"img_20120226_161648.jpg"
,
"img_2714.jpg"
,
"img_2714.jpg"
,
...
@@ -63,7 +63,7 @@ TEST_P(Objdetect_QRCode, regression)
...
@@ -63,7 +63,7 @@ TEST_P(Objdetect_QRCode, regression)
ASSERT_FALSE
(
src
.
empty
())
<<
"Can't read image: "
<<
image_path
;
ASSERT_FALSE
(
src
.
empty
())
<<
"Can't read image: "
<<
image_path
;
std
::
vector
<
Point
>
corners
;
std
::
vector
<
Point
>
corners
;
EXPEC
T_TRUE
(
detectQRCode
(
src
,
corners
));
ASSER
T_TRUE
(
detectQRCode
(
src
,
corners
));
const
std
::
string
dataset_config
=
findDataFile
(
root
+
"dataset_config.json"
,
false
);
const
std
::
string
dataset_config
=
findDataFile
(
root
+
"dataset_config.json"
,
false
);
FileStorage
file_config
(
dataset_config
,
FileStorage
::
READ
);
FileStorage
file_config
(
dataset_config
,
FileStorage
::
READ
);
...
...
samples/cpp/live_detect_qrcode.cpp
0 → 100644
View file @
1fb7ee0e
#include "opencv2/objdetect.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <string>
#include <iostream>
using
namespace
std
;
using
namespace
cv
;
void
getMatWithQRCodeContour
(
Mat
&
color_image
,
vector
<
Point
>
transform
);
void
getMatWithFPS
(
Mat
&
color_image
,
double
fps
);
int
liveQRCodeDetect
();
int
showImageQRCodeDetect
(
string
in
,
string
out
);
int
main
(
int
argc
,
char
*
argv
[])
{
const
string
keys
=
"{h help ? | | print help messages }"
"{i in | | input path to file for detect (with parameter - show image, otherwise - camera)}"
"{o out | | output path to file (save image, work with -i parameter) }"
;
CommandLineParser
cmd_parser
(
argc
,
argv
,
keys
);
cmd_parser
.
about
(
"This program detects the QR-codes from camera or images using the OpenCV library."
);
if
(
cmd_parser
.
has
(
"help"
))
{
cmd_parser
.
printMessage
();
return
0
;
}
string
in_file_name
=
cmd_parser
.
get
<
string
>
(
"in"
);
// input path to image
string
out_file_name
=
cmd_parser
.
get
<
string
>
(
"out"
);
// output path to image
if
(
!
cmd_parser
.
check
())
{
cmd_parser
.
printErrors
();
return
-
1
;
}
int
return_code
=
0
;
if
(
in_file_name
.
empty
())
{
return_code
=
liveQRCodeDetect
();
}
else
{
return_code
=
showImageQRCodeDetect
(
in_file_name
,
out_file_name
);
}
return
return_code
;
}
void
getMatWithQRCodeContour
(
Mat
&
color_image
,
vector
<
Point
>
transform
)
{
if
(
!
transform
.
empty
())
{
double
show_radius
=
(
color_image
.
rows
>
color_image
.
cols
)
?
(
2.813
*
color_image
.
rows
)
/
color_image
.
cols
:
(
2.813
*
color_image
.
cols
)
/
color_image
.
rows
;
double
contour_radius
=
show_radius
*
0.4
;
vector
<
vector
<
Point
>
>
contours
;
contours
.
push_back
(
transform
);
drawContours
(
color_image
,
contours
,
0
,
Scalar
(
211
,
0
,
148
),
cvRound
(
contour_radius
));
RNG
rng
(
1000
);
for
(
size_t
i
=
0
;
i
<
4
;
i
++
)
{
Scalar
color
=
Scalar
(
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
));
circle
(
color_image
,
transform
[
i
],
cvRound
(
show_radius
),
color
,
-
1
);
}
}
}
void
getMatWithFPS
(
Mat
&
color_image
,
double
fps
)
{
ostringstream
convert
;
convert
<<
cvRound
(
fps
)
<<
" FPS."
;
putText
(
color_image
,
convert
.
str
(),
Point
(
25
,
25
),
FONT_HERSHEY_DUPLEX
,
1
,
Scalar
(
0
,
0
,
255
),
2
);
}
int
liveQRCodeDetect
()
{
VideoCapture
cap
(
0
);
if
(
!
cap
.
isOpened
())
{
cout
<<
"Cannot open a camera"
<<
'\n'
;
return
-
4
;
}
TickMeter
total
;
for
(;;)
{
Mat
frame
,
src
;
vector
<
Point
>
transform
;
cap
>>
frame
;
if
(
frame
.
empty
())
{
break
;
}
cvtColor
(
frame
,
src
,
COLOR_BGR2GRAY
);
total
.
start
();
bool
result_detection
=
detectQRCode
(
src
,
transform
);
total
.
stop
();
double
fps
=
1
/
total
.
getTimeSec
();
total
.
reset
();
if
(
result_detection
)
{
getMatWithQRCodeContour
(
frame
,
transform
);
}
getMatWithFPS
(
frame
,
fps
);
imshow
(
"Live detect QR code"
,
frame
);
if
(
waitKey
(
30
)
>
0
)
{
break
;
}
}
return
0
;
}
int
showImageQRCodeDetect
(
string
in
,
string
out
)
{
Mat
src
=
imread
(
in
,
IMREAD_GRAYSCALE
);
vector
<
Point
>
transform
;
const
int
count_experiments
=
10
;
double
transform_time
=
0.0
;
bool
result_detection
=
false
;
TickMeter
total
;
for
(
size_t
i
=
0
;
i
<
count_experiments
;
i
++
)
{
total
.
start
();
transform
.
clear
();
result_detection
=
detectQRCode
(
src
,
transform
);
total
.
stop
();
transform_time
+=
total
.
getTimeSec
();
if
(
!
result_detection
)
{
break
;
}
total
.
reset
();
}
double
fps
=
count_experiments
/
transform_time
;
if
(
!
result_detection
)
{
cout
<<
"Not find QR-code."
<<
'\n'
;
return
-
2
;
}
Mat
color_src
=
imread
(
in
);
getMatWithQRCodeContour
(
color_src
,
transform
);
getMatWithFPS
(
color_src
,
fps
);
for
(;;)
{
imshow
(
"Detect QR code on image"
,
color_src
);
if
(
waitKey
(
30
)
>
0
)
{
break
;
}
}
if
(
!
out
.
empty
())
{
getMatWithQRCodeContour
(
color_src
,
transform
);
getMatWithFPS
(
color_src
,
fps
);
cout
<<
"Input image file path: "
<<
in
<<
'\n'
;
cout
<<
"Output image file path: "
<<
out
<<
'\n'
;
cout
<<
"Size: "
<<
color_src
.
size
()
<<
'\n'
;
cout
<<
"FPS: "
<<
fps
<<
'\n'
;
vector
<
int
>
compression_params
;
compression_params
.
push_back
(
IMWRITE_PNG_COMPRESSION
);
compression_params
.
push_back
(
9
);
try
{
imwrite
(
out
,
color_src
,
compression_params
);
}
catch
(
cv
::
Exception
&
ex
)
{
cout
<<
"Exception converting image to PNG format: "
;
cout
<<
ex
.
what
()
<<
'\n'
;
return
-
3
;
}
}
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment