Welcome to Jetson Orin NX Developer Kit repository
当製品の日本語版マニュアル資料は、こちらからご取得ください。
01.Camera preview (USB)
Camera preview (USB)
Camera preview (USB)1. Build the function package2. Start the camera3. Preview the image4. Main code
1. Build the function package
xxxxxxxxxxcd ~/yahboom_ws
xxxxxxxxxxcolcon build
xxxxxxxxxxsource install/setup.bash

2. Start the camera
Start the camera
xxxxxxxxxxros2 run camera camera_usb
View the nodes and topics
xxxxxxxxxxros2 node list
xxxxxxxxxxros2 topic list

3. Preview the image
Use rqt to view the image topic corresponding to the camera: rqt → Plugins → Visualization → Image View
xxxxxxxxxxrqt


4. Main code
ximport rclpyfrom rclpy.node import Nodefrom sensor_msgs.msg import Imagefrom cv_bridge import CvBridgeimport cv2class CameraNode(Node):def __init__(self):super().__init__('camera_usb')self.publisher = self.create_publisher(Image, 'image_raw', 10)self.bridge = CvBridge()self.cap = cv2.VideoCapture(0)if not self.cap.isOpened():self.get_logger().error('Unable to open camera')returnself.timer = self.create_timer(0.05, self.timer_callback)def timer_callback(self):ret, frame = self.cap.read()if ret:image_msg = self.bridge.cv2_to_imgmsg(frame, encoding="bgr8")self.publisher.publish(image_msg)else:self.get_logger().warn('Failed to capture image')def main(args=None):rclpy.init(args=args)node = CameraNode()rclpy.spin(node)node.cap.release()rclpy.shutdown()if __name__ == '__main__':main()