-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_parser1.py
More file actions
33 lines (23 loc) · 913 Bytes
/
image_parser1.py
File metadata and controls
33 lines (23 loc) · 913 Bytes
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import rospy
import cv2
import numpy as np
import os, rospkg
from sensor_msgs.msg import CompressedImage
from cv_bridge import CvBridgeError
class IMGParser:
def __init__(self):
self.image_sub = rospy.Subscriber("/image_jpeg/compressed", CompressedImage, self.callback)
def callback(self, msg):
try:
np_arr = np.fromstring(msg.data, np.uint8)
img_bgr = cv2.imdecode(np_arr, cv2.IMREAD_COLOR) #np.fromstring으로 바이트를 uint8 array로 변환
except CvBridgeError as e: #다시 세로, 가로, 채널 의 이미지를 array로 변환
print(e)
cv2.imshow("Image window", img_bgr)
cv2.waitKey(1) #토픽에서 받은 이미지를 띄운다.
if __name__ == '__main__':
rospy.init_node('image_parser', anonymous=True)
image_parser = IMGParser()
rospy.spin()