Closed sylvia-segfault closed 11 months ago
Hey @sylvia-segfault, thank you for creating this PR. I am assuming that the changes you have made are for the latest version of the package opencv-python as opposed to opencv-contrib-python which we use for importing the ArUco detection module and deep learning modules.
I suspect that merging this PR would break detection for users using the recommended opencv-contrib-python package as these packages are not API-compatible.
Hi Chintan! Thank you for your response. @MarkusSchiffer and @vinitha910 tried to install the latest version of opencv-contrib-python but still produced errors. It sounds like we would need a very specific configuration for it to work. Could you share the branch of the repo you guys used to run the ArUco markers as well as the version of opencv-contrib-python you used? Thank you!
@sylvia-segfault, the recommended version is opencv-contrib-python >= 4.7.0 along with the dev/noetic branch. If you also have an opencv-python module installed, be sure to uninstall it as it could result in a cv2 namespace collision. Finally, it's a good idea to check the version of opencv being imported in python by launching the IPython interpreter in a terminal and running the following statement:
import cv2; cv2.__version__
This should print '4.7.0'. Please report back what you see after running the same.
Thank you for opening this PR @sylvia-segfault! We had previously pinned OpenCV to an older version, which explains why we couldn't merge this earlier. I just updated the version of OpenCV to 4.8 and the Aruco API has changed as you described. You were ahead of the curve here! Thanks again for filing this fix!
We used
aruco.ArucoDetector
from the latest version of opencv to create a detector object, which is saved inself.detector
. This detector object is then used to calldrawDetectedMarkers
anddetectMarkers
as shown inline 542
andline 559
.The main changes we had to make were for
estimatePoseSingleMarkers
inside theupdate
function of theArucoMarker
class. The official documentation says to usesolvePnp
becauseestimatePoseSingleMarkers
was deprecated in the newest version of opencv. We manually created 3D points (line 196 - line 201
) as the object points passed tosolvePnP
. We used the source code ofestimateSinglePoseMarkers
as a reference and found thatestimateSinglePoseMarkers
callssolvePnP
and it usedgetSingleMarkerObjectPointers
to calculate the object points. Thus, we used the source code ofgetSingleMarkerObjectPointers
to compute 3D object points in Python.We also created 3 dimensional
tvecs
andrvecs
by callingsolvePnP
for every marker (forlen(self.corners)
amount of iterations) and appended the result ofrvec_ret
andtvec_ret
totvecs
andrvec
respectively (notice that these two are different from the finalrvecs
andtvecs
sincervec_ret
andtvec_ret
are 2D vectors) returned bysolvePnP
at every iteration of going through all the markers.