Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2e4145d

Browse files
author
Alex
committed
add GenericGraphicalCode, remove QRCodeDetectorBase
1 parentaf03e00 commit2e4145d

File tree

6 files changed

+121
-111
lines changed

6 files changed

+121
-111
lines changed

‎modules/objdetect/include/opencv2/objdetect.hpp‎

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
#include"opencv2/core.hpp"
4848
#include"opencv2/objdetect/aruco_detector.hpp"
49+
#include"opencv2/objdetect/generic_graphical_code.hpp"
4950

5051
/**
5152
@defgroup objdetect Object Detection
@@ -763,80 +764,7 @@ class CV_EXPORTS_W QRCodeEncoder {
763764
CV_WRAPvirtualvoidencodeStructuredAppend(const String& encoded_info, OutputArrayOfArrays qrcodes) = 0;
764765

765766
};
766-
767-
classCV_EXPORTS_W_SIMPLE QRCodeDetectorBase {
768-
public:
769-
CV_DEPRECATED_EXTERNAL// avoid using in C++ code, will be moved to "protected" (need to fix bindings first)
770-
QRCodeDetectorBase();
771-
772-
QRCodeDetectorBase(const QRCodeDetectorBase&) =default;
773-
QRCodeDetectorBase(QRCodeDetectorBase&&) =default;
774-
QRCodeDetectorBase&operator=(const QRCodeDetectorBase&) =default;
775-
QRCodeDetectorBase&operator=(QRCodeDetectorBase&&) =default;
776-
777-
/** @brief Detects QR code in image and returns the quadrangle containing the code.
778-
@param img grayscale or color (BGR) image containing (or not) QR code.
779-
@param points Output vector of vertices of the minimum-area quadrangle containing the code.
780-
*/
781-
CV_WRAPbooldetect(InputArray img, OutputArray points)const;
782-
783-
/** @brief Decodes QR code in image once it's found by the detect() method.
784-
785-
Returns UTF8-encoded output string or empty string if the code cannot be decoded.
786-
@param img grayscale or color (BGR) image containing QR code.
787-
@param points Quadrangle vertices found by detect() method (or some other algorithm).
788-
@param straight_qrcode The optional output image containing rectified and binarized QR code
789-
*/
790-
CV_WRAP std::stringdecode(InputArray img, InputArray points, OutputArray straight_qrcode = noArray())const;
791-
792-
/** @brief Both detects and decodes QR code
793-
794-
@param img grayscale or color (BGR) image containing QR code.
795-
@param points optional output array of vertices of the found QR code quadrangle. Will be empty if not found.
796-
@param straight_qrcode The optional output image containing rectified and binarized QR code
797-
*/
798-
CV_WRAP std::stringdetectAndDecode(InputArray img, OutputArray points=noArray(),
799-
OutputArray straight_qrcode = noArray())const;
800-
801-
802-
/** @brief Detects QR codes in image and returns the vector of the quadrangles containing the codes.
803-
@param img grayscale or color (BGR) image containing (or not) QR codes.
804-
@param points Output vector of vector of vertices of the minimum-area quadrangle containing the codes.
805-
*/
806-
CV_WRAP
807-
booldetectMulti(InputArray img, OutputArray points)const;
808-
809-
/** @brief Decodes QR codes in image once it's found by the detect() method.
810-
@param img grayscale or color (BGR) image containing QR codes.
811-
@param decoded_info UTF8-encoded output vector of string or empty vector of string if the codes cannot be decoded.
812-
@param points vector of Quadrangle vertices found by detect() method (or some other algorithm).
813-
@param straight_qrcode The optional output vector of images containing rectified and binarized QR codes
814-
*/
815-
CV_WRAP
816-
booldecodeMulti(
817-
InputArray img, InputArray points,
818-
CV_OUT std::vector<std::string>& decoded_info,
819-
OutputArrayOfArrays straight_qrcode = noArray()
820-
)const;
821-
822-
/** @brief Both detects and decodes QR codes
823-
@param img grayscale or color (BGR) image containing QR codes.
824-
@param decoded_info UTF8-encoded output vector of string or empty vector of string if the codes cannot be decoded.
825-
@param points optional output vector of vertices of the found QR code quadrangles. Will be empty if not found.
826-
@param straight_qrcode The optional output vector of images containing rectified and binarized QR codes
827-
*/
828-
CV_WRAP
829-
booldetectAndDecodeMulti(
830-
InputArray img, CV_OUT std::vector<std::string>& decoded_info,
831-
OutputArray points = noArray(),
832-
OutputArrayOfArrays straight_qrcode = noArray()
833-
)const;
834-
structImpl;
835-
protected:
836-
Ptr<Impl> p;
837-
};
838-
839-
classCV_EXPORTS_W_SIMPLE QRCodeDetector : public QRCodeDetectorBase
767+
classCV_EXPORTS_W_SIMPLE QRCodeDetector : public GenericGraphicalCode
840768
{
841769
public:
842770
CV_WRAPQRCodeDetector();
@@ -877,7 +805,7 @@ class CV_EXPORTS_W_SIMPLE QRCodeDetector : public QRCodeDetectorBase
877805
OutputArray straight_qrcode = noArray());
878806
};
879807

