Skip to content

Commit

Permalink
add visualized code for det results
Browse files Browse the repository at this point in the history
  • Loading branch information
LDOUBLEV committed May 15, 2020
1 parent 5c043e5 commit 1e9683b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 7 additions & 3 deletions tools/infer/predict_det.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ def __call__(self, img):
return dt_boxes, elapse


from tools.infer.utility import draw_text_det_res

if __name__ == "__main__":
args = utility.parse_args()
image_file_list = get_image_file_list(args.image_dir)
Expand All @@ -169,7 +171,9 @@ def __call__(self, img):
total_time += elapse
count += 1
print("Predict time of %s:" % image_file, elapse)
"""
add visualized code
"""
img_draw = draw_text_det_res(dt_boxes, image_file, return_img=True)
save_path = os.path.join("./inference_det/",
os.path.basename(image_file))
print("The visualized image saved in {}".format(save_path))

print("Avg Time:", total_time / (count - 1))
5 changes: 2 additions & 3 deletions tools/infer/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,12 @@ def create_predictor(args, mode):
return predictor, input_tensor, output_tensors


def draw_text_det_res(dt_boxes, img_path):
def draw_text_det_res(dt_boxes, img_path, return_img=True):
src_im = cv2.imread(img_path)
for box in dt_boxes:
box = np.array(box).astype(np.int32).reshape(-1, 2)
cv2.polylines(src_im, [box], True, color=(255, 255, 0), thickness=2)
img_name_pure = img_path.split("/")[-1]
cv2.imwrite("./output/%s" % img_name_pure, src_im)
return src_im


def resize_img(img, input_size=600):
Expand Down

0 comments on commit 1e9683b

Please sign in to comment.