1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

Merge branch 4.x

This commit is contained in:
Alexander Smorkalov
2024-02-16 18:45:22 +03:00
26 changed files with 441 additions and 89 deletions
@@ -252,7 +252,7 @@ struct CV_EXPORTS_W_SIMPLE RefineParameters {
*/
CV_PROP_RW float minRepDistance;
/** @brief minRepDistance rate of allowed erroneous bits respect to the error correction capability of the used dictionary.
/** @brief errorCorrectionRate rate of allowed erroneous bits respect to the error correction capability of the used dictionary.
*
* -1 ignores the error correction step.
*/
+6
View File
@@ -30,6 +30,7 @@ PERF_TEST_P_(Perf_Barcode_multi, detect)
}
SANITY_CHECK_NOTHING();
ASSERT_TRUE(res);
ASSERT_EQ(16ull, corners.size());
}
PERF_TEST_P_(Perf_Barcode_multi, detect_decode)
@@ -54,6 +55,8 @@ PERF_TEST_P_(Perf_Barcode_multi, detect_decode)
}
SANITY_CHECK_NOTHING();
ASSERT_TRUE(res);
ASSERT_EQ(16ull, corners.size());
ASSERT_EQ(4ull, decoded_info.size());
}
PERF_TEST_P_(Perf_Barcode_single, detect)
@@ -76,6 +79,7 @@ PERF_TEST_P_(Perf_Barcode_single, detect)
}
SANITY_CHECK_NOTHING();
ASSERT_TRUE(res);
ASSERT_EQ(4ull, corners.size());
}
PERF_TEST_P_(Perf_Barcode_single, detect_decode)
@@ -100,6 +104,8 @@ PERF_TEST_P_(Perf_Barcode_single, detect_decode)
}
SANITY_CHECK_NOTHING();
ASSERT_TRUE(res);
ASSERT_EQ(4ull, corners.size());
ASSERT_EQ(1ull, decoded_info.size());
}
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Barcode_multi,
+2 -2
View File
@@ -302,13 +302,13 @@ string BarcodeImpl::detectAndDecode(InputArray img, OutputArray points, OutputAr
CV_UNUSED(straight_code);
vector<string> decoded_info;
vector<string> decoded_type;
vector<Point> points_;
vector<Point2f> points_;
if (!detectAndDecodeWithType(img, decoded_info, decoded_type, points_))
return string();
if (points_.size() < 4 || decoded_info.size() < 1)
return string();
points_.resize(4);
points.setTo(points_);
updatePointsResult(points, points_);
return decoded_info[0];
}
+24 -12
View File
@@ -467,16 +467,25 @@ bool QRDetect::localization()
CV_TRACE_FUNCTION();
Point2f begin, end;
vector<Vec3d> list_lines_x = searchHorizontalLines();
if( list_lines_x.empty() ) { return false; }
vector<Point2f> list_lines_y = separateVerticalLines(list_lines_x);
if( list_lines_y.empty() ) { return false; }
vector<Point2f> list_lines_y;
Mat labels;
kmeans(list_lines_y, 3, labels,
TermCriteria( TermCriteria::EPS + TermCriteria::COUNT, 10, 0.1),
3, KMEANS_PP_CENTERS, localization_points);
if (!list_lines_x.empty())
{
list_lines_y = separateVerticalLines(list_lines_x);
if (!list_lines_y.empty())
{
kmeans(list_lines_y, 3, labels,
TermCriteria( TermCriteria::EPS + TermCriteria::COUNT, 10, 0.1),
3, KMEANS_PP_CENTERS, localization_points);
fixationPoints(localization_points);
fixationPoints(localization_points);
}
}
if (labels.empty())
{
localization_points.clear();
}
bool square_flag = false, local_points_flag = false;
double triangle_sides[3];
@@ -1564,9 +1573,9 @@ Point QRDecode::findClosestZeroPoint(Point2f original_point)
Point zero_point;
const int step = 2;
for (int i = orig_x - step; i >= 0 && i <= orig_x + step; i++)
for (int i = std::max(orig_x - step, 0); i >= 0 && i <= std::min(orig_x + step, bin_barcode.cols - 1); i++)
{
for (int j = orig_y - step; j >= 0 && j <= orig_y + step; j++)
for (int j = std::max(orig_y - step, 0); j >= 0 && j <= std::min(orig_y + step, bin_barcode.rows - 1); j++)
{
Point p(i, j);
value = bin_barcode.at<uint8_t>(p);
@@ -1944,7 +1953,7 @@ vector<vector<float> > QRDecode::computeSpline(const vector<int> &x_arr, const v
}
for (int i = 0; i < n - 1; i++)
{
h[i] = static_cast<float>(y_arr[i + 1] - y_arr[i]);
h[i] = static_cast<float>(y_arr[i + 1] - y_arr[i]) + std::numeric_limits<float>::epsilon();
}
for (int i = 1; i < n - 1; i++)
{
@@ -3071,7 +3080,10 @@ protected:
{
bool operator()(const Point2f& a, const Point2f& b) const
{
return a.y < b.y;
if (a.y != b.y)
return a.y < b.y;
else
return a.x < b.x;
}
};
struct compareSquare
+7
View File
@@ -95,6 +95,13 @@ TEST_P(BarcodeDetector_main, interface)
EXPECT_EQ(1u, expected_lines.count(res));
}
{
string res = det.detectAndDecode(img, points);
ASSERT_FALSE(res.empty());
EXPECT_EQ(1u, expected_lines.count(res));
EXPECT_EQ(4u, points.size());
}
// common interface (multi)
{
bool res = det.detectMulti(img, points);
+65
View File
@@ -614,4 +614,69 @@ TEST(Objdetect_QRCode_detectAndDecode, utf8_output)
EXPECT_NE(decoded_info.find("M\xc3\xbcllheimstrasse"), std::string::npos);
}
TEST_P(Objdetect_QRCode_detectAndDecodeMulti, detect_regression_24679)
{
const std::string name_current_image = "issue_24679.png";
const std::string root = "qrcode/";
std::string image_path = findDataFile(root + name_current_image);
Mat img = imread(image_path);
const std::string method = GetParam();
GraphicalCodeDetector qrcode = QRCodeDetector();
if (method == "aruco_based") {
qrcode = QRCodeDetectorAruco();
}
std::vector<cv::String> decoded_info;
ASSERT_TRUE(qrcode.detectAndDecodeMulti(img, decoded_info));
EXPECT_EQ(decoded_info.size(), 4U);
}
TEST_P(Objdetect_QRCode_detectAndDecodeMulti, detect_regression_24011)
{
const std::string name_current_image = "issue_24011.jpg";
const std::string root = "qrcode/";
std::string image_path = findDataFile(root + name_current_image);
Mat img = imread(image_path);
const std::string method = GetParam();
GraphicalCodeDetector qrcode = QRCodeDetector();
if (method == "aruco_based") {
qrcode = QRCodeDetectorAruco();
}
std::vector<cv::String> decoded_info;
ASSERT_TRUE(qrcode.detectAndDecodeMulti(img, decoded_info));
EXPECT_EQ(decoded_info.size(), 2U);
}
TEST(Objdetect_QRCode_detect, detect_regression_24450)
{
const std::string name_current_image = "issue_24450.png";
const std::string root = "qrcode/";
std::string image_path = findDataFile(root + name_current_image);
Mat img = imread(image_path);
GraphicalCodeDetector qrcode = QRCodeDetector();
std::vector<Point2f> points;
ASSERT_TRUE(qrcode.detect(img, points));
EXPECT_EQ(points.size(), 4U);
img.at<Vec3b>(img.rows - 1, 296) = {};
ASSERT_TRUE(qrcode.detect(img, points));
EXPECT_EQ(points.size(), 4U);
}
TEST(Objdetect_QRCode_detect, detect_regression_22892)
{
const std::string name_current_image = "issue_22892.png";
const std::string root = "qrcode/";
std::string image_path = findDataFile(root + name_current_image);
Mat img = imread(image_path);
QRCodeDetector qrcode;
std::vector<Point> corners;
Mat straight_code;
qrcode.detectAndDecodeCurved(img, corners, straight_code);
EXPECT_EQ(corners.size(), 4U);
}
}} // namespace