Skip to content

Hot fix negative MTCNN PNet ROI coordinates#20245

Merged
alalek merged 3 commits intoopencv:masterfrom
dbudniko:dbudniko/mtcnn_roi_size_hotfix
Jun 9, 2021
Merged

Hot fix negative MTCNN PNet ROI coordinates#20245
alalek merged 3 commits intoopencv:masterfrom
dbudniko:dbudniko/mtcnn_roi_size_hotfix

Conversation

@dbudniko
Copy link
Copy Markdown

@dbudniko dbudniko commented Jun 8, 2021

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

force_builders=Custom,Custom Win,Custom Mac
build_gapi_standalone:Linux x64=ade-0.1.1f
build_gapi_standalone:Win64=ade-0.1.1f
build_gapi_standalone:Mac=ade-0.1.1f
build_gapi_standalone:Linux x64 Debug=ade-0.1.1f

build_image:Custom=centos:7
buildworker:Custom=linux-1
build_gapi_standalone:Custom=ade-0.1.1f

Xbuild_image:Custom=ubuntu-openvino-2020.3.0:16.04
build_image:Custom Win=openvino-2021.3.0
build_image:Custom Mac=openvino-2021.3.0

test_modules:Custom=gapi,python2,python3,java
test_modules:Custom Win=gapi,python2,python3,java
test_modules:Custom Mac=gapi,python2,python3,java

buildworker:Custom=linux-1
// disabled due high memory usage: test_opencl:Custom=ON
test_opencl:Custom=OFF
test_bigdata:Custom=1
test_filter:Custom=*

cv::Rect tmp_rect = face.bbox.getRect();
//Compare to transposed sizes width<->height
tmp_rect &= cv::Rect(tmp_rect.x, tmp_rect.y, in_image_size.height - tmp_rect.x - 4, in_image_size.width - tmp_rect.y - 4);
tmp_rect &= cv::Rect(std::max(tmp_rect.x, 0), std::max(tmp_rect.y, 0), in_image_size.height - tmp_rect.x - 4, in_image_size.width - tmp_rect.y - 4);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if tmp_rect.x is negative, then probably the width argument is not calculated properly too (e.g, it may exceed image size).

What is about this?

tmp_rect &= cv::Rect(...previous variant...) & cv::Rect(0, 0, in_image_size.height - 4, in_image_size.width - 4)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • if possible, please give a name for 4 :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm stuck trying to give a name for 4. So I just removed it. :)

@sivanov-work
Copy link
Copy Markdown
Contributor

sivanov-work commented Jun 9, 2021

i suppose the a negative value could appeared from here
https://github.com/opencv/opencv/pull/20245/files#R76
in case of side is more than bboxHeight

BBox getSquare() const { 
...
   float side = std::max(bboxWidth, bboxHeight); 
...
 bbox.y1 = static_cast<int>(static_cast<float>(y1) + (bboxHeight - side) * 0.5f);

IMHO, the fix should be here

Copy link
Copy Markdown
Contributor

@dmatveev dmatveev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go ahead

@dbudniko
Copy link
Copy Markdown
Author

dbudniko commented Jun 9, 2021

@alalek let's merge. I tried multiple video inputs. Everything works just fine now.

@alalek alalek merged commit 4c2dff8 into opencv:master Jun 9, 2021
@alalek alalek mentioned this pull request Jun 13, 2021
@alalek alalek mentioned this pull request Oct 15, 2021
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
…_hotfix

Hot fix negative MTCNN PNet ROI coordinates

* fix negative roi start

* some more experiments

* clean up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants