1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

Merge branch 4.x

This commit is contained in:
Alexander Alekhin
2021-04-09 10:30:38 +00:00
1114 changed files with 64039 additions and 14611 deletions
+50 -25
View File
@@ -235,9 +235,11 @@ vector<Vec3d> QRDetect::searchHorizontalLines()
vector<Point2f> QRDetect::separateVerticalLines(const vector<Vec3d> &list_lines)
{
CV_TRACE_FUNCTION();
for (int coeff_epsilon = 1; coeff_epsilon < 10; coeff_epsilon++)
const double min_dist_between_points = 10.0;
const double max_ratio = 1.0;
for (int coeff_epsilon_i = 1; coeff_epsilon_i < 101; ++coeff_epsilon_i)
{
const float coeff_epsilon = coeff_epsilon_i * 0.1f;
vector<Point2f> point2f_result = extractVerticalLines(list_lines, eps_horizontal * coeff_epsilon);
if (!point2f_result.empty())
{
@@ -247,9 +249,23 @@ vector<Point2f> QRDetect::separateVerticalLines(const vector<Vec3d> &list_lines)
point2f_result, 3, labels,
TermCriteria(TermCriteria::EPS + TermCriteria::COUNT, 10, 0.1),
3, KMEANS_PP_CENTERS, centers);
if (compactness == 0)
double min_dist = std::numeric_limits<double>::max();
for (size_t i = 0; i < centers.size(); i++)
{
double dist = norm(centers[i] - centers[(i+1) % centers.size()]);
if (dist < min_dist)
{
min_dist = dist;
}
}
if (min_dist < min_dist_between_points)
{
continue;
if (compactness > 0)
}
double mean_compactness = compactness / point2f_result.size();
double ratio = mean_compactness / min_dist;
if (ratio < max_ratio)
{
return point2f_result;
}
@@ -456,7 +472,6 @@ bool QRDetect::localization()
vector<Point2f> list_lines_y = separateVerticalLines(list_lines_x);
if( list_lines_y.empty() ) { return false; }
vector<Point2f> centers;
Mat labels;
kmeans(list_lines_y, 3, labels,
TermCriteria( TermCriteria::EPS + TermCriteria::COUNT, 10, 0.1),
@@ -464,7 +479,7 @@ bool QRDetect::localization()
fixationPoints(localization_points);
bool suare_flag = false, local_points_flag = false;
bool square_flag = false, local_points_flag = false;
double triangle_sides[3];
double triangle_perim, square_area, img_square_area;
if (localization_points.size() == 3)
@@ -482,14 +497,14 @@ bool QRDetect::localization()
if (square_area > (img_square_area * 0.2))
{
suare_flag = true;
square_flag = true;
}
}
else
{
local_points_flag = true;
}
if ((suare_flag || local_points_flag) && purpose == SHRINKING)
if ((square_flag || local_points_flag) && purpose == SHRINKING)
{
localization_points.clear();
bin_barcode = resized_bin_barcode.clone();
@@ -1962,6 +1977,13 @@ bool QRDecode::createSpline(vector<vector<Point2f> > &spline_lines)
}
}
}
for (int i = 0; i < NUM_SIDES; i++)
{
if (spline_lines[i].size() == 0)
{
return false;
}
}
return true;
}
@@ -2469,12 +2491,13 @@ std::string QRCodeDetector::decode(InputArray in, InputArray points,
bool ok = qrdec.straightDecodingProcess();
std::string decoded_info = qrdec.getDecodeInformation();
if (ok && straight_qrcode.needed())
if (!ok && straight_qrcode.needed())
{
qrdec.getStraightBarcode().convertTo(straight_qrcode,
straight_qrcode.fixedType() ?
straight_qrcode.type() : CV_32FC2);
straight_qrcode.release();
}
else if (straight_qrcode.needed())
{
qrdec.getStraightBarcode().convertTo(straight_qrcode, CV_8UC1);
}
return ok ? decoded_info : std::string();
@@ -2498,11 +2521,13 @@ cv::String QRCodeDetector::decodeCurved(InputArray in, InputArray points,
std::string decoded_info = qrdec.getDecodeInformation();
if (ok && straight_qrcode.needed())
if (!ok && straight_qrcode.needed())
{
qrdec.getStraightBarcode().convertTo(straight_qrcode,
straight_qrcode.fixedType() ?
straight_qrcode.type() : CV_32FC2);
straight_qrcode.release();
}
else if (straight_qrcode.needed())
{
qrdec.getStraightBarcode().convertTo(straight_qrcode, CV_8UC1);
}
return ok ? decoded_info : std::string();
@@ -3593,18 +3618,18 @@ bool QRCodeDetector::decodeMulti(
for_copy.push_back(straight_barcode[i]);
}
straight_barcode = for_copy;
vector<Mat> tmp_straight_qrcodes;
if (straight_qrcode.needed())
if (straight_qrcode.needed() && straight_barcode.size() == 0)
{
straight_qrcode.release();
}
else if (straight_qrcode.needed())
{
straight_qrcode.create(Size((int)straight_barcode.size(), 1), CV_8UC1);
vector<Mat> tmp_straight_qrcodes(straight_barcode.size());
for (size_t i = 0; i < straight_barcode.size(); i++)
{
Mat tmp_straight_qrcode;
tmp_straight_qrcodes.push_back(tmp_straight_qrcode);
straight_barcode[i].convertTo(((OutputArray)tmp_straight_qrcodes[i]),
((OutputArray)tmp_straight_qrcodes[i]).fixedType() ?
((OutputArray)tmp_straight_qrcodes[i]).type() : CV_32FC2);
straight_barcode[i].convertTo(tmp_straight_qrcodes[i], CV_8UC1);
}
straight_qrcode.createSameSize(tmp_straight_qrcodes, CV_32FC2);
straight_qrcode.assign(tmp_straight_qrcodes);
}
decoded_info.clear();
+37
View File
@@ -252,6 +252,8 @@ TEST_P(Objdetect_QRCode, regression)
decoded_info = qrcode.detectAndDecode(src, corners, straight_barcode);
ASSERT_FALSE(corners.empty());
ASSERT_FALSE(decoded_info.empty());
int expected_barcode_type = CV_8UC1;
EXPECT_EQ(expected_barcode_type, straight_barcode.type());
#else
ASSERT_TRUE(qrcode.detect(src, corners));
#endif
@@ -317,6 +319,8 @@ TEST_P(Objdetect_QRCode_Close, regression)
decoded_info = qrcode.detectAndDecode(barcode, corners, straight_barcode);
ASSERT_FALSE(corners.empty());
ASSERT_FALSE(decoded_info.empty());
int expected_barcode_type = CV_8UC1;
EXPECT_EQ(expected_barcode_type, straight_barcode.type());
#else
ASSERT_TRUE(qrcode.detect(barcode, corners));
#endif
@@ -382,6 +386,8 @@ TEST_P(Objdetect_QRCode_Monitor, regression)
decoded_info = qrcode.detectAndDecode(barcode, corners, straight_barcode);
ASSERT_FALSE(corners.empty());
ASSERT_FALSE(decoded_info.empty());
int expected_barcode_type = CV_8UC1;
EXPECT_EQ(expected_barcode_type, straight_barcode.type());
#else
ASSERT_TRUE(qrcode.detect(barcode, corners));
#endif
@@ -442,6 +448,8 @@ TEST_P(Objdetect_QRCode_Curved, regression)
decoded_info = qrcode.detectAndDecodeCurved(src, corners, straight_barcode);
ASSERT_FALSE(corners.empty());
ASSERT_FALSE(decoded_info.empty());
int expected_barcode_type = CV_8UC1;
EXPECT_EQ(expected_barcode_type, straight_barcode.type());
#else
ASSERT_TRUE(qrcode.detect(src, corners));
#endif
@@ -502,6 +510,9 @@ TEST_P(Objdetect_QRCode_Multi, regression)
EXPECT_TRUE(qrcode.detectAndDecodeMulti(src, decoded_info, corners, straight_barcode));
ASSERT_FALSE(corners.empty());
ASSERT_FALSE(decoded_info.empty());
int expected_barcode_type = CV_8UC1;
for(size_t i = 0; i < straight_barcode.size(); i++)
EXPECT_EQ(expected_barcode_type, straight_barcode[i].type());
#else
ASSERT_TRUE(qrcode.detectMulti(src, corners));
#endif
@@ -612,6 +623,32 @@ TEST(Objdetect_QRCode_detectMulti, detect_regression_16961)
EXPECT_EQ(corners.size(), expect_corners_size);
}
TEST(Objdetect_QRCode_decodeMulti, check_output_parameters_type_19363)
{
const std::string name_current_image = "9_qrcodes.jpg";
const std::string root = "qrcode/multiple/";
std::string image_path = findDataFile(root + name_current_image);
Mat src = imread(image_path);
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
#ifdef HAVE_QUIRC
QRCodeDetector qrcode;
std::vector<Point> corners;
std::vector<cv::String> decoded_info;
#if 0 // FIXIT: OutputArray::create() type check
std::vector<Mat2b> straight_barcode_nchannels;
EXPECT_ANY_THROW(qrcode.detectAndDecodeMulti(src, decoded_info, corners, straight_barcode_nchannels));
#endif
int expected_barcode_type = CV_8UC1;
std::vector<Mat1b> straight_barcode;
EXPECT_TRUE(qrcode.detectAndDecodeMulti(src, decoded_info, corners, straight_barcode));
ASSERT_FALSE(corners.empty());
for(size_t i = 0; i < straight_barcode.size(); i++)
EXPECT_EQ(expected_barcode_type, straight_barcode[i].type());
#endif
}
TEST(Objdetect_QRCode_basic, not_found_qrcode)
{
std::vector<Point> corners;