def _draw_tips(self, image, tips): """Take an Image message and a Tips message, draw a boc around the tips in the image and publish the result. Record *image*'s sequence number in _last_published_seq. """ # Convert image into RGB image rgb_im = image_to_array(image) # Use OpenCV to draw boxes in image for tip in tips.tips: roi = tip.roi # NB: cv2.circle will modify the image it works on. if (roi.x_offset, roi.y_offset) != (0, 0): cv2.circle( rgb_im, (roi.x_offset, roi.y_offset), 5, (0, 255, 0), # green 2 # thickness ) # Publish image self._image_pub.publish(array_to_image(rgb_im)) self._last_published_seq = image.header.seq
def _detect_tips_callback(self, event): """Called periodically to detect tips in an image and publish the result. """ # Get the latest image to arrive image = self._latest_image # Don't do anything if there is no latest image if image is None: return # "Claim" this image by clearing _latest_image self._latest_image = None # Create the tip message we will eventually publish tips_msg = Tips() # Copy the header from the input image so we know when and what these # tip detection results relate to. tips_msg.header = image.header # Parse image message into numpy array image_array = image_to_array(image) imageArray = reduce_size(image_array,'rgb',2); #imageArray = reduce_size(imageArray,'rgb',2); #imageArray = reduce_size(imageArray,'rgb',2); # Detect tips detect_tip = TipDetector tips = detect_tip(imageArray) # Create a tip bounding box for each tip #for tip_idx, tip_bbox in enumerate(tips): # rospy.logdebug('Tip #%s at %s', tip_idx+1, tip_bbox) # Create tip message tip_msg = Tip() tip_msg.header = tips_msg.header # Initialise roi if tips != (0,0): tip_msg.roi.x_offset = tips[0] tip_msg.roi.y_offset = tips[1] tip_msg.roi.do_rectify = False # Append to list of tips tips_msg.tips.append(tip_msg) # Publish tips messages self._tips_pub.publish(tips_msg) rospy.logdebug('Coordinates of tip: %s', tips)
def _detect_tips_callback(self, event): """Called periodically to detect tips in an image and publish the result. """ # Get the latest image to arrive image = self._latest_image # Don't do anything if there is no latest image if image is None: return # "Claim" this image by clearing _latest_image self._latest_image = None # Create the tip message we will eventually publish tips_msg = Tips() # Copy the header from the input image so we know when and what these # tip detection results relate to. tips_msg.header = image.header # Parse image message into numpy array image_array = image_to_array(image) imageArray = reduce_size(image_array, 'rgb', 2) #imageArray = reduce_size(imageArray,'rgb',2); #imageArray = reduce_size(imageArray,'rgb',2); # Detect tips detect_tip = TipDetector tips = detect_tip(imageArray) # Create a tip bounding box for each tip #for tip_idx, tip_bbox in enumerate(tips): # rospy.logdebug('Tip #%s at %s', tip_idx+1, tip_bbox) # Create tip message tip_msg = Tip() tip_msg.header = tips_msg.header # Initialise roi if tips != (0, 0): tip_msg.roi.x_offset = tips[0] tip_msg.roi.y_offset = tips[1] tip_msg.roi.do_rectify = False # Append to list of tips tips_msg.tips.append(tip_msg) # Publish tips messages self._tips_pub.publish(tips_msg) rospy.logdebug('Coordinates of tip: %s', tips)
def _draw_tips(self, image, tips): """Take an Image message and a Tips message, draw a boc around the tips in the image and publish the result. Record *image*'s sequence number in _last_published_seq. """ # Convert image into RGB image rgb_im = image_to_array(image) # Use OpenCV to draw boxes in image for tip in tips.tips: roi = tip.roi # NB: cv2.circle will modify the image it works on. if (roi.x_offset, roi.y_offset) != (0, 0): cv2.circle(rgb_im, (roi.x_offset, roi.y_offset), 5, (0, 255, 0), 2) # green # thickness # Publish image self._image_pub.publish(array_to_image(rgb_im)) self._last_published_seq = image.header.seq