def process_file(self, filename_in, filename_out,draw_spline=True): if not os.path.isfile(filename_in): return [] image = cv2.imread(filename_in) image = tools_image.rgb2bgr(image) if image is None: return [] if draw_spline==False: boxes_yxyx, scores, classes = self.process_image(image) markup = tools_YOLO.get_markup(filename_in, boxes_yxyx, scores, classes) tools_YOLO.draw_and_save(filename_out, image, boxes_yxyx, scores, classes,self.colors, self.class_names) else: r = self.model.detect([image], verbose=0)[0] boxes_yxyx, scores, classes,masks = r['rois'], r['scores'], r['class_ids'],r['masks'] class_ID = tools_IO.smart_index(self.class_names,'person')[0] msk = (scores > self.obj_threshold).tolist() #msk = msk and (classes == class_ID) msk = numpy.array(msk) boxes_yxyx, scores, classes, masks = boxes_yxyx[msk], scores[msk], classes[msk], masks[:,:,msk] markup = tools_YOLO.get_markup(filename_in, boxes_yxyx, scores, classes) detector_Mask_RCNN_core.display_instances(tools_image.desaturate(image), boxes_yxyx, masks, classes, self.class_names,filename_out,scores,self.colors) return markup
def process_file(self, filename_in, filename_out): if not os.path.isfile(filename_in): return [] image = cv2.imread(filename_in) if image is None: return [] boxes_yxyx, classes, scores = self.process_image(image) tools_YOLO.draw_and_save(filename_out, image, boxes_yxyx, scores, classes, self.colors, self.class_names) markup = tools_YOLO.get_markup(filename_in, boxes_yxyx, scores, classes) return markup
def process_folder_negatives(self, path_input, path_out, list_of_masks='*.png,*.jpg', limit=1000000, confidence=0.80): tools_IO.remove_files(path_out) local_filenames = tools_IO.get_filenames(path_input, list_of_masks)[:limit] local_filenames = numpy.sort(local_filenames) for local_filename in local_filenames: image = cv2.imread(path_input + local_filename) if image is None: return [] boxes_yxyx, classes, scores = self.process_image(image) if len(scores) > 0 and scores[0] >= confidence: filename_out = path_out + '%02d_' % int( 100 * scores[0]) + local_filename tools_YOLO.draw_and_save(filename_out, image, boxes_yxyx, scores, classes, self.colors, self.class_names) return
def draw_and_save(filename_out, image, boxes_yxyx, scores, classes, colors, class_names): return tools_YOLO.draw_and_save(filename_out, image, boxes_yxyx, scores, classes, colors, class_names)