Changed visualization

This commit is contained in:
charlesbvll 2021-05-01 17:25:13 +02:00
parent 40eddd66e4
commit a68699db62
3 changed files with 39 additions and 34 deletions

View File

@ -24,8 +24,10 @@ def cli():
help='what to output: json keypoints skeleton for Pifpaf' help='what to output: json keypoints skeleton for Pifpaf'
'json bird front or multi for MonStereo') 'json bird front or multi for MonStereo')
predict_parser.add_argument('--no_save', help='to show images', action='store_true') predict_parser.add_argument('--no_save', help='to show images', action='store_true')
predict_parser.add_argument('--hide_distance', help='to not show the absolute distance of people from the camera',
default=False, action='store_true')
predict_parser.add_argument('--dpi', help='image resolution', type=int, default=150) predict_parser.add_argument('--dpi', help='image resolution', type=int, default=150)
predict_parser.add_argument('--long-edge', default=None, type=int, predict_parser.add_argument('--long_edge', default=None, type=int,
help='rescale the long side of the image (aspect ratio maintained)') help='rescale the long side of the image (aspect ratio maintained)')
predict_parser.add_argument('--white-overlay', predict_parser.add_argument('--white-overlay',
nargs='?', default=False, const=0.8, type=float, nargs='?', default=False, const=0.8, type=float,
@ -60,7 +62,6 @@ def cli():
predict_parser.add_argument('--dropout', type=float, help='dropout parameter', default=0.2) predict_parser.add_argument('--dropout', type=float, help='dropout parameter', default=0.2)
predict_parser.add_argument('--show_all', help='only predict ground-truth matches or all', action='store_true') predict_parser.add_argument('--show_all', help='only predict ground-truth matches or all', action='store_true')
predict_parser.add_argument('--webcam', help='monstereo streaming', action='store_true') predict_parser.add_argument('--webcam', help='monstereo streaming', action='store_true')
predict_parser.add_argument('--scale', default=0.2, type=float, help='change the scale of the webcam image')
predict_parser.add_argument('--focal', help='focal length in mm for a sensor size of 7.2x5.4 mm. (nuScenes)', predict_parser.add_argument('--focal', help='focal length in mm for a sensor size of 7.2x5.4 mm. (nuScenes)',
type=float, default=5.7) type=float, default=5.7)

View File

@ -65,6 +65,7 @@ class Printer:
self.save = not args.no_save and not self.webcam self.save = not args.no_save and not self.webcam
self.plt_close = not self.webcam self.plt_close = not self.webcam
self.activities = args.activities self.activities = args.activities
self.hide_distance = args.hide_distance
# define image attributes # define image attributes
self.attr = image_attributes(args.dpi, args.output_types) self.attr = image_attributes(args.dpi, args.output_types)
@ -184,22 +185,22 @@ class Printer:
keypoint_sets, _ = get_pifpaf_outputs(annotations) keypoint_sets, _ = get_pifpaf_outputs(annotations)
keypoint_painter = KeypointPainter(show_box=False, y_scale=self.y_scale) keypoint_painter = KeypointPainter(show_box=False, y_scale=self.y_scale)
if not self.hide_distance:
scores = self.dd_pred
else:
scores=None
if activities: if activities:
keypoint_painter.keypoints( keypoint_painter.keypoints(
axis, keypoint_sets, size=self.im.size, axis, keypoint_sets, size=self.im.size,
scores=self.dd_pred, colors=colors, activities=activities, dic_out=dic_out) scores=scores, colors=colors, activities=activities, dic_out=dic_out)
if 'social_distance' in activities:
draw_orientation(axis, self.centers,
sizes, self.angles, colors, mode='front')
else: else:
keypoint_painter.keypoints( keypoint_painter.keypoints(
axis, keypoint_sets, size=self.im.size, scores=self.dd_pred) axis, keypoint_sets, size=self.im.size, colors=colors, scores=scores)
draw_orientation(axis, self.centers,
def _activities_bird(self, axis, colors, activities): sizes, self.angles, colors, mode='front')
if 'social_distance' in activities:
draw_orientation(axis, self.xz_centers, [], self.angles, colors, mode='bird')
def _front_loop(self, iterator, axes, number, colors, annotations, dic_out): def _front_loop(self, iterator, axes, number, colors, annotations, dic_out):
@ -218,8 +219,7 @@ class Printer:
def _bird_loop(self, iterator, axes, colors, number): def _bird_loop(self, iterator, axes, colors, number):
for idx in iterator: for idx in iterator:
if any(xx in self.output_types for xx in ['bird', 'multi']) and self.zz_pred[idx] > 0: if any(xx in self.output_types for xx in ['bird', 'multi']) and self.zz_pred[idx] > 0:
if self.activities: draw_orientation(axes[1], self.xz_centers, [], self.angles, colors, mode='bird')
self._activities_bird(axes[1], colors, self.activities)
# Draw ground truth and uncertainty # Draw ground truth and uncertainty
self._draw_uncertainty(axes, idx) self._draw_uncertainty(axes, idx)
@ -231,9 +231,8 @@ class Printer:
def draw(self, figures, axes, image, dic_out=None, annotations=None): def draw(self, figures, axes, image, dic_out=None, annotations=None):
colors = [] colors = ['deepskyblue' for _ in self.uv_heads]
if self.activities: if self.activities:
colors = ['deepskyblue' for _ in self.uv_heads]
if 'social_distance' in self.activities: if 'social_distance' in self.activities:
colors = social_distance_colors(colors, dic_out) colors = social_distance_colors(colors, dic_out)
@ -291,23 +290,24 @@ class Printer:
x_t = x0 - 1.5 x_t = x0 - 1.5
y_t = y1 + self.attr['y_box_margin'] y_t = y1 + self.attr['y_box_margin']
if y_t < (self.height-10): if y_t < (self.height-10):
ax.annotate( if not self.hide_distance:
text, ax.annotate(
(x_t, y_t), text,
fontsize=self.attr['fontsize_d'], (x_t, y_t),
weight='bold', fontsize=self.attr['fontsize_d'],
xytext=(5.0, 5.0), weight='bold',
textcoords='offset points', xytext=(5.0, 5.0),
color='white', textcoords='offset points',
bbox=bbox_config, color='white',
) bbox=bbox_config,
if number['flag']: )
ax.text(x0 - 17, if number['flag']:
y1 + 14, ax.text(x0 - 17,
chr(number['num']), y1 + 14,
fontsize=self.attr['fontsize_num'], chr(number['num']),
color=self.attr[self.modes[idx]]['numcolor'], fontsize=self.attr['fontsize_num'],
weight='bold') color=self.attr[self.modes[idx]]['numcolor'],
weight='bold')
def _draw_text_bird(self, axes, idx, num): def _draw_text_bird(self, axes, idx, num):
"""Plot the number in the bird eye view map""" """Plot the number in the bird eye view map"""
@ -429,13 +429,14 @@ class Printer:
else: else:
uv_max = [0., float(self.height)] uv_max = [0., float(self.height)]
xyz_max = pixel_to_camera(uv_max, self.kk, self.z_max) xyz_max = pixel_to_camera(uv_max, self.kk, self.z_max)
x_max = max(abs(xyz_max[0]), 6) # shortcut to avoid oval circles in case of different kk x_max = abs(xyz_max[0]) # shortcut to avoid oval circles in case of different kk
corr = round(float(x_max / 3)) corr = round(float(x_max / 3))
ax.plot([0, x_max], [0, self.z_max], 'k--') ax.plot([0, x_max], [0, self.z_max], 'k--')
ax.plot([0, -x_max], [0, self.z_max], 'k--') ax.plot([0, -x_max], [0, self.z_max], 'k--')
ax.set_xlim(-x_max + corr, x_max - corr) ax.set_xlim(-x_max + corr, x_max - corr)
ax.set_ylim(0, self.z_max + 1) ax.set_ylim(0, self.z_max + 1)
ax.set_xlabel("X [m]") ax.set_xlabel("X [m]")
ax.set_box_aspect(.8)
plt.xticks(fontsize=self.attr['fontsize_ax']) plt.xticks(fontsize=self.attr['fontsize_ax'])
plt.yticks(fontsize=self.attr['fontsize_ax']) plt.yticks(fontsize=self.attr['fontsize_ax'])
return ax return ax

View File

@ -55,6 +55,8 @@ def factory_from_args(args):
args.no_save = True args.no_save = True
args.batch_size = 1 args.batch_size = 1
if args.long_edge is None:
args.long_edge = 144
# Make default pifpaf argument # Make default pifpaf argument
args.force_complete_pose = True args.force_complete_pose = True
LOG.info("Force complete pose is active") LOG.info("Force complete pose is active")
@ -88,7 +90,8 @@ def webcam(args):
while True: while True:
start = time.time() start = time.time()
ret, frame = cam.read() ret, frame = cam.read()
image = cv2.resize(frame, None, fx=args.scale, fy=args.scale) scale = (args.long_edge)/frame.shape[0]
image = cv2.resize(frame, None, fx=scale, fy=scale)
height, width, _ = image.shape height, width, _ = image.shape
print('resized image size: {}'.format(image.shape)) print('resized image size: {}'.format(image.shape))
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)