Skip to content

fix findContours in SimpleBlobDetector#24433

Draft
AleksandrPanov wants to merge 1 commit into
opencv:4.xfrom
AleksandrPanov:update_contour_docs
Draft

fix findContours in SimpleBlobDetector#24433
AleksandrPanov wants to merge 1 commit into
opencv:4.xfrom
AleksandrPanov:update_contour_docs

Conversation

@AleksandrPanov
Copy link
Copy Markdown
Contributor

@AleksandrPanov AleksandrPanov commented Oct 20, 2023

commented problem from #24388
TODO: need to fix a bug

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 another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the 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

@AleksandrPanov AleksandrPanov marked this pull request as ready for review October 22, 2023 23:08
minConvexity (inclusive) and maxConvexity (exclusive).

Default values of parameters are tuned to extract dark circular blobs.
@note Don't disable the param filterByArea with dark blobs and white backgound, findContours() find extra contour in this case.
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.

I propose to extract parameters description from brief section and move to each parameter. It fixes doxygen documentation and add help messages to IDE. Also I propose to rephrase the sentence: "filterByArea should be true for black blobs on white background as findContours expects background to be black and adds extra contours for the case."

The function retrieves contours from the binary image using the algorithm @cite Suzuki85 . The contours
are a useful tool for shape analysis and object detection and recognition. See squares.cpp in the
OpenCV sample directory.
OpenCV sample directory, tutorial @ref tutorial_py_contours_begin} or @ref tutorial_find_contours.
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.

extra } in the reference.

Comment on lines +4021 to +4022
@note In OpenCV, finding contours is like finding white object from black background. So remember,
object to be found should be white and background should be black.
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.

I propose to remove note and extend function description:

Non-zero pixels are treated as 1's. Zero
pixels remain 0's, so the image is treated as binary.
Zero values (black color) is used as background.

@asmorkalov
Copy link
Copy Markdown
Contributor

@AleksandrPanov Friendly reminder.

@AleksandrPanov AleksandrPanov marked this pull request as draft November 12, 2023 22:29
@AleksandrPanov
Copy link
Copy Markdown
Contributor Author

The contours of a certain size and in a certain position distort the answer. Perhaps this is due to the wrong grouping.
3

result:
(353.14007568359375, 223.4298553466797) 267.6434326171875
problem
We need a fix for this problem.

@AleksandrPanov AleksandrPanov added bug pr: needs test New functionality requires minimal tests set labels Nov 16, 2023
@AleksandrPanov AleksandrPanov changed the title update docs for findContours/SimpleBlobDetector fix findContours in SimpleBlobDetector Nov 16, 2023
@AleksandrPanov
Copy link
Copy Markdown
Contributor Author

import cv2 as cv

image = cv.imread("3.png", cv.IMREAD_GRAYSCALE)
parameters = cv.SimpleBlobDetector_Params()
detector = cv.SimpleBlobDetector_create(parameters)

keypoints = detector.detect(image)
for kp in keypoints:
    print(kp.pt, kp.size)
    p = (int(kp.pt[0]), int(kp.pt[1]))
    cv.circle(image, p, 5, (255, 255, 255), 2)
cv.imshow("1", image)
cv.waitKey(0)

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

Labels

bug category: documentation Documentation fix or update category: imgproc pr: needs test New functionality requires minimal tests set

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants