Detect_aruco_markers node not working in ROS2

Hi,
When I try to use detect_aruco_markers node, I get the following error:

/opt/ros/galactic/bin/ros2:6: DeprecationWarning: pkg_resources is deprecated as an API. See Package Discovery and Resource Access using pkg_resources - setuptools 69.0.2.post20231206 documentation

  • from pkg_resources import load_entry_point*
    [INFO] [launch]: All log files can be found below /home/hello-robot/.ros/log/2023-12-12-15-36-24-986549-stretch-re1-1049-7007
    [INFO] [launch]: Default logging verbosity is set to INFO
    [INFO] [detect_aruco_markers-1]: process started with pid [7009]
    [detect_aruco_markers-1] [INFO] [1702416986.299282752] [detect_aruco_node]: detect_aruco_node started
    [detect_aruco_markers-1] /home/hello-robot/ament_ws/install/stretch_core/lib/stretch_core/detect_aruco_markers:6: DeprecationWarning: pkg_resources is deprecated as an API. See Package Discovery and Resource Access using pkg_resources - setuptools 69.0.2.post20231206 documentation
    [detect_aruco_markers-1] from pkg_resources import load_entry_point
    [detect_aruco_markers-1] Traceback (most recent call last):
    [detect_aruco_markers-1] File “/home/hello-robot/ament_ws/install/stretch_core/lib/stretch_core/detect_aruco_markers”, line 11, in
    [detect_aruco_markers-1] load_entry_point(‘stretch-core==0.2.0’, ‘console_scripts’, ‘detect_aruco_markers’)()
    [detect_aruco_markers-1] File “/home/hello-robot/ament_ws/install/stretch_core/lib/python3.8/site-packages/stretch_core/detect_aruco_markers.py”, line 811, in main
    [detect_aruco_markers-1] rclpy.spin(node)
    [detect_aruco_markers-1] File “/opt/ros/galactic/lib/python3.8/site-packages/rclpy/init.py”, line 196, in spin
    [detect_aruco_markers-1] executor.spin_once()
    [detect_aruco_markers-1] File “/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py”, line 713, in spin_once
    [detect_aruco_markers-1] raise handler.exception()
    [detect_aruco_markers-1] File “/opt/ros/galactic/lib/python3.8/site-packages/rclpy/task.py”, line 239, in call
    [detect_aruco_markers-1] self._handler.send(None)
    [detect_aruco_markers-1] File “/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py”, line 418, in handler
    [detect_aruco_markers-1] await call_coroutine(entity, arg)
    [detect_aruco_markers-1] File “/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py”, line 343, in _execute_subscription
    [detect_aruco_markers-1] await await_or_execute(sub.callback, msg)
    [detect_aruco_markers-1] File “/opt/ros/galactic/lib/python3.8/site-packages/rclpy/executors.py”, line 107, in await_or_execute
    [detect_aruco_markers-1] return callback(args)
    [detect_aruco_markers-1] File “/opt/ros/galactic/lib/python3.8/site-packages/message_filters/init.py”, line 83, in callback
    [detect_aruco_markers-1] self.signalMessage(msg)
    [detect_aruco_markers-1] File “/opt/ros/galactic/lib/python3.8/site-packages/message_filters/init.py”, line 64, in signalMessage
    [detect_aruco_markers-1] cb((msg + args))

    [detect_aruco_markers-1] File “/opt/ros/galactic/lib/python3.8/site-packages/message_filters/init.py”, line 237, in add
    [detect_aruco_markers-1] self.signalMessage(msgs)
    [detect_aruco_markers-1] File “/opt/ros/galactic/lib/python3.8/site-packages/message_filters/init.py”, line 64, in signalMessage
    [detect_aruco_markers-1] cb((msg + args))

    [detect_aruco_markers-1] File “/home/hello-robot/ament_ws/install/stretch_core/lib/python3.8/site-packages/stretch_core/detect_aruco_markers.py”, line 692, in image_callback
    [detect_aruco_markers-1] self.aruco_marker_collection.update(self.rgb_image, self.camera_info, self.depth_image, self.rgb_image_timestamp)
    [detect_aruco_markers-1] File “/home/hello-robot/ament_ws/install/stretch_core/lib/python3.8/site-packages/stretch_core/detect_aruco_markers.py”, line 569, in update
    [detect_aruco_markers-1] self.aruco_corners, self.aruco_ids, aruco_rejected_image_points = aruco.detectMarkers(self.gray_image,
    [detect_aruco_markers-1] AttributeError: module ‘cv2.aruco’ has no attribute ‘detectMarkers’
    [ERROR] [detect_aruco_markers-1]: process has died [pid 7009, exit code 1, cmd ‘/home/hello-robot/ament_ws/install/stretch_core/lib/stretch_core/detect_aruco_markers --ros-args --params-file /home/hello-robot/ament_ws/install/stretch_core/share/stretch_core/config/stretch_marker_dict.yaml’].

It seems that there is a problem in openCV. Similar error occured in ROS, but when I updated my ROS workspace, it was fixed. I tried to do same with ament workspace, but did not work because of version issue. How can I solve this issue?

Hi @Rupesh,

This could be an issue regarding the python version from OpenCV, can you please run in your terminal:

pip3 list | grep opencv

I would like to check this first and compare with what I have, so that I can reproduce the issue and give you a proper solution.

Screenshot 2023-12-13 130353
Hi @jesusrdz ,
I got this.

Hi @Rupesh,

I tried reproducing the issue but I didn’t manage to do it, but I have some points that you can do:

  • You can try uninstalling the opencv-python package, apparently, there are some issues if you have opencv-contrib-python and opencv-python, you can run in your terminal pip3 uninstall opencv-python, then you can try upgrading your contrib version, I have the 4.8.1.78, you can run pip3 install opencv-contrib-python==4.8.1.78, the main reason is because OpenCV tells you that you only need one package, you can check the opencv repo for more information.
    image

  • Another important thing is that unfortunately we no longer support Galactic, if you want you can try the installation of ubuntu 22.04 and within this version of ubuntu you can use ROS2 Humble.

This is what I have right now and I don’t present issues with the launch of the detect_aruco_markers node, we can try this path but let me know what you think.