def execute(self, *input_columns) -> bytes: bboxes_list = [] for c in input_columns: bboxes_list += readers.bboxes(c, self._config.protobufs) nmsed_bboxes = bboxes.nms(bboxes_list, self._threshold) return writers.bboxes(nmsed_bboxes, self._config.protobufs)
def compute_exemplar(): img = cv2.imread(exemplar) with Database() as db: bboxes = [db.protobufs.BoundingBox(x1=0, y1=0, x2=img.shape[1], y2=img.shape[0])] kernel = EmbedFaceKernel(None, db.protobufs) [emb] = kernel.execute( [cv2.cvtColor(img, cv2.COLOR_RGB2BGR), writers.bboxes([bboxes], db.protobufs)[0]]) return np.frombuffer(emb, dtype=np.float32)
def bboxes_from_json(config, bboxes: bytes) -> bytes: dilate = config.args['dilate'] if 'dilate' in config.args else 1.0 bboxes = json.loads(bboxes.decode('utf-8')) return writers.bboxes([ config.protobufs.BoundingBox(x1=bb['bbox_x1'] * (2. - dilate), x2=bb['bbox_x2'] * dilate, y1=bb['bbox_y1'] * (2. - dilate), y2=bb['bbox_y2'] * dilate) for bb in bboxes ], config.protobufs)
def execute(self, frame: FrameType) -> bytes: image_tensor = self.graph.get_tensor_by_name('image_tensor:0') boxes = self.graph.get_tensor_by_name('detection_boxes:0') scores = self.graph.get_tensor_by_name('detection_scores:0') classes = self.graph.get_tensor_by_name('detection_classes:0') with self.graph.as_default(): (boxes, scores, classes) = self.sess.run( [boxes, scores, classes], feed_dict={image_tensor: np.expand_dims(frame, axis=0)}) bboxes = [ self.protobufs.BoundingBox(x1=box[1], y1=box[0], x2=box[3], y2=box[2], score=score, label=cls) for (box, score, cls) in zip(boxes.reshape( 100, 4), scores.reshape(100, 1), classes.reshape(100, 1)) ] return writers.bboxes(bboxes, self.protobufs)
def execute(self, *inputs) -> bytes: bboxes_list = [] for c in inputs: bboxes_list += readers.bboxes(c, self.protobufs) nmsed_bboxes = bboxes.nms(bboxes_list, 0.1) return writers.bboxes(nmsed_bboxes, self.protobufs)
def execute(self, frame: Sequence[FrameType], bboxes: Sequence[bytes]) -> Sequence[bytes]: h, w = frame[0].shape[:2] all_new_bbs = [] for fram, bbs in zip(frame, bboxes): bbs = readers.bboxes(bbs, self.protobufs) new_bbs = [] for i, bbox in enumerate(bbs): x1 = int(bbox.x1 * w) y1 = int(bbox.y1 * h) x2 = int(bbox.x2 * w) y2 = int(bbox.y2 * h) ## set crop window crop_w = (x2 - x1) * 2 crop_h = crop_w * 2 X1 = int((x1 + x2) / 2 - crop_w / 2) X2 = X1 + crop_w Y1 = int((y1 + y2) / 2 - crop_h / 3) Y2 = Y1 + crop_h ## adjust box size by image boundary crop_x1 = max(0, X1) crop_x2 = min(w - 1, X2) crop_y1 = max(0, Y1) crop_y2 = min(h - 1, Y2) cropped = fram[crop_y1:crop_y2 + 1, crop_x1:crop_x2 + 1, :] ## compute body bound body_bound = 1.0 for j, other_bbox in enumerate(bbs): if i == j: continue if bbox.y2 < other_bbox.y1: center = (bbox.x1 + bbox.x2) / 2 crop_x1 = (center - bbox.x2 + bbox.x1) crop_x2 = (center + bbox.x2 - bbox.x1) if other_bbox.x1 < crop_x2 or other_bbox.x2 > crop_x1: body_bound = other_bbox.y1 ## detect edge and text neck_line = y2 - crop_y1 body_bound = int(body_bound * h) - crop_y1 crop_y = self.detect_edge_text(cropped, neck_line) crop_y = min(crop_y, body_bound) def inbound(coord, limit): return 0 <= int(coord) and int(coord) < limit # If we produce a malformed bbox then just use the original bbox. if abs(crop_x1 - crop_x2) < 20 or abs(crop_y1 - crop_y) < 20 \ or crop_x1 >= crop_x2 or crop_y1 >= crop_y \ or not inbound(crop_x1, w) or not inbound(crop_x2, w) \ or not inbound(crop_y1, h) or not inbound(crop_y, h): new_bbs.append(bbox) else: new_bbs.append( self.protobufs.BoundingBox(x1=crop_x1 / w, x2=crop_x2 / w, y1=crop_y1 / h, y2=crop_y / h)) all_new_bbs.append(writers.bboxes(new_bbs, self.protobufs)) return all_new_bbs
def execute(self, input_columns): bboxes_list = [] for c in input_columns: bboxes_list += parsers.bboxes(c, self.protobufs) nmsed_bboxes = bboxes.nms(bboxes_list, 0.1) return writers.bboxes([nmsed_bboxes], self.protobufs)