def learn_person(self, name='operator'): HEIGHT_TRESHOLD = 88 WIDTH_TRESHOLD = 88 try: image = self.get_image() except: rospy.logerr("Cannot get image") return False raw_recognitions = self._get_faces(image).recognitions recognitions = [ r for r in raw_recognitions if r.roi.height > HEIGHT_TRESHOLD and r.roi.width > WIDTH_TRESHOLD ] rospy.loginfo('found %d valid face(s)', len(recognitions)) if len(recognitions) != 1: rospy.loginfo("Too many faces: {}".format(len(recognitions))) return False recognition = recognitions[0] rospy.loginfo('annotating that face as %s', name) try: self._annotate_srv( image=image, annotations=[Annotation(label=name, roi=recognition.roi)]) except rospy.ServiceException as e: rospy.logerr('annotate failed: {}'.format(e)) return False return True
def learn_person(self, image, name='operator'): # HEIGHT_TRESHOLD = 88 # WIDTH_TRESHOLD = 88 try: recognitions = self._recognize_srv(image=image).recognitions except rospy.ServiceException as e: rospy.logerr('annotate failed: {}'.format(e)) return False # raw_recognitions = self._recognize_srv(image=image).recognitions # recognitions = [r for r in raw_recognitions if r.roi.height > HEIGHT_TRESHOLD and r.roi.width > WIDTH_TRESHOLD] rospy.loginfo('found %d valid face(s)', len(recognitions)) if len(recognitions) != 1: rospy.loginfo("Too many faces: {}".format(len(recognitions))) # return False if not recognitions: return False recognition = filter_on_area(recognitions) rospy.loginfo(recognition) rospy.loginfo('annotating that face as %s', name) try: self._annotate_srv( image=image, annotations=[Annotation(label=name, roi=recognition.roi)]) except rospy.ServiceException as e: rospy.logerr('annotate failed: {}'.format(e)) return False return True
def annotate_srv(self, roi_image): """ Call the selected Annotate.srv :param roi_image: The full opencv image we want to annotate """ if roi_image is not None and self.label is not None and self._srv is not None: height, width = roi_image.shape[:2] try: self._srv(image=self.bridge.cv2_to_imgmsg(roi_image, "bgr8"), annotations=[ Annotation(label=self.label, roi=RegionOfInterest(x_offset=0, y_offset=0, width=width, height=height)) ]) except Exception as e: warning_dialog("Service Exception", str(e))
def learn_face(self, roi_image): if self.label == "nobody": return self.tresh = 50 print("try to learn") if roi_image is not None and self.an_srv is not None: height = roi_image.height width = roi_image.width try: self.an_srv(image=roi_image, annotations=[ Annotation(label=self.label, roi=RegionOfInterest(x_offset=0, y_offset=0, width=width, height=height)) ]) except Exception as e: print(e)