未验证 提交 e0a8d481 编写于 作者: W wangguanzhong 提交者: GitHub

refine pphuman vis (#5426)

上级 22736876
...@@ -521,13 +521,16 @@ class PipePredictor(object): ...@@ -521,13 +521,16 @@ class PipePredictor(object):
mot_res = result.get('mot') mot_res = result.get('mot')
if mot_res is not None: if mot_res is not None:
ids = mot_res['boxes'][:, 0] ids = mot_res['boxes'][:, 0]
scores = mot_res['boxes'][:, 2]
boxes = mot_res['boxes'][:, 3:] boxes = mot_res['boxes'][:, 3:]
boxes[:, 2] = boxes[:, 2] - boxes[:, 0] boxes[:, 2] = boxes[:, 2] - boxes[:, 0]
boxes[:, 3] = boxes[:, 3] - boxes[:, 1] boxes[:, 3] = boxes[:, 3] - boxes[:, 1]
else: else:
boxes = np.zeros([0, 4]) boxes = np.zeros([0, 4])
ids = np.zeros([0]) ids = np.zeros([0])
image = plot_tracking(image, boxes, ids, frame_id=frame_id, fps=fps) scores = np.zeros([0])
image = plot_tracking(
image, boxes, ids, scores, frame_id=frame_id, fps=fps)
attr_res = result.get('attr') attr_res = result.get('attr')
if attr_res is not None: if attr_res is not None:
......
...@@ -134,47 +134,45 @@ def plot_tracking(image, ...@@ -134,47 +134,45 @@ def plot_tracking(image,
im = np.ascontiguousarray(np.copy(image)) im = np.ascontiguousarray(np.copy(image))
im_h, im_w = im.shape[:2] im_h, im_w = im.shape[:2]
text_scale = max(1, image.shape[1] / 1600.) text_scale = max(0.5, image.shape[1] / 3000.)
text_thickness = 2 text_thickness = 2
line_thickness = max(1, int(image.shape[1] / 500.)) line_thickness = max(1, int(image.shape[1] / 500.))
cv2.putText( cv2.putText(
im, im,
'frame: %d fps: %.2f num: %d' % (frame_id, fps, len(tlwhs)), 'frame: %d fps: %.2f num: %d' % (frame_id, fps, len(tlwhs)),
(0, int(15 * text_scale)), (0, int(15 * text_scale) + 5),
cv2.FONT_HERSHEY_PLAIN, cv2.FONT_ITALIC,
text_scale, (0, 0, 255), text_scale, (0, 0, 255),
thickness=2) thickness=text_thickness)
for i, tlwh in enumerate(tlwhs): for i, tlwh in enumerate(tlwhs):
x1, y1, w, h = tlwh x1, y1, w, h = tlwh
intbox = tuple(map(int, (x1, y1, x1 + w, y1 + h))) intbox = tuple(map(int, (x1, y1, x1 + w, y1 + h)))
obj_id = int(obj_ids[i]) obj_id = int(obj_ids[i])
id_text = '{}'.format(int(obj_id)) id_text = 'ID: {}'.format(int(obj_id))
if ids2names != []: if ids2names != []:
assert len( assert len(
ids2names) == 1, "plot_tracking only supports single classes." ids2names) == 1, "plot_tracking only supports single classes."
id_text = '{}_'.format(ids2names[0]) + id_text id_text = 'ID: {}_'.format(ids2names[0]) + id_text
_line_thickness = 1 if obj_id <= 0 else line_thickness _line_thickness = 1 if obj_id <= 0 else line_thickness
color = get_color(abs(obj_id)) color = get_color(abs(obj_id))
cv2.rectangle( cv2.rectangle(
im, intbox[0:2], intbox[2:4], color=color, thickness=line_thickness) im, intbox[0:2], intbox[2:4], color=color, thickness=line_thickness)
cv2.putText( cv2.putText(
im, im,
id_text, (intbox[0], intbox[1] - 10), id_text, (intbox[0], intbox[1] - 25),
cv2.FONT_HERSHEY_PLAIN, cv2.FONT_ITALIC,
text_scale, (0, 0, 255), text_scale, (0, 255, 255),
thickness=text_thickness) thickness=text_thickness)
if scores is not None: if scores is not None:
text = '{:.2f}'.format(float(scores[i])) text = 'score: {:.2f}'.format(float(scores[i]))
cv2.putText( cv2.putText(
im, im,
text, (intbox[0], intbox[1] + 10), text, (intbox[0], intbox[1] - 6),
cv2.FONT_HERSHEY_PLAIN, cv2.FONT_ITALIC,
text_scale, (0, 255, 255), text_scale, (0, 255, 0),
thickness=text_thickness) thickness=text_thickness)
if do_entrance_counting: if do_entrance_counting:
entrance_line = tuple(map(int, entrance)) entrance_line = tuple(map(int, entrance))
cv2.rectangle( cv2.rectangle(
...@@ -201,7 +199,7 @@ def plot_tracking_dict(image, ...@@ -201,7 +199,7 @@ def plot_tracking_dict(image,
im = np.ascontiguousarray(np.copy(image)) im = np.ascontiguousarray(np.copy(image))
im_h, im_w = im.shape[:2] im_h, im_w = im.shape[:2]
text_scale = max(1, image.shape[1] / 1600.) text_scale = max(0.5, image.shape[1] / 3000.)
text_thickness = 2 text_thickness = 2
line_thickness = max(1, int(image.shape[1] / 500.)) line_thickness = max(1, int(image.shape[1] / 500.))
...@@ -212,9 +210,9 @@ def plot_tracking_dict(image, ...@@ -212,9 +210,9 @@ def plot_tracking_dict(image,
cv2.putText( cv2.putText(
im, im,
records[-1][start:end], (0, int(40 * text_scale)), records[-1][start:end], (0, int(40 * text_scale)),
cv2.FONT_HERSHEY_PLAIN, cv2.FONT_ITALIC,
text_scale, (0, 0, 255), text_scale, (0, 0, 255),
thickness=2) thickness=text_thickness)
if num_classes == 1 and do_entrance_counting: if num_classes == 1 and do_entrance_counting:
entrance_line = tuple(map(int, entrance)) entrance_line = tuple(map(int, entrance))
...@@ -229,9 +227,9 @@ def plot_tracking_dict(image, ...@@ -229,9 +227,9 @@ def plot_tracking_dict(image,
cv2.putText( cv2.putText(
im, im,
records[-1][start:-1], (0, int(60 * text_scale)), records[-1][start:-1], (0, int(60 * text_scale)),
cv2.FONT_HERSHEY_PLAIN, cv2.FONT_ITALIC,
text_scale, (0, 0, 255), text_scale, (0, 0, 255),
thickness=2) thickness=text_thickness)
for cls_id in range(num_classes): for cls_id in range(num_classes):
tlwhs = tlwhs_dict[cls_id] tlwhs = tlwhs_dict[cls_id]
...@@ -240,10 +238,10 @@ def plot_tracking_dict(image, ...@@ -240,10 +238,10 @@ def plot_tracking_dict(image,
cv2.putText( cv2.putText(
im, im,
'frame: %d fps: %.2f num: %d' % (frame_id, fps, len(tlwhs)), 'frame: %d fps: %.2f num: %d' % (frame_id, fps, len(tlwhs)),
(0, int(15 * text_scale)), (0, int(15 * text_scale) + 5),
cv2.FONT_HERSHEY_PLAIN, cv2.FONT_ITALIC,
text_scale, (0, 0, 255), text_scale, (0, 0, 255),
thickness=2) thickness=text_thickness)
record_id = set() record_id = set()
for i, tlwh in enumerate(tlwhs): for i, tlwh in enumerate(tlwhs):
...@@ -273,18 +271,18 @@ def plot_tracking_dict(image, ...@@ -273,18 +271,18 @@ def plot_tracking_dict(image,
thickness=line_thickness) thickness=line_thickness)
cv2.putText( cv2.putText(
im, im,
id_text, (intbox[0], intbox[1] - 10), id_text, (intbox[0], intbox[1] - 25),
cv2.FONT_HERSHEY_PLAIN, cv2.FONT_ITALIC,
text_scale, (0, 0, 255), text_scale, (0, 255, 255),
thickness=text_thickness) thickness=text_thickness)
if scores is not None: if scores is not None:
text = '{:.2f}'.format(float(scores[i])) text = 'score: {:.2f}'.format(float(scores[i]))
cv2.putText( cv2.putText(
im, im,
text, (intbox[0], intbox[1] + 10), text, (intbox[0], intbox[1] - 6),
cv2.FONT_HERSHEY_PLAIN, cv2.FONT_ITALIC,
text_scale, (0, 255, 255), text_scale, (0, 255, 0),
thickness=text_thickness) thickness=text_thickness)
if center_traj is not None: if center_traj is not None:
for traj in center_traj: for traj in center_traj:
......
...@@ -338,17 +338,17 @@ def visualize_attr(im, results, boxes=None): ...@@ -338,17 +338,17 @@ def visualize_attr(im, results, boxes=None):
im = np.ascontiguousarray(np.copy(im)) im = np.ascontiguousarray(np.copy(im))
im_h, im_w = im.shape[:2] im_h, im_w = im.shape[:2]
text_scale = max(1, int(im.shape[0] / 1600.)) text_scale = max(0.5, im.shape[0] / 3000.)
text_thickness = 2 text_thickness = 1
line_inter = im.shape[0] / 50. line_inter = im.shape[0] / 40.
for i, res in enumerate(results): for i, res in enumerate(results):
if boxes is None: if boxes is None:
text_w = 1 text_w = 3
text_h = 1 text_h = 1
else: else:
box = boxes[i] box = boxes[i]
text_w = int(box[2]) text_w = int(box[2]) + 3
text_h = int(box[3]) text_h = int(box[3])
for text in res: for text in res:
text_h += int(line_inter) text_h += int(line_inter)
...@@ -357,8 +357,8 @@ def visualize_attr(im, results, boxes=None): ...@@ -357,8 +357,8 @@ def visualize_attr(im, results, boxes=None):
im, im,
text, text,
text_loc, text_loc,
cv2.FONT_HERSHEY_PLAIN, cv2.FONT_ITALIC,
text_scale, (0, 0, 255), text_scale, (0, 255, 255),
thickness=text_thickness) thickness=text_thickness)
return im return im
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册