8 from sensor_msgs.msg
import CompressedImage
9 from raspicam_node.msg
import MotionVectors
10 from cv_bridge
import CvBridge, CvBridgeError
20 size = ( num_elements, 1, 1 )
21 im = np.zeros(size, dtype=np.uint8)
23 for i
in range(0, num_elements):
26 return cv2.applyColorMap(im, cv2.COLORMAP_JET)
29 height, width, channels = img.shape
30 mbx = int(math.ceil(width/16.0))
31 mby = int(math.ceil(height/16.0))
34 for j
in range(0, imv.mby):
35 for i
in range(0, imv.mbx):
36 idx = (i + (imv.mbx + 1) * j)
44 if dx == 0
and dy == 0:
47 if sad >= SAD_THRESHOLD:
50 color = ( int(color_map[sad,0,0]),
51 int(color_map[sad,0,1]),
52 int(color_map[sad,0,2]) )
53 cv2.arrowedLine(img, (x+dx, y+dy), (x, y), color, 1)
57 img = bridge.compressed_imgmsg_to_cv2(msg,
'bgr8')
58 except CvBridgeError
as e:
61 if last_imv
is not None:
63 cv2.imshow(
'raspicam_node motion vectors visualization', img)
74 img_topic =
'/raspicam_node/image/compressed' 75 imv_topic =
'/raspicam_node/motion_vectors' 77 rospy.init_node(
'imv_view')
78 rospy.Subscriber(img_topic, CompressedImage, img_callback)
79 rospy.Subscriber(imv_topic, MotionVectors, imv_callback)
82 if __name__ ==
'__main__':
def create_colormap(num_elements)