From 9686f7579a9de9f1bcd8c7469b983205370356d4 Mon Sep 17 00:00:00 2001 From: Jiandong Chen <jiandong.chen@rwth-aachen.de> Date: Fri, 20 Oct 2023 19:10:31 +0200 Subject: [PATCH] add postprocess infrared images --- dataset_converter/pohang.py | 49 ++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/dataset_converter/pohang.py b/dataset_converter/pohang.py index 6b7e227..df98fdd 100644 --- a/dataset_converter/pohang.py +++ b/dataset_converter/pohang.py @@ -2,6 +2,7 @@ import rospy import rosbag import cv2 import cv_bridge +import numpy as np import dataset_converter.util as util from pathlib import Path from sensor_msgs.msg import Imu @@ -45,6 +46,10 @@ STEREO_FOLDER = {"left_images", "right_images", "timestamp.txt"} INFRARED_FOLDER = {"images", "timestamp.txt"} OMNI_FOLDER = {"cam_0", "cam_1", "cam_2", "cam_3", "cam_4", "cam_5", "timestamp.txt"} +# Other setup +MIN_INFRARED_TEMPERTURE = 20 +MAX_INFRARED_TEMPERTURE = 50 + def is_datafolder_valid(folder: Path): print(f"Checking Folder: {folder}") @@ -74,7 +79,12 @@ def is_datafolder_valid(folder: Path): def process_images( - data_path: Path, rosbag_path: Path, topic: str, frame_id: str, dst_fmt=None + data_path: Path, + rosbag_path: Path, + topic: str, + frame_id: str, + dst_fmt=None, + is_infrared=False, ): # read the images path and sort based on file name images = util.get_sorted_file_list(data_path) @@ -93,9 +103,9 @@ def process_images( # store all images into bag bridge = cv_bridge.CvBridge() + postprocess_func = np.vectorize(postprocess_infrared) bagmode = check_bag_mode(rosbag_path) - with rosbag.Bag(rosbag_path, bagmode) as bag: for img_path, time_list in zip(images, timestamps): t = rospy.Time.from_sec(float(time_list[0])) @@ -110,7 +120,13 @@ def process_images( ) break - img = cv2.imread(img_path.as_posix()) + if is_infrared: + img = cv2.imread(img_path.as_posix(), -1) + img = postprocess_func(img) + img = img.astype(np.uint8) + else: + img = cv2.imread(img_path.as_posix()) + msg = bridge.cv2_to_compressed_imgmsg( img, dst_format=dst_fmt if dst_fmt is not None else "jpg" ) @@ -177,6 +193,7 @@ def process_navigation(data_folder: Path, rosbag_path: Path): print("Baseline Done!") + def process_stereo(data_folder: Path, rosbag_path: Path): data_path = data_folder.joinpath("stereo") for k, v in STEREO_PROCESS.items(): @@ -188,7 +205,16 @@ def process_stereo(data_folder: Path, rosbag_path: Path): def process_infrared(data_folder: Path, rosbag_path: Path): data_path = data_folder.joinpath("infrared") for k, v in INFRARED_PROCESS.items(): - process_images(data_path / k, rosbag_path, v[1], v[0], "png") + process_images(data_path / k, rosbag_path, v[1], v[0], "png", is_infrared=True) + + # raw data + process_images( + data_path / "images", + rosbag_path, + "/infrared/raw/image/compressed", + INFRARED_PROCESS["images"][0], + "png", + ) print("Infrared Done!") @@ -221,3 +247,18 @@ def check_bag_mode(rosbag_path: Path): bagmode = "w" return bagmode + + +def postprocess_infrared(data): + # computer temperture + temp = data * 0.04 - 273.15 + if temp <= MIN_INFRARED_TEMPERTURE: + return 0 + elif temp >= MAX_INFRARED_TEMPERTURE: + return 255 # 2^8 - 1 + else: + return int( + (temp - MIN_INFRARED_TEMPERTURE) + / (MAX_INFRARED_TEMPERTURE - MIN_INFRARED_TEMPERTURE) + * 255 + ) -- GitLab