-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextract_image.py
37 lines (31 loc) · 1.23 KB
/
extract_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import subprocess
import yaml
import rosbag
import cv2
from cv_bridge import CvBridge
import numpy as np
FILENAME = '_2022-08-19-16-51-16'
ROOT_DIR = '/home/ducanh/ducanh_ws/bag_record/fly_bag'
BAGFILE = ROOT_DIR + '/' + FILENAME + '.bag'
if __name__ == '__main__':
bag = rosbag.Bag(BAGFILE)
for i in range(2):
if (i == 0):
TOPIC = '/camera/depth/image_rect_raw'
DESCRIPTION = 'depth_'
else:
TOPIC = '/camera/color/image_raw'
DESCRIPTION = 'color_'
image_topic = bag.read_messages(TOPIC)
for k, b in enumerate(image_topic):
bridge = CvBridge()
cv_image = bridge.imgmsg_to_cv2(b.message, b.message.encoding)
cv_image.astype(np.uint8)
if (DESCRIPTION == 'depth_'):
depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(cv_image, alpha=0.03), cv2.COLORMAP_JET)
cv2.imwrite(ROOT_DIR + '/depth/' + DESCRIPTION + str(b.timestamp) + '.png', cv_image)
else:
cv2.imwrite(ROOT_DIR + '/color/' + DESCRIPTION + str(b.timestamp) + '.png', cv_image)
print('saved: ' + DESCRIPTION + str(b.timestamp) + '.png')
bag.close()
print('PROCESS COMPLETE')