-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_subscriber.py
35 lines (30 loc) · 1.04 KB
/
image_subscriber.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
#Checkout http://wiki.ros.org/cv_bridge/Tutorials
import sys
import cv2
import rospy
import numpy as np
from cv_bridge import CvBridge
from sensor_msgs.msg import Image
bridge = CvBridge()
def callback_Img(data):
img = bridge.imgmsg_to_cv2(data, desired_encoding='rgb8')
# Start coordinate, here (5, 5)
# represents the top left corner of rectangle
start_point = (5, 5)
# Ending coordinate, here (220, 220)
# represents the bottom right corner of rectangle
end_point = (220, 220)
# Blue color in BGR
color = (255, 0, 0)
# Line thickness of 2 px
thickness = 2
img = cv2.rectangle(img, start_point, end_point, color, thickness)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
grayImageMsg = CvBridge().cv2_to_imgmsg(gray.astype(np.uint8))
grayImageMsg.header = data.header
grayImageMsg.encoding = '8UC1'
grayImgPub.publish(grayImageMsg)
rospy.init_node('img_record_node')
rospy.Subscriber("/front_camera/image_raw", Image, callback_Img)
grayImgPub = rospy.Publisher('/img_gray', Image, queue_size=10)
rospy.spin()