|
| 1 | +# ROS Headers |
| 2 | +import rospy |
| 3 | +from sensor_msgs.msg import Image,PointCloud2 |
| 4 | +import sensor_msgs.point_cloud2 as pc2 |
| 5 | +import ctypes |
| 6 | +import struct |
| 7 | +import argparse |
| 8 | + |
| 9 | + |
| 10 | +# OpenCV and cv2 bridge |
| 11 | +import cv2 |
| 12 | +from cv_bridge import CvBridge |
| 13 | +import numpy as np |
| 14 | +import os |
| 15 | +import time |
| 16 | + |
| 17 | +lidar_points = None |
| 18 | +camera_image = None |
| 19 | +depth = None |
| 20 | +camera_right_img = None |
| 21 | +bridge = CvBridge() |
| 22 | + |
| 23 | +def camera_left_callback(img : Image): |
| 24 | + global camera_image |
| 25 | + camera_image = img |
| 26 | + |
| 27 | +def camera_right_callback(img : Image): |
| 28 | + global camera_right_img |
| 29 | + camera_right_img = img |
| 30 | + |
| 31 | +def save_scan(left,right): |
| 32 | + cv2.imwrite(left,bridge.imgmsg_to_cv2(camera_image)) |
| 33 | + cv2.imwrite(right,bridge.imgmsg_to_cv2(camera_right_img)) |
| 34 | + |
| 35 | + |
| 36 | +def main(folder='data',start_index=1, frequency=2): |
| 37 | + rospy.init_node("capture_triton_l_r",disable_signals=True) |
| 38 | + camera_sub_left = rospy.Subscriber("/camera_fl/arena_camera_node/image_raw", Image, camera_left_callback) |
| 39 | + camera_sub_right = rospy.Subscriber("/camera_fr/arena_camera_node/image_raw", Image, camera_right_callback) |
| 40 | + index = start_index |
| 41 | + print(" Storing images as png") |
| 42 | + print(" Ctrl+C to quit") |
| 43 | + while True: |
| 44 | + if camera_image and camera_right_img: |
| 45 | + cv2.imshow("result",bridge.imgmsg_to_cv2(camera_image)) |
| 46 | + time.sleep(1.0/frequency) |
| 47 | + files = [ |
| 48 | + os.path.join(folder,'left{}.png'.format(index)), |
| 49 | + os.path.join(folder,'right{}.png'.format(index))] |
| 50 | + save_scan(*files) |
| 51 | + index += 1 |
| 52 | + |
| 53 | +if __name__ == '__main__': |
| 54 | + import sys |
| 55 | + parser = argparse.ArgumentParser(description='Capture LiDAR and camera data.') |
| 56 | + parser.add_argument('--folder', type=str, default='data', help='Directory to store data') |
| 57 | + parser.add_argument('--start_index', type=int, default=1, help='Starting index for saved files') |
| 58 | + parser.add_argument('--frequency', type=float, default=2.0, help='Capture frequency in Hz') |
| 59 | + args = parser.parse_args() |
| 60 | + main(args.folder, args.start_index, args.frequency) |
0 commit comments