Commit f5b212a9 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge remote-tracking branch 'upstream/3.4' into merge-3.4

parents e31eb461 cae2992a
...@@ -56,7 +56,7 @@ macro(ocv_optimization_process_obsolete_option legacy_flag OPT legacy_warn) ...@@ -56,7 +56,7 @@ macro(ocv_optimization_process_obsolete_option legacy_flag OPT legacy_warn)
message(STATUS " Behaviour of this option is not backward compatible") message(STATUS " Behaviour of this option is not backward compatible")
message(STATUS " Refer to 'CPU_BASELINE'/'CPU_DISPATCH' CMake options documentation") message(STATUS " Refer to 'CPU_BASELINE'/'CPU_DISPATCH' CMake options documentation")
endif() endif()
if("${legacy_flag}") if("${${legacy_flag}}")
if(NOT ";${CPU_BASELINE_REQUIRE};" MATCHES ";${OPT};") if(NOT ";${CPU_BASELINE_REQUIRE};" MATCHES ";${OPT};")
set(CPU_BASELINE_REQUIRE "${CPU_BASELINE_REQUIRE};${OPT}" CACHE STRING "${HELP_CPU_BASELINE_REQUIRE}" FORCE) set(CPU_BASELINE_REQUIRE "${CPU_BASELINE_REQUIRE};${OPT}" CACHE STRING "${HELP_CPU_BASELINE_REQUIRE}" FORCE)
endif() endif()
......
...@@ -2291,10 +2291,15 @@ void testDivideChecks(const Mat& dst) ...@@ -2291,10 +2291,15 @@ void testDivideChecks(const Mat& dst)
{ {
for (int x = 0; x < dst.cols; x++) for (int x = 0; x < dst.cols; x++)
{ {
if (x == 2) if ((x % 4) == 2)
{ {
EXPECT_EQ(0, dst.at<T>(y, x)) << "dst(" << y << ", " << x << ") = " << dst.at<T>(y, x); EXPECT_EQ(0, dst.at<T>(y, x)) << "dst(" << y << ", " << x << ") = " << dst.at<T>(y, x);
} }
else
{
EXPECT_TRUE(0 == cvIsNaN((double)dst.at<T>(y, x))) << "dst(" << y << ", " << x << ") = " << dst.at<T>(y, x);
EXPECT_TRUE(0 == cvIsInf((double)dst.at<T>(y, x))) << "dst(" << y << ", " << x << ") = " << dst.at<T>(y, x);
}
} }
} }
} }
...@@ -2308,11 +2313,11 @@ void testDivideChecksFP(const Mat& dst) ...@@ -2308,11 +2313,11 @@ void testDivideChecksFP(const Mat& dst)
{ {
for (int x = 0; x < dst.cols; x++) for (int x = 0; x < dst.cols; x++)
{ {
if (y == 0 && x == 2) if ((y % 3) == 0 && (x % 4) == 2)
{ {
EXPECT_TRUE(cvIsNaN(dst.at<T>(y, x))) << "dst(" << y << ", " << x << ") = " << dst.at<T>(y, x); EXPECT_TRUE(cvIsNaN(dst.at<T>(y, x))) << "dst(" << y << ", " << x << ") = " << dst.at<T>(y, x);
} }
else if (x == 2) else if ((x % 4) == 2)
{ {
EXPECT_TRUE(cvIsInf(dst.at<T>(y, x))) << "dst(" << y << ", " << x << ") = " << dst.at<T>(y, x); EXPECT_TRUE(cvIsInf(dst.at<T>(y, x))) << "dst(" << y << ", " << x << ") = " << dst.at<T>(y, x);
} }
...@@ -2329,24 +2334,40 @@ template <> inline void testDivideChecks<float>(const Mat& dst) { testDivideChec ...@@ -2329,24 +2334,40 @@ template <> inline void testDivideChecks<float>(const Mat& dst) { testDivideChec
template <> inline void testDivideChecks<double>(const Mat& dst) { testDivideChecksFP<double>(dst); } template <> inline void testDivideChecks<double>(const Mat& dst) { testDivideChecksFP<double>(dst); }
template <typename T, bool isUMat> static inline template <typename T> static inline
void testDivide() void testDivide(bool isUMat, double scale, bool largeSize, bool tailProcessing, bool roi)
{ {
Mat src1, src2; Mat src1, src2;
testDivideInitData<T>(src1, src2); testDivideInitData<T>(src1, src2);
ASSERT_FALSE(src1.empty()); ASSERT_FALSE(src2.empty()); ASSERT_FALSE(src1.empty()); ASSERT_FALSE(src2.empty());
if (largeSize)
{
repeat(src1.clone(), 1, 8, src1);
repeat(src2.clone(), 1, 8, src2);
}
if (tailProcessing)
{
src1 = src1(Rect(0, 0, src1.cols - 1, src1.rows));
src2 = src2(Rect(0, 0, src2.cols - 1, src2.rows));
}
if (!roi && tailProcessing)
{
src1 = src1.clone();
src2 = src2.clone();
}
Mat dst; Mat dst;
if (!isUMat) if (!isUMat)
{ {
cv::divide(src1, src2, dst); cv::divide(src1, src2, dst, scale);
} }
else else
{ {
UMat usrc1, usrc2, udst; UMat usrc1, usrc2, udst;
src1.copyTo(usrc1); src1.copyTo(usrc1);
src2.copyTo(usrc2); src2.copyTo(usrc2);
cv::divide(usrc1, usrc2, udst); cv::divide(usrc1, usrc2, udst, scale);
udst.copyTo(dst); udst.copyTo(dst);
} }
...@@ -2360,14 +2381,46 @@ void testDivide() ...@@ -2360,14 +2381,46 @@ void testDivide()
} }
} }
TEST(Core_DivideRules, type_32s) { testDivide<int, false>(); } typedef tuple<bool, double, bool, bool, bool> DivideRulesParam;
TEST(UMat_Core_DivideRules, type_32s) { testDivide<int, true>(); } typedef testing::TestWithParam<DivideRulesParam> Core_DivideRules;
TEST(Core_DivideRules, type_16s) { testDivide<short, false>(); }
TEST(UMat_Core_DivideRules, type_16s) { testDivide<short, true>(); } TEST_P(Core_DivideRules, type_32s)
TEST(Core_DivideRules, type_32f) { testDivide<float, false>(); } {
TEST(UMat_Core_DivideRules, type_32f) { testDivide<float, true>(); } DivideRulesParam param = GetParam();
TEST(Core_DivideRules, type_64f) { testDivide<double, false>(); } testDivide<int>(get<0>(param), get<1>(param), get<2>(param), get<3>(param), get<4>(param));
TEST(UMat_Core_DivideRules, type_64f) { testDivide<double, true>(); } }
TEST_P(Core_DivideRules, type_16s)
{
DivideRulesParam param = GetParam();
testDivide<short>(get<0>(param), get<1>(param), get<2>(param), get<3>(param), get<4>(param));
}
TEST_P(Core_DivideRules, type_32f)
{
DivideRulesParam param = GetParam();
testDivide<float>(get<0>(param), get<1>(param), get<2>(param), get<3>(param), get<4>(param));
}
TEST_P(Core_DivideRules, type_64f)
{
DivideRulesParam param = GetParam();
testDivide<double>(get<0>(param), get<1>(param), get<2>(param), get<3>(param), get<4>(param));
}
INSTANTIATE_TEST_CASE_P(/* */, Core_DivideRules, testing::Combine(
/* isMat */ testing::Values(false),
/* scale */ testing::Values(1.0, 5.0),
/* largeSize */ testing::Bool(),
/* tail */ testing::Bool(),
/* roi */ testing::Bool()
));
INSTANTIATE_TEST_CASE_P(UMat, Core_DivideRules, testing::Combine(
/* isMat */ testing::Values(true),
/* scale */ testing::Values(1.0, 5.0),
/* largeSize */ testing::Bool(),
/* tail */ testing::Bool(),
/* roi */ testing::Bool()
));
TEST(Core_MinMaxIdx, rows_overflow) TEST(Core_MinMaxIdx, rows_overflow)
......
...@@ -1898,7 +1898,7 @@ struct Net::Impl ...@@ -1898,7 +1898,7 @@ struct Net::Impl
nextEltwiseLayer = nextData->layerInstance.dynamicCast<EltwiseLayer>(); nextEltwiseLayer = nextData->layerInstance.dynamicCast<EltwiseLayer>();
if( !nextEltwiseLayer.empty() && pinsToKeep.count(lpNext) == 0 && if( !nextEltwiseLayer.empty() && pinsToKeep.count(lpNext) == 0 &&
nextData->inputBlobsId.size() == 2 ) nextData && nextData->inputBlobsId.size() == 2 )
{ {
LayerData *eltwiseData = nextData; LayerData *eltwiseData = nextData;
......
...@@ -74,6 +74,17 @@ PERF_TEST_P_(Perf_Objdetect_Not_QRCode, detect) ...@@ -74,6 +74,17 @@ PERF_TEST_P_(Perf_Objdetect_Not_QRCode, detect)
RNG rng; RNG rng;
rng.fill(not_qr_code, RNG::UNIFORM, Scalar(0), Scalar(1)); rng.fill(not_qr_code, RNG::UNIFORM, Scalar(0), Scalar(1));
} }
if (type_gen == "chessboard")
{
uint8_t next_pixel = 0;
for (int r = 0; r < not_qr_code.rows * not_qr_code.cols; r++)
{
int i = r / not_qr_code.cols;
int j = r % not_qr_code.cols;
not_qr_code.ptr<uchar>(i)[j] = next_pixel;
next_pixel = 255 - next_pixel;
}
}
QRCodeDetector qrcode; QRCodeDetector qrcode;
TEST_CYCLE() ASSERT_FALSE(qrcode.detect(not_qr_code, corners)); TEST_CYCLE() ASSERT_FALSE(qrcode.detect(not_qr_code, corners));
...@@ -96,6 +107,17 @@ PERF_TEST_P_(Perf_Objdetect_Not_QRCode, decode) ...@@ -96,6 +107,17 @@ PERF_TEST_P_(Perf_Objdetect_Not_QRCode, decode)
RNG rng; RNG rng;
rng.fill(not_qr_code, RNG::UNIFORM, Scalar(0), Scalar(1)); rng.fill(not_qr_code, RNG::UNIFORM, Scalar(0), Scalar(1));
} }
if (type_gen == "chessboard")
{
uint8_t next_pixel = 0;
for (int r = 0; r < not_qr_code.rows * not_qr_code.cols; r++)
{
int i = r / not_qr_code.cols;
int j = r % not_qr_code.cols;
not_qr_code.ptr<uchar>(i)[j] = next_pixel;
next_pixel = 255 - next_pixel;
}
}
QRCodeDetector qrcode; QRCodeDetector qrcode;
TEST_CYCLE() ASSERT_TRUE(qrcode.decode(not_qr_code, corners, straight_barcode).empty()); TEST_CYCLE() ASSERT_TRUE(qrcode.decode(not_qr_code, corners, straight_barcode).empty());
...@@ -105,8 +127,9 @@ PERF_TEST_P_(Perf_Objdetect_Not_QRCode, decode) ...@@ -105,8 +127,9 @@ PERF_TEST_P_(Perf_Objdetect_Not_QRCode, decode)
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_Not_QRCode, INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_Not_QRCode,
::testing::Combine( ::testing::Combine(
::testing::Values("zero", "random"), ::testing::Values("zero", "random", "chessboard"),
::testing::Values(Size(640, 480), Size(1280, 720), Size(1920, 1080)) ::testing::Values(Size(640, 480), Size(1280, 720),
Size(1920, 1080), Size(3840, 2160))
)); ));
} }
......
...@@ -48,6 +48,7 @@ protected: ...@@ -48,6 +48,7 @@ protected:
void QRDetect::init(const Mat& src, double eps_vertical_, double eps_horizontal_) void QRDetect::init(const Mat& src, double eps_vertical_, double eps_horizontal_)
{ {
CV_TRACE_FUNCTION();
CV_Assert(!src.empty()); CV_Assert(!src.empty());
const double min_side = std::min(src.size().width, src.size().height); const double min_side = std::min(src.size().width, src.size().height);
if (min_side < 512.0) if (min_side < 512.0)
...@@ -72,26 +73,26 @@ void QRDetect::init(const Mat& src, double eps_vertical_, double eps_horizontal_ ...@@ -72,26 +73,26 @@ void QRDetect::init(const Mat& src, double eps_vertical_, double eps_horizontal_
vector<Vec3d> QRDetect::searchHorizontalLines() vector<Vec3d> QRDetect::searchHorizontalLines()
{ {
CV_TRACE_FUNCTION();
vector<Vec3d> result; vector<Vec3d> result;
const int height_bin_barcode = bin_barcode.rows; const int height_bin_barcode = bin_barcode.rows;
const int width_bin_barcode = bin_barcode.cols; const int width_bin_barcode = bin_barcode.cols;
const size_t test_lines_size = 5; const size_t test_lines_size = 5;
double test_lines[test_lines_size]; double test_lines[test_lines_size];
const size_t count_pixels_position = 1024; vector<size_t> pixels_position;
size_t pixels_position[count_pixels_position];
size_t index = 0;
for (int y = 0; y < height_bin_barcode; y++) for (int y = 0; y < height_bin_barcode; y++)
{ {
pixels_position.clear();
const uint8_t *bin_barcode_row = bin_barcode.ptr<uint8_t>(y); const uint8_t *bin_barcode_row = bin_barcode.ptr<uint8_t>(y);
int pos = 0; int pos = 0;
for (; pos < width_bin_barcode; pos++) { if (bin_barcode_row[pos] == 0) break; } for (; pos < width_bin_barcode; pos++) { if (bin_barcode_row[pos] == 0) break; }
if (pos == width_bin_barcode) { continue; } if (pos == width_bin_barcode) { continue; }
index = 0; pixels_position.push_back(pos);
pixels_position[index] = pixels_position[index + 1] = pixels_position[index + 2] = pos; pixels_position.push_back(pos);
index +=3; pixels_position.push_back(pos);
uint8_t future_pixel = 255; uint8_t future_pixel = 255;
for (int x = pos; x < width_bin_barcode; x++) for (int x = pos; x < width_bin_barcode; x++)
...@@ -99,13 +100,11 @@ vector<Vec3d> QRDetect::searchHorizontalLines() ...@@ -99,13 +100,11 @@ vector<Vec3d> QRDetect::searchHorizontalLines()
if (bin_barcode_row[x] == future_pixel) if (bin_barcode_row[x] == future_pixel)
{ {
future_pixel = 255 - future_pixel; future_pixel = 255 - future_pixel;
pixels_position[index] = x; pixels_position.push_back(x);
index++;
} }
} }
pixels_position[index] = width_bin_barcode - 1; pixels_position.push_back(width_bin_barcode - 1);
index++; for (size_t i = 2; i < pixels_position.size() - 4; i+=2)
for (size_t i = 2; i < index - 4; i+=2)
{ {
test_lines[0] = static_cast<double>(pixels_position[i - 1] - pixels_position[i - 2]); test_lines[0] = static_cast<double>(pixels_position[i - 1] - pixels_position[i - 2]);
test_lines[1] = static_cast<double>(pixels_position[i ] - pixels_position[i - 1]); test_lines[1] = static_cast<double>(pixels_position[i ] - pixels_position[i - 1]);
...@@ -120,8 +119,8 @@ vector<Vec3d> QRDetect::searchHorizontalLines() ...@@ -120,8 +119,8 @@ vector<Vec3d> QRDetect::searchHorizontalLines()
if (length == 0) { continue; } if (length == 0) { continue; }
for (size_t j = 0; j < test_lines_size; j++) for (size_t j = 0; j < test_lines_size; j++)
{ {
if (j == 2) { weight += fabs((test_lines[j] / length) - 3.0/7.0); } if (j != 2) { weight += fabs((test_lines[j] / length) - 1.0/7.0); }
else { weight += fabs((test_lines[j] / length) - 1.0/7.0); } else { weight += fabs((test_lines[j] / length) - 3.0/7.0); }
} }
if (weight < eps_vertical) if (weight < eps_vertical)
...@@ -139,6 +138,7 @@ vector<Vec3d> QRDetect::searchHorizontalLines() ...@@ -139,6 +138,7 @@ vector<Vec3d> QRDetect::searchHorizontalLines()
vector<Point2f> QRDetect::separateVerticalLines(const vector<Vec3d> &list_lines) vector<Point2f> QRDetect::separateVerticalLines(const vector<Vec3d> &list_lines)
{ {
CV_TRACE_FUNCTION();
vector<Vec3d> result; vector<Vec3d> result;
int temp_length = 0; int temp_length = 0;
uint8_t next_pixel; uint8_t next_pixel;
...@@ -157,7 +157,7 @@ vector<Point2f> QRDetect::separateVerticalLines(const vector<Vec3d> &list_lines) ...@@ -157,7 +157,7 @@ vector<Point2f> QRDetect::separateVerticalLines(const vector<Vec3d> &list_lines)
for (int j = y; j < bin_barcode.rows - 1; j++) for (int j = y; j < bin_barcode.rows - 1; j++)
{ {
next_pixel = bin_barcode.at<uint8_t>(j + 1, x); next_pixel = bin_barcode.ptr<uint8_t>(j + 1)[x];
temp_length++; temp_length++;
if (next_pixel == future_pixel_up) if (next_pixel == future_pixel_up)
{ {
...@@ -173,7 +173,7 @@ vector<Point2f> QRDetect::separateVerticalLines(const vector<Vec3d> &list_lines) ...@@ -173,7 +173,7 @@ vector<Point2f> QRDetect::separateVerticalLines(const vector<Vec3d> &list_lines)
uint8_t future_pixel_down = 255; uint8_t future_pixel_down = 255;
for (int j = y; j >= 1; j--) for (int j = y; j >= 1; j--)
{ {
next_pixel = bin_barcode.at<uint8_t>(j - 1, x); next_pixel = bin_barcode.ptr<uint8_t>(j - 1)[x];
temp_length++; temp_length++;
if (next_pixel == future_pixel_down) if (next_pixel == future_pixel_down)
{ {
...@@ -195,8 +195,8 @@ vector<Point2f> QRDetect::separateVerticalLines(const vector<Vec3d> &list_lines) ...@@ -195,8 +195,8 @@ vector<Point2f> QRDetect::separateVerticalLines(const vector<Vec3d> &list_lines)
CV_Assert(length > 0); CV_Assert(length > 0);
for (size_t i = 0; i < test_lines.size(); i++) for (size_t i = 0; i < test_lines.size(); i++)
{ {
if (i % 3 == 0) { weight += fabs((test_lines[i] / length) - 3.0/14.0); } if (i % 3 != 0) { weight += fabs((test_lines[i] / length) - 1.0/ 7.0); }
else { weight += fabs((test_lines[i] / length) - 1.0/ 7.0); } else { weight += fabs((test_lines[i] / length) - 3.0/14.0); }
} }
if(weight < eps_horizontal) if(weight < eps_horizontal)
...@@ -218,7 +218,7 @@ vector<Point2f> QRDetect::separateVerticalLines(const vector<Vec3d> &list_lines) ...@@ -218,7 +218,7 @@ vector<Point2f> QRDetect::separateVerticalLines(const vector<Vec3d> &list_lines)
void QRDetect::fixationPoints(vector<Point2f> &local_point) void QRDetect::fixationPoints(vector<Point2f> &local_point)
{ {
CV_TRACE_FUNCTION();
double cos_angles[3], norm_triangl[3]; double cos_angles[3], norm_triangl[3];
norm_triangl[0] = norm(local_point[1] - local_point[2]); norm_triangl[0] = norm(local_point[1] - local_point[2]);
...@@ -311,6 +311,7 @@ void QRDetect::fixationPoints(vector<Point2f> &local_point) ...@@ -311,6 +311,7 @@ void QRDetect::fixationPoints(vector<Point2f> &local_point)
bool QRDetect::localization() bool QRDetect::localization()
{ {
CV_TRACE_FUNCTION();
Point2f begin, end; Point2f begin, end;
vector<Vec3d> list_lines_x = searchHorizontalLines(); vector<Vec3d> list_lines_x = searchHorizontalLines();
if( list_lines_x.empty() ) { return false; } if( list_lines_x.empty() ) { return false; }
...@@ -356,6 +357,7 @@ bool QRDetect::localization() ...@@ -356,6 +357,7 @@ bool QRDetect::localization()
bool QRDetect::computeTransformationPoints() bool QRDetect::computeTransformationPoints()
{ {
CV_TRACE_FUNCTION();
if (localization_points.size() != 3) { return false; } if (localization_points.size() != 3) { return false; }
vector<Point> locations, non_zero_elem[3], newHull; vector<Point> locations, non_zero_elem[3], newHull;
...@@ -367,8 +369,7 @@ bool QRDetect::computeTransformationPoints() ...@@ -367,8 +369,7 @@ bool QRDetect::computeTransformationPoints()
int count_test_lines = 0, index = cvRound(localization_points[i].x); int count_test_lines = 0, index = cvRound(localization_points[i].x);
for (; index < bin_barcode.cols - 1; index++) for (; index < bin_barcode.cols - 1; index++)
{ {
next_pixel = bin_barcode.at<uint8_t>( next_pixel = bin_barcode.ptr<uint8_t>(cvRound(localization_points[i].y))[index + 1];
cvRound(localization_points[i].y), index + 1);
if (next_pixel == future_pixel) if (next_pixel == future_pixel)
{ {
future_pixel = 255 - future_pixel; future_pixel = 255 - future_pixel;
...@@ -495,6 +496,7 @@ Point2f QRDetect::intersectionLines(Point2f a1, Point2f a2, Point2f b1, Point2f ...@@ -495,6 +496,7 @@ Point2f QRDetect::intersectionLines(Point2f a1, Point2f a2, Point2f b1, Point2f
// test function (if true then ------> else <------ ) // test function (if true then ------> else <------ )
bool QRDetect::testBypassRoute(vector<Point2f> hull, int start, int finish) bool QRDetect::testBypassRoute(vector<Point2f> hull, int start, int finish)
{ {
CV_TRACE_FUNCTION();
int index_hull = start, next_index_hull, hull_size = (int)hull.size(); int index_hull = start, next_index_hull, hull_size = (int)hull.size();
double test_length[2] = { 0.0, 0.0 }; double test_length[2] = { 0.0, 0.0 };
do do
...@@ -521,6 +523,7 @@ bool QRDetect::testBypassRoute(vector<Point2f> hull, int start, int finish) ...@@ -521,6 +523,7 @@ bool QRDetect::testBypassRoute(vector<Point2f> hull, int start, int finish)
vector<Point2f> QRDetect::getQuadrilateral(vector<Point2f> angle_list) vector<Point2f> QRDetect::getQuadrilateral(vector<Point2f> angle_list)
{ {
CV_TRACE_FUNCTION();
size_t angle_size = angle_list.size(); size_t angle_size = angle_list.size();
uint8_t value, mask_value; uint8_t value, mask_value;
Mat mask = Mat::zeros(bin_barcode.rows + 2, bin_barcode.cols + 2, CV_8UC1); Mat mask = Mat::zeros(bin_barcode.rows + 2, bin_barcode.cols + 2, CV_8UC1);
...@@ -819,6 +822,7 @@ protected: ...@@ -819,6 +822,7 @@ protected:
void QRDecode::init(const Mat &src, const vector<Point2f> &points) void QRDecode::init(const Mat &src, const vector<Point2f> &points)
{ {
CV_TRACE_FUNCTION();
original = src.clone(); original = src.clone();
intermediate = Mat::zeros(src.size(), CV_8UC1); intermediate = Mat::zeros(src.size(), CV_8UC1);
original_points = points; original_points = points;
...@@ -830,6 +834,7 @@ void QRDecode::init(const Mat &src, const vector<Point2f> &points) ...@@ -830,6 +834,7 @@ void QRDecode::init(const Mat &src, const vector<Point2f> &points)
bool QRDecode::updatePerspective() bool QRDecode::updatePerspective()
{ {
CV_TRACE_FUNCTION();
const Point2f centerPt = QRDetect::intersectionLines(original_points[0], original_points[2], const Point2f centerPt = QRDetect::intersectionLines(original_points[0], original_points[2],
original_points[1], original_points[3]); original_points[1], original_points[3]);
if (cvIsNaN(centerPt.x) || cvIsNaN(centerPt.y)) if (cvIsNaN(centerPt.x) || cvIsNaN(centerPt.y))
...@@ -878,6 +883,7 @@ inline Point computeOffset(const vector<Point>& v) ...@@ -878,6 +883,7 @@ inline Point computeOffset(const vector<Point>& v)
bool QRDecode::versionDefinition() bool QRDecode::versionDefinition()
{ {
CV_TRACE_FUNCTION();
LineIterator line_iter(intermediate, Point2f(0, 0), Point2f(test_perspective_size, test_perspective_size)); LineIterator line_iter(intermediate, Point2f(0, 0), Point2f(test_perspective_size, test_perspective_size));
Point black_point = Point(0, 0); Point black_point = Point(0, 0);
for(int j = 0; j < line_iter.count; j++, ++line_iter) for(int j = 0; j < line_iter.count; j++, ++line_iter)
...@@ -940,6 +946,7 @@ bool QRDecode::versionDefinition() ...@@ -940,6 +946,7 @@ bool QRDecode::versionDefinition()
bool QRDecode::samplingForVersion() bool QRDecode::samplingForVersion()
{ {
CV_TRACE_FUNCTION();
const double multiplyingFactor = (version < 3) ? 1 : const double multiplyingFactor = (version < 3) ? 1 :
(version == 3) ? 1.5 : (version == 3) ? 1.5 :
version * (5 + version - 4); version * (5 + version - 4);
...@@ -949,21 +956,20 @@ bool QRDecode::samplingForVersion() ...@@ -949,21 +956,20 @@ bool QRDecode::samplingForVersion()
Mat postIntermediate(newFactorSize, CV_8UC1); Mat postIntermediate(newFactorSize, CV_8UC1);
resize(no_border_intermediate, postIntermediate, newFactorSize, 0, 0, INTER_AREA); resize(no_border_intermediate, postIntermediate, newFactorSize, 0, 0, INTER_AREA);
const int no_inter_rows = postIntermediate.rows; const int delta_rows = cvRound((postIntermediate.rows * 1.0) / version_size);
const int no_inter_cols = postIntermediate.cols; const int delta_cols = cvRound((postIntermediate.cols * 1.0) / version_size);
const int delta_rows = cvRound((no_inter_rows * 1.0) / version_size);
const int delta_cols = cvRound((no_inter_cols * 1.0) / version_size);
vector<double> listFrequencyElem; vector<double> listFrequencyElem(version_size * version_size, 0);
for (int r = 0; r < no_inter_rows; r += delta_rows) int k = 0;
for (int r = 0; r < postIntermediate.rows; r += delta_rows)
{ {
for (int c = 0; c < no_inter_cols; c += delta_cols) for (int c = 0; c < postIntermediate.cols; c += delta_cols)
{ {
Mat tile = postIntermediate( Mat tile = postIntermediate(
Range(r, min(r + delta_rows, no_inter_rows)), Range(r, min(r + delta_rows, postIntermediate.rows)),
Range(c, min(c + delta_cols, no_inter_cols))); Range(c, min(c + delta_cols, postIntermediate.cols)));
const double frequencyElem = (countNonZero(tile) * 1.0) / tile.total(); const double frequencyElem = (countNonZero(tile) * 1.0) / tile.total();
listFrequencyElem.push_back(frequencyElem); listFrequencyElem[k] = frequencyElem; k++;
} }
} }
...@@ -986,27 +992,11 @@ bool QRDecode::samplingForVersion() ...@@ -986,27 +992,11 @@ bool QRDecode::samplingForVersion()
} }
straight = Mat(Size(version_size, version_size), CV_8UC1, Scalar(0)); straight = Mat(Size(version_size, version_size), CV_8UC1, Scalar(0));
size_t k = 0; for (int r = 0; r < version_size * version_size; r++)
for (int r = 0; r < no_inter_rows &&
k < listFrequencyElem.size() &&
floor((r * 1.0) / delta_rows) < version_size; r += delta_rows)
{ {
for (int c = 0; c < no_inter_cols && int i = r / straight.cols;
k < listFrequencyElem.size() && int j = r % straight.cols;
floor((c * 1.0) / delta_cols) < version_size; c += delta_cols, k++) straight.ptr<uint8_t>(i)[j] = (listFrequencyElem[r] < experimentalFrequencyElem) ? 0 : 255;
{
Mat tile = postIntermediate(
Range(r, min(r + delta_rows, no_inter_rows)),
Range(c, min(c + delta_cols, no_inter_cols)));
if (listFrequencyElem[k] < experimentalFrequencyElem) { tile.setTo(0); }
else
{
tile.setTo(255);
straight.at<uint8_t>(cvRound(floor((r * 1.0) / delta_rows)),
cvRound(floor((c * 1.0) / delta_cols))) = 255;
}
}
} }
return true; return true;
} }
...@@ -1026,7 +1016,7 @@ bool QRDecode::decodingProcess() ...@@ -1026,7 +1016,7 @@ bool QRDecode::decodingProcess()
{ {
int position = y * qr_code.size + x; int position = y * qr_code.size + x;
qr_code.cell_bitmap[position >> 3] qr_code.cell_bitmap[position >> 3]
|= straight.at<uint8_t>(y, x) ? 0 : (1 << (position & 7)); |= straight.ptr<uint8_t>(y)[x] ? 0 : (1 << (position & 7));
} }
} }
......
...@@ -348,7 +348,9 @@ struct CvCaptureCAM_V4L CV_FINAL : public CvCapture ...@@ -348,7 +348,9 @@ struct CvCaptureCAM_V4L CV_FINAL : public CvCapture
/*********************** Implementations ***************************************/ /*********************** Implementations ***************************************/
CvCaptureCAM_V4L::CvCaptureCAM_V4L() : deviceHandle(-1), bufferIndex(-1) CvCaptureCAM_V4L::CvCaptureCAM_V4L() : deviceHandle(-1), bufferIndex(-1)
{} {
memset(&timestamp, 0, sizeof(timestamp));
}
CvCaptureCAM_V4L::~CvCaptureCAM_V4L() { CvCaptureCAM_V4L::~CvCaptureCAM_V4L() {
streaming(false); streaming(false);
...@@ -1739,7 +1741,6 @@ double CvCaptureCAM_V4L::getProperty(int property_id) const ...@@ -1739,7 +1741,6 @@ double CvCaptureCAM_V4L::getProperty(int property_id) const
return value; return value;
} }
} }
return -1.0;
} }
bool CvCaptureCAM_V4L::icvSetFrameSize(int _width, int _height) bool CvCaptureCAM_V4L::icvSetFrameSize(int _width, int _height)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment