mirror of
https://github.com/opencv/opencv.git
synced 2025-06-07 17:44:04 +08:00
Merge pull request #25183 from MaximSmolskiy:fix-bug-in-maskBoundingRect
Fix bug in maskBoundingRect
This commit is contained in:
commit
d664d8d450
@ -1056,16 +1056,12 @@ static Rect maskBoundingRect( const Mat& img )
|
|||||||
for( ; j < offset; j++ )
|
for( ; j < offset; j++ )
|
||||||
if( _ptr[j] )
|
if( _ptr[j] )
|
||||||
{
|
{
|
||||||
|
if( j < xmin )
|
||||||
|
xmin = j;
|
||||||
|
if( j > xmax )
|
||||||
|
xmax = j;
|
||||||
have_nz = 1;
|
have_nz = 1;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if( j < offset )
|
|
||||||
{
|
|
||||||
if( j < xmin )
|
|
||||||
xmin = j;
|
|
||||||
if( j > xmax )
|
|
||||||
xmax = j;
|
|
||||||
}
|
|
||||||
if( offset < size.width )
|
if( offset < size.width )
|
||||||
{
|
{
|
||||||
xmin -= offset;
|
xmin -= offset;
|
||||||
|
@ -140,4 +140,20 @@ void CV_BoundingRectTest::run(int)
|
|||||||
|
|
||||||
TEST (Imgproc_BoundingRect, accuracy) { CV_BoundingRectTest test; test.safe_run(); }
|
TEST (Imgproc_BoundingRect, accuracy) { CV_BoundingRectTest test; test.safe_run(); }
|
||||||
|
|
||||||
|
TEST (Imgproc_BoundingRect, bug_24217)
|
||||||
|
{
|
||||||
|
for (int image_width = 3; image_width < 20; image_width++)
|
||||||
|
{
|
||||||
|
for (int image_height = 1; image_height < 15; image_height++)
|
||||||
|
{
|
||||||
|
cv::Rect rect(0, image_height - 1, 3, 1);
|
||||||
|
|
||||||
|
cv::Mat image(cv::Size(image_width, image_height), CV_8UC1, cv::Scalar(0));
|
||||||
|
image(rect) = 255;
|
||||||
|
|
||||||
|
ASSERT_EQ(boundingRect(image), rect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}} // namespace
|
}} // namespace
|
||||||
|
Loading…
Reference in New Issue
Block a user