def updateImage(self, img):
arr = self.bridge.imgmsg_to_cv2(img,"bgr8")
# Uncomment following two lines for CompressedImage topic
#np_arr = np.fromstring(img.data, np.uint8)
#arr = cv2.imdecode(np_arr, cv2.IMREAD_COLOR)
if self.image_lock.acquire(True):
self.img = arr
if self.model is None:
self.model = self.get_model()
self.img_out, self.boxes = self.predict(self.model, self.img)
self.img_out = np.asarray(self.img_out[0,:,:,:])
for box in self.boxes:
if 'traffic light' in box['label']:
cv2.rectangle(self.img_out,(box['topleft']['x'],
box['topleft']['y']),
(box['bottomright']['x'],
box['bottomright']['y']),
(255,0,0), 6)
cv2.putText(self.img_out, box['label'],
(box['topleft']['x'],
box['topleft']['y'] - 12), 0, 0.6, (255,0,0) ,6//3)
print(self.img_out.shape)
self.image_lock.release()
评论列表
文章目录