Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

AleksandrPanov
Copy link
Contributor

@AleksandrPanov AleksandrPanov commented Jan 15, 2023

Added python sample to detect charuco board.

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
Copy link
Contributor Author

AleksandrPanov commented Jan 15, 2023

works with choriginal.jpg:
choriginal
tutorial_camera_charuco.yml.txt

args:
-w=5 -h=7 -sl=0.04 -ml=0.02 -d=10 -v=choriginal.jpg

result:
image

To correctly works with matchImagePoints need merge PR #23138

@satpalsr
Copy link

satpalsr commented Jan 18, 2023

Hey @AleksandrPanov , can you share how you generated charuco board? Specially want to fit on A4 paper size.

@AleksandrPanov
Copy link
Contributor Author

AleksandrPanov commented Jan 18, 2023

Hey @satpalsr, you can use code from this sample:

import cv2 as cv
from cv2 import aruco
print(cv.__version__)


"setup"
arucoDict = aruco.getPredefinedDictionary(aruco.DICT_6X6_250)

"create the charuco board"
calibration_board = aruco.CharucoBoard((5, 7), squareLength=0.072, markerLength=0.062, dictionary=arucoDict)
board_image = calibration_board.generateImage((500, 700))
cv.imwrite("sample_board.png", board_image)

@AleksandrPanov AleksandrPanov force-pushed the add_py_charuco_sample branch 2 times, most recently from f80907a to 0a649e5 Compare January 19, 2023 16:50
@asmorkalov
Copy link
Contributor

Current version of sample fails with exception, when Charuco board is shown to camera:

[ WARN:[email protected]] global cap_gstreamer.cpp:1728 open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
Traceback (most recent call last):
  File "./aruco_detect_board_charuco.py", line 110, in <module>
    main()
  File "./aruco_detect_board_charuco.py", line 95, in main
    if len(charuco_ids) > 0:
TypeError: object of type 'NoneType' has no len()

@AleksandrPanov
Copy link
Contributor Author

add NoneType checks

Now sample must works in all cases:
part charuco corners:
image
full charuco corners:
image
and also works without charuco corners

(Uses PR #23138)

@AleksandrPanov AleksandrPanov marked this pull request as draft January 20, 2023 15:15
@AleksandrPanov AleksandrPanov marked this pull request as ready for review January 20, 2023 15:24
@AleksandrPanov
Copy link
Contributor Author

AleksandrPanov commented Jan 20, 2023

I check sample with camera and add new condition to correct work with solvePnP():
if len(cam_matrix) > 0 and len(charuco_ids) >= 4:

@satpalsr
Copy link

Also add if len(obj_points) >= 6:

Otherwise I get

    flag, rvec, tvec = cv.solvePnP(obj_points, img_points, cam_matrix, dist_coefficients)
cv2.error: OpenCV(4.7.0) /io/opencv/modules/calib3d/src/calibration.cpp:1173: error: (-2:Unspecified error) in function 'void cvFindExtrinsicCameraParams2(const CvMat*, const CvMat*, const CvMat*, const CvMat*, CvMat*, CvMat*, int)'
> DLT algorithm needs at least 6 points for pose estimation from 3D-2D point correspondences. (expected: 'count >= 6'), where
>     'count' is 4
> must be greater than or equal to
>     '6' is 6

@satpalsr
Copy link

Also, would be cool to add Charuco camera calibration script/function.

Copy link
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

Please take a look on already maintained samples in the main repository.

@AleksandrPanov AleksandrPanov force-pushed the add_py_charuco_sample branch 2 times, most recently from e031712 to faa479d Compare January 27, 2023 00:53
@asmorkalov
Copy link
Contributor

@alalek Could you take a look again? May the PR be merged?

@AleksandrPanov AleksandrPanov force-pushed the add_py_charuco_sample branch 2 times, most recently from f42d9db to 3960ca2 Compare March 13, 2023 12:07
@asmorkalov asmorkalov self-requested a review March 13, 2023 12:54
@AleksandrPanov AleksandrPanov force-pushed the add_py_charuco_sample branch from 3960ca2 to 0d455e0 Compare March 15, 2023 08:28
@asmorkalov asmorkalov added this to the 4.8.0 milestone Mar 15, 2023
@asmorkalov asmorkalov merged commit 86fa030 into opencv:4.x Mar 15, 2023
@asmorkalov asmorkalov mentioned this pull request May 31, 2023
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