Skip to content

Commit 51cb56e

Browse files
terfendailvpisarev
authored andcommitted
Implementation of bit-exact resize. Internal calls to linear resize updated to use bit-exact version. (opencv#9468)
1 parent 84ee4d7 commit 51cb56e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1300
-112
lines changed

3rdparty/carotene/src/resize.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ bool isResizeLinearOpenCVSupported(const Size2D &ssize, const Size2D &dsize, u32
106106
&& !(ssize.width > 0xffffFFFF || ssize.height > 0xffffFFFF)// Restrict image size since internal index evaluation
107107
// is performed with u32
108108
#endif
109-
&& dsize.width >= 2 && dsize.height >= 8)
109+
&& dsize.width >= 2 && dsize.height >= 8
110+
&& (2*dsize.width != ssize.width || 2*dsize.height != ssize.height)) // 2x downscaling is performed as area in OpenCV which differs from this implementation
110111
return isSupportedConfiguration();
111112
default:
112113
return false;

apps/annotation/opencv_annotation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ int main( int argc, const char** argv )
273273
}
274274

275275
if(resize_bool){
276-
resize(current_image, current_image, Size(current_image.cols/resizeFactor, current_image.rows/resizeFactor));
276+
resize(current_image, current_image, Size(current_image.cols/resizeFactor, current_image.rows/resizeFactor), 0, 0, INTER_LINEAR_EXACT);
277277
}
278278

279279
// Perform annotations & store the result inside the vectorized structure

apps/createsamples/utility.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,8 @@ void icvPlaceDistortedSample( Mat background,
686686
Mat img( background.size(), CV_8UC1 );
687687
Mat maskimg( background.size(), CV_8UC1 );
688688

689-
resize( data->img(roi), img, img.size(), 0, 0, INTER_LINEAR);
690-
resize( data->maskimg(roi), maskimg, maskimg.size(), 0, 0, INTER_LINEAR);
689+
resize( data->img(roi), img, img.size(), 0, 0, INTER_LINEAR_EXACT);
690+
resize( data->maskimg(roi), maskimg, maskimg.size(), 0, 0, INTER_LINEAR_EXACT);
691691

692692
forecolordev = (int) (maxintensitydev * (2.0 * rand() / RAND_MAX - 1.0));
693693

@@ -877,7 +877,7 @@ void icvGetNextFromBackgroundData( CvBackgroundData* data,
877877
((float) data->winsize.height + reader->point.y) / ((float) reader->src.rows) );
878878

879879
resize( reader->src, reader->img,
880-
Size((int)(reader->scale * reader->src.rows + 0.5F), (int)(reader->scale * reader->src.cols + 0.5F)), 0, 0, INTER_LINEAR );
880+
Size((int)(reader->scale * reader->src.rows + 0.5F), (int)(reader->scale * reader->src.cols + 0.5F)), 0, 0, INTER_LINEAR_EXACT );
881881
}
882882