880-
classCV_EXPORTS_W_SIMPLE QRCodeDetectorAruco : publicQRCodeDetectorBase {
808+
classCV_EXPORTS_W_SIMPLE QRCodeDetectorAruco : publicGenericGraphicalCode {
881809
public:
882810
CV_WRAPQRCodeDetectorAruco();
883811

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html
4+
#ifndef OPENCV_OBJDETECT_GENERIC_GRAPHICAL_CODE_HPP
5+
#defineOPENCV_OBJDETECT_GENERIC_GRAPHICAL_CODE_HPP
6+
7+
#include<opencv2/core.hpp>
8+
9+
namespacecv {
10+
11+
//! @addtogroup objdetect_common
12+
//! @{
13+
14+
classCV_EXPORTS_W_SIMPLE GenericGraphicalCode {
15+
public:
16+
CV_DEPRECATED_EXTERNAL// avoid using in C++ code, will be moved to "protected" (need to fix bindings first)
17+
GenericGraphicalCode();
18+
19+
GenericGraphicalCode(const GenericGraphicalCode&) =default;
20+
GenericGraphicalCode(GenericGraphicalCode&&) =default;
21+
GenericGraphicalCode&operator=(const GenericGraphicalCode&) =default;
22+
GenericGraphicalCode&operator=(GenericGraphicalCode&&) =default;
23+
24+
/** @brief Detects graphical code in image and returns the quadrangle containing the code.
25+
@param img grayscale or color (BGR) image containing (or not) graphical code.
26+
@param points Output vector of vertices of the minimum-area quadrangle containing the code.
27+
*/
28+
CV_WRAPbooldetect(InputArray img, OutputArray points)const;
29+
30+
/** @brief Decodes graphical code in image once it's found by the detect() method.
31+
32+
Returns UTF8-encoded output string or empty string if the code cannot be decoded.
33+
@param img grayscale or color (BGR) image containing graphical code.
34+
@param points Quadrangle vertices found by detect() method (or some other algorithm).
35+
@param straight_code The optional output image containing binarized code, will be empty if not found.
36+
*/
37+
CV_WRAP std::stringdecode(InputArray img, InputArray points, OutputArray straight_qrcode = noArray())const;
38+
39+
/** @brief Both detects and decodes graphical code
40+
41+
@param img grayscale or color (BGR) image containing graphical code.
42+
@param points optional output array of vertices of the found graphical code quadrangle, will be empty if not found.
43+
@param straight_code The optional output image containing binarized code
44+
*/
45+
CV_WRAP std::stringdetectAndDecode(InputArray img, OutputArray points = noArray(),
46+
OutputArray straight_qrcode = noArray())const;
47+
48+
49+
/** @brief Detects graphical codes in image and returns the vector of the quadrangles containing the codes.
50+
@param img grayscale or color (BGR) image containing (or not) graphical codes.
51+
@param points Output vector of vector of vertices of the minimum-area quadrangle containing the codes.
52+
*/
53+
CV_WRAPbooldetectMulti(InputArray img, OutputArray points)const;
54+
55+
/** @brief Decodes graphical codes in image once it's found by the detect() method.
56+
@param img grayscale or color (BGR) image containing graphical codes.
57+
@param decoded_info UTF8-encoded output vector of string or empty vector of string if the codes cannot be decoded.
58+
@param points vector of Quadrangle vertices found by detect() method (or some other algorithm).
59+
@param straight_code The optional output vector of images containing binarized codes
60+
*/
61+
CV_WRAPbooldecodeMulti(InputArray img, InputArray points, CV_OUT std::vector<std::string>& decoded_info,
62+
OutputArrayOfArrays straight_qrcode = noArray())const;
63+
64+
/** @brief Both detects and decodes graphical codes
65+
@param img grayscale or color (BGR) image containing graphical codes.
66+
@param decoded_info UTF8-encoded output vector of string or empty vector of string if the codes cannot be decoded.
67+
@param points optional output vector of vertices of the found graphical code quadrangles. Will be empty if not found.
68+
@param straight_code The optional vector of images containing binarized codes
69+
*/
70+
CV_WRAPbooldetectAndDecodeMulti(InputArray img, CV_OUT std::vector<std::string>& decoded_info, OutputArray points = noArray(),
71+
OutputArrayOfArrays straight_qrcode = noArray())const;
72+
structImpl;
73+
protected:
74+
Ptr<Impl> p;
75+
};
76+
77+
structGenericGraphicalCode::Impl {
78+
virtual~Impl() {}
79+
virtualbooldetect(InputArray img, OutputArray points)const = 0;
80+
virtual std::stringdecode(InputArray img, InputArray points, OutputArray straight_qrcode)const = 0;
81+
virtual std::stringdetectAndDecode(InputArray img, OutputArray points, OutputArray straight_qrcode)const = 0;
82+
virtualbooldetectMulti(InputArray img, OutputArray points)const = 0;
83+
virtualbooldecodeMulti(InputArray img, InputArray points, std::vector<std::string>& decoded_info,
84+
OutputArrayOfArrays straight_code)const = 0;
85+
virtualbooldetectAndDecodeMulti(InputArray img, std::vector<std::string>& decoded_info,
86+
OutputArray points, OutputArrayOfArrays straight_code)const = 0;
87+
};
88+
89+
//! @}
90+
91+
}
92+
93+
#endif

‎modules/objdetect/perf/perf_qrcode_pipeline.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ PERF_TEST_P_(Perf_Objdetect_QRCode_Multi, detectMulti)
6868
Mat src =imread(image_path);
6969
ASSERT_FALSE(src.empty()) <<"Can't read image:" << image_path;
7070
std::vector<Point> corners;
71-
QRCodeDetectorBase qrcode =QRCodeDetector();
71+
GenericGraphicalCode qrcode =QRCodeDetector();
7272
if (method =="aruco_based") {
7373
qrcode =QRCodeDetectorAruco();
7474
}
@@ -90,7 +90,7 @@ PERF_TEST_P_(Perf_Objdetect_QRCode_Multi, decodeMulti)
9090
if (disabled_samples.find({name_current_image, method}) != disabled_samples.end()) {
9191
throwSkipTestException(name_current_image +" is disabled sample for method" + method);
9292
}
93-
QRCodeDetectorBase qrcode =QRCodeDetector();
93+
GenericGraphicalCode qrcode =QRCodeDetector();
9494
if (method =="aruco_based") {
9595
qrcode =QRCodeDetectorAruco();
9696
}

‎modules/objdetect/src/qrcode.cpp‎

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include"precomp.hpp"
99
#include"opencv2/objdetect.hpp"
10+
#include"opencv2/objdetect/generic_graphical_code.hpp"
1011
#include"opencv2/calib3d.hpp"
1112
#include<opencv2/core/utils/logger.hpp>
1213

@@ -950,53 +951,41 @@ vector<Point2f> QRDetect::getQuadrilateral(vector<Point2f> angle_list)
950951
return result_angle_list;
951952
}
952953

953-
structQRCodeDetectorBase::Impl {
954-
virtual~Impl() {}
955-
virtualbooldetect(InputArray img, OutputArray points)const = 0;
956-
virtual std::stringdecode(InputArray img, InputArray points, OutputArray straight_qrcode)const = 0;
957-
virtual std::stringdetectAndDecode(InputArray img, OutputArray points, OutputArray straight_qrcode)const = 0;
958-
virtualbooldetectMulti(InputArray img, OutputArray points)const = 0;
959-
virtualbooldecodeMulti(InputArray img, InputArray points, std::vector<std::string>& decoded_info,
960-
OutputArrayOfArrays straight_qrcode)const = 0;
961-
virtualbooldetectAndDecodeMulti(InputArray img, std::vector<std::string>& decoded_info, OutputArray points,
962-
OutputArrayOfArrays straight_qrcode)const = 0;
963-
};
964-
965-
QRCodeDetectorBase::QRCodeDetectorBase() {}
954+
GenericGraphicalCode::GenericGraphicalCode() {}
966955

967-
boolQRCodeDetectorBase::detect(InputArray img, OutputArray points)const {
956+
boolGenericGraphicalCode::detect(InputArray img, OutputArray points)const {
968957
CV_Assert(p);
969958
return p->detect(img, points);
970959
}
971960

972-
std::stringQRCodeDetectorBase::decode(InputArray img, InputArray points, OutputArraystraight_qrcode)const {
961+
std::stringGenericGraphicalCode::decode(InputArray img, InputArray points, OutputArraystraight_code)const {
973962
CV_Assert(p);
974-
return p->decode(img, points,straight_qrcode);
963+
return p->decode(img, points,straight_code);
975964
}
976965

977-
std::stringQRCodeDetectorBase::detectAndDecode(InputArray img, OutputArray points, OutputArraystraight_qrcode)const {
966+
std::stringGenericGraphicalCode::detectAndDecode(InputArray img, OutputArray points, OutputArraystraight_code)const {
978967
CV_Assert(p);
979-
return p->detectAndDecode(img, points,straight_qrcode);
968+
return p->detectAndDecode(img, points,straight_code);
980969
}
981970

982-
boolQRCodeDetectorBase::detectMulti(InputArray img, OutputArray points)const {
971+
boolGenericGraphicalCode::detectMulti(InputArray img, OutputArray points)const {
983972
CV_Assert(p);
984973
return p->detectMulti(img, points);
985974
}
986975

987-
boolQRCodeDetectorBase::decodeMulti(InputArray img, InputArray points, std::vector<std::string>& decoded_info,
988-
OutputArrayOfArraysstraight_qrcode)const {
976+
boolGenericGraphicalCode::decodeMulti(InputArray img, InputArray points, std::vector<std::string>& decoded_info,
977+
OutputArrayOfArraysstraight_code)const {
989978
CV_Assert(p);
990-
return p->decodeMulti(img, points, decoded_info,straight_qrcode);
979+
return p->decodeMulti(img, points, decoded_info,straight_code);
991980
}
992981

993-
boolQRCodeDetectorBase::detectAndDecodeMulti(InputArray img, std::vector<std::string>& decoded_info,
994-
OutputArray points, OutputArrayOfArraysstraight_qrcode)const {
982+
boolGenericGraphicalCode::detectAndDecodeMulti(InputArray img, std::vector<std::string>& decoded_info, OutputArray points,
983+
OutputArrayOfArraysstraight_code)const {
995984
CV_Assert(p);
996-
return p->detectAndDecodeMulti(img, decoded_info, points,straight_qrcode);
985+
return p->detectAndDecodeMulti(img, decoded_info, points,straight_code);
997986
}
998987

999-
structImplContour :publicQRCodeDetectorBase::Impl
988+
structImplContour :publicGenericGraphicalCode::Impl
1000989
{
1001990
public:
1002991
ImplContour(): epsX(0.2), epsY(0.1) {}

‎modules/objdetect/test/test_qrcode.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ TEST_P(Objdetect_QRCode_Multi, regression)
369369
ASSERT_FALSE(src.empty()) <<"Can't read image:" << image_path;
370370
if (disabled_samples.find({name_current_image, method}) != disabled_samples.end())
371371
throwSkipTestException(name_current_image +" is disabled sample for method" + method);
372-
QRCodeDetectorBase qrcode =QRCodeDetector();
372+
GenericGraphicalCode qrcode =QRCodeDetector();
373373
if (method =="aruco_based") {
374374
qrcode =QRCodeDetectorAruco();
375375
}
@@ -427,7 +427,7 @@ TEST_P(Objdetect_QRCode_detectMulti, detect_regression_16961)
427427
Mat src =imread(image_path);
428428
ASSERT_FALSE(src.empty()) <<"Can't read image:" << image_path;
429429

430-
QRCodeDetectorBase qrcode =QRCodeDetector();
430+
GenericGraphicalCode qrcode =QRCodeDetector();
431431
if (method =="aruco_based") {
432432
qrcode =QRCodeDetectorAruco();
433433
}
@@ -450,7 +450,7 @@ TEST_P(Objdetect_QRCode_detectAndDecodeMulti, check_output_parameters_type_19363
450450
Mat src =imread(image_path);
451451
ASSERT_FALSE(src.empty()) <<"Can't read image:" << image_path;
452452
#ifdef HAVE_QUIRC
453-
QRCodeDetectorBase qrcode =QRCodeDetector();
453+
GenericGraphicalCode qrcode =QRCodeDetector();
454454
if (method =="aruco_based") {
455455
qrcode =QRCodeDetectorAruco();
456456
}
@@ -619,7 +619,7 @@ TEST_P(Objdetect_QRCode_detectAndDecodeMulti, decode_9_qrcodes_version7)
619619
std::string image_path =findDataFile(root + name_current_image);
620620
Mat src =imread(image_path);
621621
const std::string method =GetParam();
622-
QRCodeDetectorBase qrcode =QRCodeDetector();
622+
GenericGraphicalCode qrcode =QRCodeDetector();
623623
if (method =="aruco_based") {
624624
qrcode =QRCodeDetectorAruco();
625625
}

‎samples/cpp/qrcode.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void drawQRCodeResults(Mat& frame, const vector<Point>& corners, const vector<cv
160160

161161
static
162162
voidrunQR(
163-
constQRCodeDetectorBase& qrcode,const Mat& input,
163+
constGenericGraphicalCode& qrcode,const Mat& input,
164164
vector<Point>& corners, vector<cv::String>& decode_info
165165
// +global: bool g_modeMultiQR, bool g_detectOnly
166166
)
@@ -194,7 +194,7 @@ void runQR(
194194
}
195195

196196
static
197-
doubleprocessQRCodeDetection(constQRCodeDetectorBase& qrcode,const Mat& input, Mat& result, vector<Point>& corners)
197+
doubleprocessQRCodeDetection(constGenericGraphicalCode& qrcode,const Mat& input, Mat& result, vector<Point>& corners)
198198
{
199199
if (input.channels() ==1)
200200
cvtColor(input, result, COLOR_GRAY2BGR);
@@ -232,7 +232,7 @@ int liveQRCodeDetect()
232232
cout <<"Press 'd' to switch between decoder and detector" << endl;
233233
cout <<"Press ' ' (space) to save result into images" << endl;
234234
cout <<"Press 'ESC' to exit" << endl;
235-
QRCodeDetectorBase qrcode =QRCodeDetector();
235+
GenericGraphicalCode qrcode =QRCodeDetector();
236236
if (g_useArucoBased)
237237
qrcode =QRCodeDetectorAruco();
238238

@@ -315,7 +315,7 @@ int imageQRCodeDetect(const string& in_file)
315315
<<" on image:" << input.size() <<" (" <<typeToString(input.type()) <<")"
316316
<< endl;
317317

318-
QRCodeDetectorBase qrcode =QRCodeDetector();
318+
GenericGraphicalCode qrcode =QRCodeDetector();
319319
if (g_useArucoBased)
320320
qrcode =QRCodeDetectorAruco();
321321

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp