mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
different interpolation by double image (#23124)
* different interpolation by double image * fixing scaling mapping * fixing a test * added an option to enable previous interpolation * added doxygen entries for the new parameter * ASSERT_TRUE -> ASSERT_EQ * changed log message when using old upscale mode
This commit is contained in:
@@ -7,6 +7,34 @@ namespace opencv_test { namespace {
|
||||
/****************************************************************************************\
|
||||
* Regression tests for descriptor extractors. *
|
||||
\****************************************************************************************/
|
||||
static void double_image(Mat& src, Mat& dst) {
|
||||
|
||||
dst.create(Size(src.cols*2, src.rows*2), src.type());
|
||||
|
||||
Mat H = Mat::zeros(2, 3, CV_32F);
|
||||
H.at<float>(0, 0) = 0.5f;
|
||||
H.at<float>(1, 1) = 0.5f;
|
||||
cv::warpAffine(src, dst, H, dst.size(), INTER_LINEAR | WARP_INVERSE_MAP, BORDER_REFLECT);
|
||||
|
||||
}
|
||||
|
||||
static Mat prepare_img(bool rows_indexed) {
|
||||
int rows = 5;
|
||||
int columns = 5;
|
||||
Mat img(rows, columns, CV_32F);
|
||||
|
||||
for (int i = 0; i < rows; i++) {
|
||||
for (int j = 0; j < columns; j++) {
|
||||
if (rows_indexed) {
|
||||
img.at<float>(i, j) = (float)i;
|
||||
} else {
|
||||
img.at<float>(i, j) = (float)j;
|
||||
}
|
||||
}
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
static void writeMatInBin( const Mat& mat, const string& filename )
|
||||
{
|
||||
FILE* f = fopen( filename.c_str(), "wb");
|
||||
@@ -145,6 +173,25 @@ protected:
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
|
||||
}
|
||||
|
||||
image = prepare_img(false);
|
||||
Mat dbl;
|
||||
try
|
||||
{
|
||||
double_image(image, dbl);
|
||||
|
||||
Mat downsized_back(dbl.rows/2, dbl.cols/2, CV_32F);
|
||||
resize(dbl, downsized_back, Size(dbl.cols/2, dbl.rows/2), 0, 0, INTER_NEAREST);
|
||||
|
||||
cv::Mat diff = (image != downsized_back);
|
||||
ASSERT_EQ(0, cv::norm(image, downsized_back, NORM_INF));
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
ts->printf( cvtest::TS::LOG, "double_image() must not generate exception (1).\n");
|
||||
ts->printf( cvtest::TS::LOG, "double_image() when downsized back by NEAREST must generate the same original image (1).\n");
|
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
|
||||
}
|
||||
|
||||
// Several images.
|
||||
vector<Mat> images;
|
||||
vector<vector<KeyPoint> > keypointsCollection;
|
||||
|
||||
@@ -37,7 +37,7 @@ INSTANTIATE_TEST_CASE_P(AKAZE_DESCRIPTOR_KAZE, DetectorRotationInvariance,
|
||||
*/
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(SIFT, DetectorScaleInvariance,
|
||||
Value(IMAGE_BIKES, SIFT::create(0, 3, 0.09), 0.65f, 0.98f));
|
||||
Value(IMAGE_BIKES, SIFT::create(0, 3, 0.09), 0.60f, 0.98f));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(BRISK, DetectorScaleInvariance,
|
||||
Value(IMAGE_BIKES, BRISK::create(), 0.08f, 0.49f));
|
||||
|
||||
@@ -25,7 +25,6 @@ void matchKeyPoints(const vector<KeyPoint>& keypoints0, const Mat& H,
|
||||
perspectiveTransform(Mat(points0), points0t, H);
|
||||
|
||||
matches.clear();
|
||||
vector<uchar> usedMask(keypoints1.size(), 0);
|
||||
for(int i0 = 0; i0 < static_cast<int>(keypoints0.size()); i0++)
|
||||
{
|
||||
int nearestPointIndex = -1;
|
||||
@@ -33,8 +32,6 @@ void matchKeyPoints(const vector<KeyPoint>& keypoints0, const Mat& H,
|
||||
const float r0 = 0.5f * keypoints0[i0].size;
|
||||
for(size_t i1 = 0; i1 < keypoints1.size(); i1++)
|
||||
{
|
||||
if(nearestPointIndex >= 0 && usedMask[i1])
|
||||
continue;
|
||||
|
||||
float r1 = 0.5f * keypoints1[i1].size;
|
||||
float intersectRatio = calcIntersectRatio(points0t.at<Point2f>(i0), r0,
|
||||
@@ -47,8 +44,6 @@ void matchKeyPoints(const vector<KeyPoint>& keypoints0, const Mat& H,
|
||||
}
|
||||
|
||||
matches.push_back(DMatch(i0, nearestPointIndex, maxIntersectRatio));
|
||||
if(nearestPointIndex >= 0)
|
||||
usedMask[nearestPointIndex] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,8 +75,8 @@ void scaleKeyPoints(const vector<KeyPoint>& src, vector<KeyPoint>& dst, float sc
|
||||
dst.resize(src.size());
|
||||
for (size_t i = 0; i < src.size(); i++) {
|
||||
dst[i] = src[i];
|
||||
dst[i].pt.x *= scale;
|
||||
dst[i].pt.y *= scale;
|
||||
dst[i].pt.x = dst[i].pt.x * scale + (scale - 1.0f) / 2.0f;
|
||||
dst[i].pt.y = dst[i].pt.y * scale + (scale - 1.0f) / 2.0f;
|
||||
dst[i].size *= scale;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user