883883
/*
@@ -932,7 +932,7 @@ void icvGetBackgroundImage( CvBackgroundData* data,
932932
if( reader->scale <= 1.0F )
933933
{
934934
resize(reader->src, reader->img,
935-
Size((int)(reader->scale * reader->src.rows), (int)(reader->scale * reader->src.cols)), 0, 0, INTER_LINEAR);
935+
Size((int)(reader->scale * reader->src.rows), (int)(reader->scale * reader->src.cols)), 0, 0, INTER_LINEAR_EXACT);
936936
}
937937
else
938938
{
@@ -1323,7 +1323,7 @@ int cvCreateTrainingSamplesFromInfo( const char* infoname, const char* vecfilena
13231323
if( error ) break;
13241324
Mat sample;
13251325
resize( src(Rect(x, y, width, height)), sample, Size(winwidth, winheight), 0, 0,
1326-
width >= winwidth && height >= winheight ? INTER_AREA : INTER_LINEAR );
1326+
width >= winwidth && height >= winheight ? INTER_AREA : INTER_LINEAR_EXACT );
13271327

13281328
if( showsamples )
13291329
{
@@ -1452,7 +1452,7 @@ void cvShowVecSamples( const char* filename, int winwidth, int winheight,
14521452
icvGetTraininDataFromVec( sample, file );
14531453
if( scale != 1.0 )
14541454
resize( sample, sample,
1455-
Size(MAX(1, cvCeil(scale * winheight)), MAX(1, cvCeil(scale * winwidth))), 0, 0, INTER_LINEAR);
1455+
Size(MAX(1, cvCeil(scale * winheight)), MAX(1, cvCeil(scale * winwidth))), 0, 0, INTER_LINEAR_EXACT);
14561456
imshow( "Sample", sample );
14571457
if( (waitKey( 0 ) & 0xFF) == 27 ) break;
14581458
}

apps/traincascade/imagestorage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ bool CvCascadeImageReader::NegReader::nextImg()
7777
((float)winSize.height + point.y) / ((float)src.rows) );
7878

7979
Size sz( (int)(scale*src.cols + 0.5F), (int)(scale*src.rows + 0.5F) );
80-
resize( src, img, sz );
80+
resize( src, img, sz, 0, 0, INTER_LINEAR_EXACT );
8181
return true;
8282
}
8383

@@ -108,7 +108,7 @@ bool CvCascadeImageReader::NegReader::get( Mat& _img )
108108
point.y = offset.y;
109109
scale *= scaleFactor;
110110
if( scale <= 1.0F )
111-
resize( src, img, Size( (int)(scale*src.cols), (int)(scale*src.rows) ) );
111+
resize( src, img, Size( (int)(scale*src.cols), (int)(scale*src.rows) ), 0, 0, INTER_LINEAR_EXACT );
112112
else
113113
{
114114
if ( !nextImg() )

apps/visualisation/opencv_visualisation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ int main( int argc, const char** argv )
142142
return -1;
143143
}
144144
Mat visualization;
145-
resize(reference_image, visualization, Size(reference_image.cols * resize_factor, reference_image.rows * resize_factor));
145+
resize(reference_image, visualization, Size(reference_image.cols * resize_factor, reference_image.rows * resize_factor), 0, 0, INTER_LINEAR_EXACT);
146146

147147
// First recover for each stage the number of weak features and their index
148148
// Important since it is NOT sequential when using LBP features
@@ -220,7 +220,7 @@ int main( int argc, const char** argv )
220220
int current_feature_index = stage_features[sid][fid];
221221
current_rects = feature_data[current_feature_index];
222222
Mat single_feature = reference_image.clone();
223-
resize(single_feature, single_feature, Size(), resize_storage_factor, resize_storage_factor);
223+
resize(single_feature, single_feature, Size(), resize_storage_factor, resize_storage_factor, INTER_LINEAR_EXACT);
224224
for(int i = 0; i < (int)current_rects.size(); i++){
225225
rect_data local = current_rects[i];
226226
if(draw_planes){
@@ -293,7 +293,7 @@ int main( int argc, const char** argv )
293293
int current_feature_index = stage_features[sid][fid];
294294
Rect current_rect = feature_data[current_feature_index];
295295
Mat single_feature = reference_image.clone();
296-
resize(single_feature, single_feature, Size(), resize_storage_factor, resize_storage_factor);
296+
resize(single_feature, single_feature, Size(), resize_storage_factor, resize_storage_factor, INTER_LINEAR_EXACT);
297297

298298
// VISUALISATION
299299
// The rectangle is the top left one of a 3x3 block LBP constructor

modules/calib3d/test/test_cameracalibration.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,10 +1431,10 @@ void CV_StereoCalibrationCornerTest::run(int)
14311431
// perform remap-resize
14321432
Mat src_result;
14331433
remap(image, src_result, srcRmap[0], srcRmap[1], INTER_LINEAR);
1434-
resize(src_result, src_result, Size(), scale, scale, INTER_LINEAR);
1434+
resize(src_result, src_result, Size(), scale, scale, INTER_LINEAR_EXACT);
14351435
// perform resize-remap
14361436
Mat rsz_result;
1437-
resize(image, rsz_result, Size(), scale, scale, INTER_LINEAR);
1437+
resize(image, rsz_result, Size(), scale, scale, INTER_LINEAR_EXACT);
14381438
remap(rsz_result, rsz_result, rszRmap[0], rszRmap[1], INTER_LINEAR);
14391439

14401440
// modifying the camera matrix with resizeCameraMatrix must yield the same

modules/calib3d/test/test_chessboardgenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Mat cv::ChessBoardGenerator::generateChessBoard(const Mat& bg, const Mat& camMat
169169
else
170170
{
171171
Mat tmp;
172-
resize(bg, tmp, bg.size() * rendererResolutionMultiplier);
172+
resize(bg, tmp, bg.size() * rendererResolutionMultiplier, 0, 0, INTER_LINEAR_EXACT);
173173
drawContours(tmp, whole_contour, -1, Scalar::all(255), FILLED, LINE_AA);
174174
drawContours(tmp, squares_black, -1, Scalar::all(0), FILLED, LINE_AA);
175175
resize(tmp, result, bg.size(), 0, 0, INTER_AREA);

modules/dnn/src/dnn.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ Mat blobFromImages(const std::vector<Mat>& images_, double scalefactor, Size siz
108108
{
109109
float resizeFactor = std::max(size.width / (float)imgSize.width,
110110
size.height / (float)imgSize.height);
111-
resize(images[i], images[i], Size(), resizeFactor, resizeFactor);
111+
resize(images[i], images[i], Size(), resizeFactor, resizeFactor, INTER_LINEAR);
112112
Rect crop(Point(0.5 * (images[i].cols - size.width),
113113
0.5 * (images[i].rows - size.height)),
114114
size);
115115
images[i] = images[i](crop);
116116
}
117117
else
118-
resize(images[i], images[i], size);
118+
resize(images[i], images[i], size, 0, 0, INTER_LINEAR);
119119
}
120120
if(images[i].depth() == CV_8U)
121121
images[i].convertTo(images[i], CV_32F);

modules/features2d/src/orb.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,10 +1060,10 @@ void ORB_Impl::detectAndCompute( InputArray _image, InputArray _mask,
10601060
// Compute the resized image
10611061
if( level != firstLevel )
10621062
{
1063-
resize(prevImg, currImg, sz, 0, 0, INTER_LINEAR);
1063+
resize(prevImg, currImg, sz, 0, 0, INTER_LINEAR_EXACT);
10641064
if( !mask.empty() )
10651065
{
1066-
resize(prevMask, currMask, sz, 0, 0, INTER_LINEAR);
1066+
resize(prevMask, currMask, sz, 0, 0, INTER_LINEAR_EXACT);
10671067
if( level > firstLevel )
10681068
threshold(currMask, currMask, 254, 0, THRESH_TOZERO);
10691069
}

modules/features2d/test/test_descriptors_invariance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ TEST_P(DescriptorScaleInvariance, scale)
132132
float scale = 1.f + scaleIdx * 0.5f;
133133

134134
Mat image1;
135-
resize(image0, image1, Size(), 1./scale, 1./scale);
135+
resize(image0, image1, Size(), 1./scale, 1./scale, INTER_LINEAR_EXACT);
136136

137137
vector<KeyPoint> keypoints1;
138138
scaleKeyPoints(keypoints0, keypoints1, 1.0f/scale);

0 commit comments

Comments
 (0)