Hi, I am trying to extract body silhouettes of people walking across a corridor in realtime (8m long, 2.4m tall, 3m wide). We will use 4 ZED2 cameras spaced evenly across the same wall. The desired outcome is a black&white 1600px*480px video stream, which will be used as a mask in another application.
After reading posts like Extract point cloud data of particular detection and removing background point cloud and Extracing point cloud and mesh of human body, I think I could extract point clouds from each camera, mask out background points using bodyData.mask, and offset the masked point clouds in the same 3d space.
So far I came up with this prototype using 2 cameras (havenât implemented point cloud masking yet - just attempting to extract and visualize all the necessary data):
And here is the corresponding code:
import ogl_viewer.GLViewer as gl
import numpy as np
import pyzed.sl as sl
import cv2
# initialization code...
cameras = {...} # { sl.Camera, ... }
point_clouds = {...} # { sl.Mat, ... }
cam_images = {...} # { sl.Mat, ... }
bodies = {...} # { sl.Bodies, ... }
viewer = gl.GLViewer()
# main loop
while viewer.is_available():
for sn in cameras:
camera = cameras[sn]
if camera.grab() == sl.ERROR_CODE.SUCCESS:
camera.retrieve_bodies(bodies[sn])
camera.retrieve_image(cam_images[sn], sl.VIEW.LEFT_GRAY, sl.MEM.CPU)
camera.retrieve_measure(point_clouds[sn], sl.MEASURE.XYZRGBA, sl.MEM.CPU)
image_data = cam_images[sn].get_data()
for bodyData in bodies[sn].body_list:
box2d = bodyData.bounding_box_2d
x1, y1 = map(int, box2d[0])
x2, y2 = map(int, box2d[2])
w = x2 - x1
h = y2 - y1
cv2.rectangle(image_data, (x1, y1), (x2, y2), [255, 0, 0], 2) # draw bodyData bounding box
if (bodyData.mask.is_init()):
mask_data = bodyData.mask.get_data()
image_data[y1:y1+h, x1:x1+w] = mask_data # draw bodyData.mask
cv2.imshow('rgb_' + str(sn), image_data)
viewer.updateData(sn, point_clouds[sn])
As you can see in the video, the extracted mask doesnât always include the complete silhouette (especially the hair and cloth), and in a lot of frames the mask is just empty (but the bounding box is there).
Iâm wondering if what Iâve been doing is a sensible approach? Are there any suggestion / alternative solution I should explore?
Thanks a lot!