def make_window_boxed_image(img, veh_feats, color=None, show_sec=-1): for veh_idx, veh_feat in enumerate(veh_feats): if veh_feat.win_conf_arr: color = utils.get_color(i=veh_idx, primary_=False) if color is None else color for win_idx, win_pos in enumerate(veh_feat.win_pos_arr): img = utils.draw_quadrilateral_on_image(img, win_pos, color=color, thickness=4) text = "{}: {:2d}".format("Window", veh_feat.win_conf_arr[win_idx]) img = cv2.putText(img, text, (win_pos[0], win_pos[1] - 10), cv2.FONT_HERSHEY_SIMPLEX, 2, color, 4) utils.imshow(img, desc="make window boxed image", pause_sec=show_sec) return img
def process_frame(self, frame_no, in_frame): if frame_no == 1714: a = 0 ret_img = in_frame ret_img = self.draw_text(ret_img, self.frame_no_text_pos, "Frame : {}".format(frame_no), font=self.font_frame) # 기존 plate 검출을 가지고 있다가 점점 박스 두께를 줄이도록 하며, final 검출 이후엔 없애도록 하자! # 그런데, 두개를 동시에 잡았을 땐 어떻게??? plt_info_list = [] if frame_no in self.pd_info_dict: plt_pos_arr, plt_list = self.pd_info_dict[frame_no] for plt_pos in plt_pos_arr: plt_pts = utils.transform_quadrilateral_to_rectangle( plt_pos, algo='max', margin=0) crop_plt_img = ret_img[plt_pts[0][1]:plt_pts[1][1], plt_pts[0][0]:plt_pts[1][0]] plt_info_list.append((plt_pts, crop_plt_img.copy())) ret_img = utils.draw_quadrilateral_on_image(ret_img, self.camera_roi, color=utils.GREEN, clockwise_=False, thickness=4) if len(plt_info_list) > 0: # ROI 선들이 번호판위를 지나갈수 있기 때문에 한번더 그려준다. for plt_info in plt_info_list: pts, crop_plt_img = plt_info ret_img[pts[0][1]:pts[1][1], pts[0][0]:pts[1][0]] = crop_plt_img # 박스를 그리자! ret_img = utils.draw_quadrilateral_on_image(ret_img, plt_pos_arr, color=utils.RED, clockwise_=True, thickness=10) if plt_list is not None: for idx in range(len(plt_pos_arr)): if idx < len(plt_list): plt_num = plt_list[idx]['plt_num'] else: plt_num = "not found" plt_pos = plt_pos_arr[idx] test_box2 = (min(plt_pos[0][0] + 600, ret_img.shape[1]), plt_pos[0][1] - 10) text_box1 = (test_box2[0] - 600, plt_pos[0][1] - (self.font_height + 20)) ret_img = cv2.rectangle(ret_img, text_box1, test_box2, utils.BLACK, -1) ret_img = self.draw_text(ret_img, (text_box1[0], text_box1[1]), plt_num) self.last_plt_list = (plt_info_list, plt_list) if self.last_plt_list: plt_info_list, plt_list = self.last_plt_list box_l = self.last_box_tl[0] box_r = self.last_box_br[0] text_pos_x = self.last_text_pos[0] for idx in range(len(plt_info_list)): if idx < len(plt_list): if self.is_paint_black_box: ret_img = cv2.rectangle(ret_img, (box_l, self.last_box_tl[1]), (box_r, self.last_box_br[1]), utils.BLACK, -1) plt_num = plt_list[idx]['plt_num'] plt_url = plt_list[idx]['plt_uri'] ret_img = self.draw_text( ret_img, (text_pos_x, self.last_text_pos[1]), plt_num) plt_img = utils.imread(plt_url) if plt_img is not None: plt_img = utils.imresize(plt_img, height=self.plt_height) plt_height = plt_img.shape[0] plt_width = plt_img.shape[1] ret_img[self.last_plt_pos_y:self.last_plt_pos_y + plt_height, text_pos_x:text_pos_x + plt_width] = plt_img box_l += 700 box_r += 700 text_pos_x += 700 return ret_img