mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 06:03:15 +08:00
fixed for resize with INTER AREA. Since now we divide by convolved area
This commit is contained in:
parent
eabd757def
commit
8231d0d11d
@ -1274,13 +1274,13 @@ static void resizeArea_( const Mat& src, Mat& dst, const DecimateAlpha* xofs, in
|
||||
if( fabs(beta) < 1e-3 )
|
||||
for( dx = 0; dx < dsize.width; dx++ )
|
||||
{
|
||||
D[dx] = saturate_cast<T>(sum[dx] + buf[dx]);
|
||||
D[dx] = saturate_cast<T>((sum[dx] + buf[dx]) / min(scale_y, src.cols - cur_dy * scale_y));
|
||||
sum[dx] = buf[dx] = 0;
|
||||
}
|
||||
else
|
||||
for( dx = 0; dx < dsize.width; dx++ )
|
||||
{
|
||||
D[dx] = saturate_cast<T>(sum[dx] + buf[dx]*beta1);
|
||||
D[dx] = saturate_cast<T>((sum[dx] + buf[dx]* beta1)/ min(scale_y, src.cols - cur_dy*scale_y));
|
||||
sum[dx] = buf[dx]*beta;
|
||||
buf[dx] = 0;
|
||||
}
|
||||
@ -1498,7 +1498,6 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize,
|
||||
|
||||
AutoBuffer<DecimateAlpha> _xofs(ssize.width*2);
|
||||
DecimateAlpha* xofs = _xofs;
|
||||
double scale = 1.f/(scale_x*scale_y);
|
||||
|
||||
for( dx = 0, k = 0; dx < dsize.width; dx++ )
|
||||
{
|
||||
@ -1512,7 +1511,7 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize,
|
||||
assert( k < ssize.width*2 );
|
||||
xofs[k].di = dx*cn;
|
||||
xofs[k].si = (sx1-1)*cn;
|
||||
xofs[k++].alpha = (float)((sx1 - fsx1)*scale);
|
||||
xofs[k++].alpha = (float)((sx1 - fsx1) / min(scale_x, src.cols - fsx1));
|
||||
}
|
||||
|
||||
for( sx = sx1; sx < sx2; sx++ )
|
||||
@ -1520,7 +1519,7 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize,
|
||||
assert( k < ssize.width*2 );
|
||||
xofs[k].di = dx*cn;
|
||||
xofs[k].si = sx*cn;
|
||||
xofs[k++].alpha = (float)scale;
|
||||
xofs[k++].alpha = 1.f / min(scale_x, src.cols - fsx1);
|
||||
}
|
||||
|
||||
if( fsx2 - sx2 > 1e-3 )
|
||||
@ -1528,10 +1527,9 @@ void cv::resize( InputArray _src, OutputArray _dst, Size dsize,
|
||||
assert( k < ssize.width*2 );
|
||||
xofs[k].di = dx*cn;
|
||||
xofs[k].si = sx2*cn;
|
||||
xofs[k++].alpha = (float)(min(fsx2 - sx2, 1.)*scale);
|
||||
xofs[k++].alpha = (float)(min(fsx2 - sx2, 1.) / min(scale_x, src.cols - fsx1));
|
||||
}
|
||||
}
|
||||
|
||||
func( src, dst, xofs, k ,scale_y);
|
||||
return;
|
||||
}
|
||||
|
@ -1462,6 +1462,51 @@ TEST(Imgproc_fitLine_Mat_3dC1, regression)
|
||||
ASSERT_EQ(line2.size(), (size_t)6);
|
||||
}
|
||||
|
||||
TEST(Imgproc_resize_area, regression)
|
||||
{
|
||||
static ushort input_data[16 * 16] = {
|
||||
90, 94, 80, 3, 231, 2, 186, 245, 188, 165, 10, 19, 201, 169, 8, 228,
|
||||
86, 5, 203, 120, 136, 185, 24, 94, 81, 150, 163, 137, 88, 105, 132, 132,
|
||||
236, 48, 250, 218, 19, 52, 54, 221, 159, 112, 45, 11, 152, 153, 112, 134,
|
||||
78, 133, 136, 83, 65, 76, 82, 250, 9, 235, 148, 26, 236, 179, 200, 50,
|
||||
99, 51, 103, 142, 201, 65, 176, 33, 49, 226, 177, 109, 46, 21, 67, 130,
|
||||
54, 125, 107, 154, 145, 51, 199, 189, 161, 142, 231, 240, 139, 162, 240, 22,
|
||||
231, 86, 79, 106, 92, 47, 146, 156, 36, 207, 71, 33, 2, 244, 221, 71,
|
||||
44, 127, 71, 177, 75, 126, 68, 119, 200, 129, 191, 251, 6, 236, 247, 6,
|
||||
133, 175, 56, 239, 147, 221, 243, 154, 242, 82, 106, 99, 77, 158, 60, 229,
|
||||
2, 42, 24, 174, 27, 198, 14, 204, 246, 251, 141, 31, 114, 163, 29, 147,
|
||||
121, 53, 74, 31, 147, 189, 42, 98, 202, 17, 228, 123, 209, 40, 77, 49,
|
||||
112, 203, 30, 12, 205, 25, 19, 106, 145, 185, 163, 201, 237, 223, 247, 38,
|
||||
33, 105, 243, 117, 92, 179, 204, 248, 160, 90, 73, 126, 2, 41, 213, 204,
|
||||
6, 124, 195, 201, 230, 187, 210, 167, 48, 79, 123, 159, 145, 218, 105, 209,
|
||||
240, 152, 136, 235, 235, 164, 157, 9, 152, 38, 27, 209, 120, 77, 238, 196,
|
||||
240, 233, 10, 241, 90, 67, 12, 79, 0, 43, 58, 27, 83, 199, 190, 182};
|
||||
|
||||
static ushort expected_data[5 * 5] = {
|
||||
120, 100, 151, 101, 130,
|
||||
106, 115, 141, 130, 127,
|
||||
91, 136, 170, 114, 140,
|
||||
104, 122, 131, 147, 133,
|
||||
161, 163, 70, 107, 182
|
||||
};
|
||||
|
||||
cv::Mat src(16, 16, CV_16UC1, input_data);
|
||||
cv::Mat actual;
|
||||
cv::Mat expected(5,5,CV_16UC1, expected_data);
|
||||
|
||||
cv::resize(src, actual, cv::Size(), 0.3, 0.3, INTER_AREA);
|
||||
std::cout << actual << std::endl;
|
||||
std::cout << expected << std::endl;
|
||||
|
||||
ASSERT_EQ(actual.type(), expected.type());
|
||||
ASSERT_EQ(actual.size(), expected.size());
|
||||
Mat diff;
|
||||
absdiff(actual, expected, diff);
|
||||
Mat one_channel_diff = diff.reshape(1);
|
||||
ASSERT_EQ(norm(one_channel_diff, cv::NORM_INF),0);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST(Imgproc_Resize, accuracy) { CV_ResizeTest test; test.safe_run(); }
|
||||
|
Loading…
Reference in New Issue
Block a user