|
24 | 24 | parser.add_argument('--top_k', default=5000, type=int, help='top_k') |
25 | 25 | parser.add_argument('--nms_threshold', default=0.3, type=float, help='nms_threshold') |
26 | 26 | parser.add_argument('--keep_top_k', default=750, type=int, help='keep_top_k') |
| 27 | +parser.add_argument('-s', '--show_image', action="store_true", default=False, help='show detection results') |
| 28 | +parser.add_argument('--vis_thres', default=0.5, type=float, help='visualization_threshold') |
27 | 29 | args = parser.parse_args() |
28 | 30 |
|
29 | 31 |
|
@@ -101,7 +103,8 @@ def load_model(model, pretrained_path, load_to_cpu): |
101 | 103 | # testing begin |
102 | 104 | for i, img_name in enumerate(test_dataset): |
103 | 105 | image_path = testset_folder + img_name + '.jpg' |
104 | | - img = np.float32(cv2.imread(image_path, cv2.IMREAD_COLOR)) |
| 106 | + img_raw = cv2.imread(image_path, cv2.IMREAD_COLOR) |
| 107 | + img = np.float32(img_raw) |
105 | 108 | if resize != 1: |
106 | 109 | img = cv2.resize(img, None, None, fx=resize, fy=resize, interpolation=cv2.INTER_LINEAR) |
107 | 110 | im_height, im_width, _ = img.shape |
@@ -168,4 +171,20 @@ def load_model(model, pretrained_path, load_to_cpu): |
168 | 171 | score = dets[k, 4] |
169 | 172 | fw.write('{:s} {:.3f} {:.1f} {:.1f} {:.1f} {:.1f}\n'.format(img_name, score, xmin, ymin, xmax, ymax)) |
170 | 173 | print('im_detect: {:d}/{:d} forward_pass_time: {:.4f}s misc: {:.4f}s'.format(i + 1, num_images, _t['forward_pass'].average_time, _t['misc'].average_time)) |
| 174 | + |
| 175 | + # show image |
| 176 | + if args.show_image: |
| 177 | + for b in dets: |
| 178 | + if b[4] < args.vis_thres: |
| 179 | + continue |
| 180 | + text = "{:.4f}".format(b[4]) |
| 181 | + b = list(map(int, b)) |
| 182 | + cv2.rectangle(img_raw, (b[0], b[1]), (b[2], b[3]), (0, 0, 255), 2) |
| 183 | + cx = b[0] |
| 184 | + cy = b[1] + 12 |
| 185 | + cv2.putText(img_raw, text, (cx, cy), |
| 186 | + cv2.FONT_HERSHEY_DUPLEX, 0.5, (255, 255, 255)) |
| 187 | + cv2.imshow('res', img_raw) |
| 188 | + cv2.waitKey(0) |
| 189 | + |
171 | 190 | fw.close() |
0 commit comments