I am trying to send a .png file or .avi file to a Node, apriltag
, with Isaac-ROS-Apriltag without using Isaac SIM.
However, I cannot solve it.
I think if I can control the messages like the rqt_graph image I attached, I can send the .png image.
But it is difficult and errors occurred.
Could I ask two questions?
- Is it possible to send not streams from usb camera but image or movie files to Isaac-ROS-Apriltag and detect apriltag markers in the files?
- If possible, what should I change in my code?
Thank you.
my code, 3d_april.py
import os, sys
import rclpy
from rclpy.node import Node
import cv2
from cv_bridge import CvBridge, CvBridgeError
from sensor_msgs.msg import Image, CameraInfo
import logging
logging.basicConfig(
stream=sys.stdout,
level=logging.DEBUG,
format="[%(asctime)s] [%(levelname)s] [%(filename)s] [Line : %(lineno)d] [module : %(module)s] [PID : %(process)d] %(message)s")
class Send_3d_April(Node):
def __init__(self):
super().__init__("send_3d_april")
self.publisher_image = self.create_publisher(Image, "image", 10)
self.publisher_camera_info = self.create_publisher(CameraInfo, "camera_info", 10)
timer_period = 1
self.timer = self.create_timer(timer_period, self.send_3d_image_producer_callback)
self.i = 0
def send_3d_image_producer_callback(self):
# I referred to `$ play quickstart.bag`and set these parameters
msg_image = Image()
msg_image.header.stamp.sec = 333 # uint8
msg_image.header.stamp.nanosec = 716684071 # uint32
msg_image.header.frame_id = "3d_image" # string
msg_image.width = 1920 # uint32
msg_image.height = 1080 # uint32
msg_image.encoding = "rgb8" # string
msg_image.is_bigendian = 0 # uint8
msg_image.step = 5760 # uint32
cv_bridge = CvBridge()
cv_image = cv2.imread("tag36h11_00555.png", cv2.IMREAD_COLOR)
cv_image = cv2.cvtColor(cv_image, cv2.COLOR_BGR2RGB)
try:
# TODO!
# An exception occurred.". / The 'data' field must be a set or sequence and each value of type 'int' and each unsigned integer in [0, 255]`
# msg_image.data = cv_bridge.cv2_to_imgmsg(cv_image, encoding="rgb8")
# logging.debug(f"Type of msg_image / {type(self.bridge.cv2_to_imgmsg(np.array(self.cv_image), encoding='bgr8'))}") # <class 'sensor_msgs.msg._image.Image'>
# So, I use following this instead.
msg_image.data = np.array(cv_image).flatten().tolist()
except CvBridgeError as err:
logging.error(f"Error occured when using CvBridge: {err}")
msg_camera_info = CameraInfo()
msg_camera_info.header.stamp.sec = 333
msg_camera_info.header.stamp.nanosec = 300017382
msg_camera_info.header.frame_id = "3d_image"
msg_camera_info.width = 1920
msg_camera_info.width = 1080
msg_camera_info.distortion_model = "pinhole"
msg_camera_info.d = []
msg_camera_info.k = [
1465.99853515625,
0.0,
640.0,
0.0,
1468.26416015625,
360.0,
0.0,
0.0,
1.0,
]
msg_camera_info.r = [
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
]
msg_camera_info.p = [
1465.99853515625,
0.0,
640.0,
0.0,
0.0,
1468.26416015625,
360.0,
0.0,
0.0,
0.0,
1.0,
0.0,
]
msg_camera_info.binning_x = 0
msg_camera_info.binning_y = 0
msg_camera_info.roi.x_offset = 0
msg_camera_info.roi.y_offset = 0
msg_camera_info.roi.height = 0
msg_camera_info.roi.width = 0
msg_camera_info.roi.do_rectify = False
self.publisher.publish(msg_image)
self.publisher.publish(msg_camera_info)
# self.get_logger().info(f"Publishing, {msg_image.data}")
self.i += 1
# self.destroy_timer(self.timer)
def main(args=None):
try:
logging.info("Send 3D image to Apriltag Node.")
rclpy.init(args=args)
send_3d_april = Send_3d_April()
rclpy.spin_once(send_3d_april)
except KeyboardInterrupt as err:
logging.error('Interrupted by Keybord "ctrl + C". / {}'.format(err))
except Exception as exc:
logging.error('An exception occurred.". / {}'.format(exc))
finally:
send_3d_april.destroy_node()
rclpy.shutdown()
logging.info("Node, send_3D_image_to_apriltag, is terminated.")
if __name__ == '__main__':
main()
No info is shown after run 3d_april.py
as $ python 3d_april.py
.
uma7@uma7:~$ cd ${ISAAC_ROS_WS}/src/isaac_ros_common && ./scripts/run_dev.sh
admin@uma7:/workspaces/isaac_ros-dev$ ros2 topic echo /tag_detections
And if I run 3d_april.py
twice, this error occurred…
admin@uma7:/workspaces/isaac_ros-dev$ ros2 launch isaac_ros_apriltag isaac_ros_apriltag.launch.py
[component_container_mt-1] CUDA error at /workspaces/isaac_ros-dev/lib/src/cuapriltags/april_tagging/corner_detection/corner_detector.cpp:97 code=2(cudaErrorMemoryAllocation) "cudaMalloc((void**)&d_gradient_x2, sizeof(float) * gradient_w * gradient_h)"
[component_container_mt-1] CUDA error at /workspaces/isaac_ros-dev/lib/src/cuapriltags/april_tagging/corner_detection/corner_detector.cpp:98 code=2(cudaErrorMemoryAllocation) "cudaMalloc((void**)&d_gradient_y2, sizeof(float) * gradient_w * gradient_h)"
[component_container_mt-1] CUDA error at /workspaces/isaac_ros-dev/lib/src/cuapriltags/april_tagging/corner_detection/corner_detector.cpp:99 code=2(cudaErrorMemoryAllocation) "cudaMalloc((void**)&d_gradient_xy, sizeof(float) * gradient_w * gradient_h)"
[component_container_mt-1] CUDA error at /workspaces/isaac_ros-dev/lib/src/cuapriltags/april_tagging/corner_detection/corner_detector.cpp:100 code=2(cudaErrorMemoryAllocation) "cudaMalloc((void**)&d_blur_gradient_x2, sizeof(float) * blur_gradient_w * blur_gradient_h)"
[component_container_mt-1] CUDA error at /workspaces/isaac_ros-dev/lib/src/cuapriltags/april_tagging/corner_detection/corner_detector.cpp:101 code=2(cudaErrorMemoryAllocation) "cudaMalloc((void**)&d_blur_gradient_y2, sizeof(float) * blur_gradient_w * blur_gradient_h)"
[component_container_mt-1] CUDA error at /workspaces/isaac_ros-dev/lib/src/cuapriltags/april_tagging/corner_detection/corner_detector.cpp:102 code=2(cudaErrorMemoryAllocation) "cudaMalloc((void**)&d_blur_gradient_xy, sizeof(float) * blur_gradient_w * blur_gradient_h)"
[component_container_mt-1] CUDA error at /workspaces/isaac_ros-dev/lib/src/cuapriltags/april_tagging/corner_detection/corner_detector.cpp:104 code=2(cudaErrorMemoryAllocation) "cudaMalloc((void**)&d_maxima_suppression, sizeof(bool) * corners_w * corners_h)"
[component_container_mt-1] CUDA error at /workspaces/isaac_ros-dev/lib/src/cuapriltags/april_tagging/corner_detection/corner_detector.cpp:186 code=700(cudaErrorIllegalAddress) "cudaEventRecord(sync_event_x2, main_stream)"
[component_container_mt-1] CUDA error at /workspaces/isaac_ros-dev/lib/src/cuapriltags/april_tagging/corner_detection/corner_detector.cpp:187 code=700(cudaErrorIllegalAddress) "cudaStreamWaitEvent(x2_stream, sync_event_x2, 0)"
[component_container_mt-1] CUDA error at /workspaces/isaac_ros-dev/lib/src/cuapriltags/april_tagging/corner_detection/corner_detector.cpp:196 code=700(cudaErrorIllegalAddress) "cudaEventRecord(sync_event_y2, main_stream)"
[component_container_mt-1] CUDA error at /workspaces/isaac_ros-dev/lib/src/cuapriltags/april_tagging/corner_detection/corner_detector.cpp:197 code=700(cudaErrorIllegalAddress) "cudaStreamWaitEvent(y2_stream, sync_event_y2, 0)"
[component_container_mt-1] CUDA error at /workspaces/isaac_ros-dev/lib/src/cuapriltags/april_tagging/corner_detection/corner_detector.cpp:217 code=700(cudaErrorIllegalAddress) "cudaEventRecord(sync_event_x2, x2_stream)"
[component_container_mt-1] CUDA error at /workspaces/isaac_ros-dev/lib/src/cuapriltags/april_tagging/corner_detection/corner_detector.cpp:218 code=700(cudaErrorIllegalAddress) "cudaStreamWaitEvent(main_stream, sync_event_x2, 0)"
[component_container_mt-1] CUDA error at /workspaces/isaac_ros-dev/lib/src/cuapriltags/april_tagging/corner_detection/corner_detector.cpp:219 code=700(cudaErrorIllegalAddress) "cudaEventRecord(sync_event_y2, y2_stream)"
[component_container_mt-1] CUDA error at /workspaces/isaac_ros-dev/lib/src/cuapriltags/april_tagging/corner_detection/corner_detector.cpp:220 code=700(cudaErrorIllegalAddress) "cudaStreamWaitEvent(main_stream, sync_event_y2, 0)"
[component_container_mt-1] CUDA error at /workspaces/isaac_ros-dev/lib/src/cuapriltags/april_tagging/corner_detection/corner_detector.cpp:151 code=700(cudaErrorIllegalAddress) "cudaMemsetAsync(d_maxima_suppression, 1, sizeof(bool) * corners_w * corners_h, main_stream)"
[component_container_mt-1] CUDA error at /workspaces/isaac_ros-dev/lib/src/cuapriltags/april_tagging/quad_detection/quad_detector.cpp:32 code=700(cudaErrorIllegalAddress) "cudaMemsetAsync(bound_corners_cnt_.Data(), 0, sizeof(uint32_t), boundary_stream_)"
[component_container_mt-1] CUDA error at /workspaces/isaac_ros-dev/lib/src/cuapriltags/april_tagging/quad_detection/quad_detector.cpp:34 code=700(cudaErrorIllegalAddress) "cudaEventRecord(sync_event_, corner_stream_)"
[component_container_mt-1] CUDA error at /workspaces/isaac_ros-dev/lib/src/cuapriltags/april_tagging/quad_detection/quad_detector.cpp:35 code=700(cudaErrorIllegalAddress) "cudaStreamWaitEvent(boundary_stream_, sync_event_, 0)"
[component_container_mt-1] CUDA error at /workspaces/isaac_ros-dev/lib/src/cuapriltags/april_tagging/quad_detection/quad_detector.cpp:162 code=700(cudaErrorIllegalAddress) "cudaMemcpy(&corner_cnt, bound_corners_cnt_.Data(), sizeof(uint32_t), cudaMemcpyDefault)"
[component_container_mt-1] 2024-01-21 22:38:13.526 ERROR gxf/std/unbounded_allocator.cpp@99: Failure in cudaFree. cuda_error: cudaErrorIllegalAddress, error_str: an illegal memory access was encountered
[ERROR] [component_container_mt-1]: process has died [pid 4072, exit code -11, cmd '/opt/ros/humble/lib/rclcpp_components/component_container_mt --ros-args -r __node:=apriltag_container -r __ns:=/'].
And if I set data to Image/data as coding msg_image.data = cv_bridge.cv2_to_imgmsg(np.array(cv_image), encoding="rgb8")
, I encounter this error.
uma7@uma7:~$ cd ${ISAAC_ROS_WS}/src/isaac_ros_common && ./scripts/run_dev.sh
admin@uma7:/workspaces/isaac_ros-dev$ python 3d_april.py
An exception occurred.". / The 'data' field must be a set or sequence and each value of type 'int' and each unsigned integer in [0, 255]`