Body tracking not displaying

Hi when i am trying to run ```python “body_tracking.py” , its running i am getting the coordinates but nothing is displaying , can you please help me how to display live body tracking , i have zed cameras.

Hello and thank you for contacting us,

Can you give me a little more information about your setup ? Which ZED SDK version are you using ? Also, what happens when you run basic tools like ZED Depth Viewer ?

Antoine

Hi antoine,

Thanks for your reply

its working now , but i have small issue that how to track person with a id associated to that person . i am able to track the positional and body but my requirements is to track a person with a ID

for example i have a small store , in that i want to track a person with a ID .how to do it

Kind Regards
Siddharth Rana

Sent from my iPhone

Hello,

The ObjectData structure contains an id. You need to enable the tracking to keep the ids between the frames :

detection_parameters.enable_tracking = true; // Objects will keep the same ID between frames

Antoine Lassagne
Senior Developer - ZED SDK
Stereolabs Support

Hi,

i tried to find this detect.parameters but i couldn’t, could you please tell me on which line and python file it’s available

Sent from my iPhone

Hi ,

where i will find

detection_parameters.enable_tracking = true; // Objects will keep the same ID between frames

Sent from my iPhone

Hi,

i tried to find this detect.parameters but i couldn’t, could you please tell me on which line and python file it’s available

Sent from my iPhone

On Mar 22, 2023, at 10:37 AM, Antoine Lassagne (Stereolabs) support@stereolabs.com wrote:

hi,

please find the attached screenshot

already have done obj_param.enable_tracking = True ,

but still not getting the id

Hi,

i tried to find this detect.parameters but i couldn’t, could you please tell me on which line and python file it’s available

Sent from my iPhone

On Mar 22, 2023, at 10:37 AM, Antoine Lassagne (Stereolabs) support@stereolabs.com wrote:

You get the id in the ObjectData structure. You should follow this tutorial :
https://www.stereolabs.com/docs/object-detection/using-object-detection/

And here is a partial code that retrieves the id :

objects = sl.Objects() # Structure containing all the detected objectsif zed.grab() == sl.ERROR_CODE.SUCCESS : zed.retrieve_objects(objects, obj_runtime_param) # Retrieve the detected objects for object in objects.object_list: print("{} {}".format(object.id, object.position))

Antoine Lassagne
Senior Developer - ZED SDK
Stereolabs Support

Hi,

please find the attached code, i am trying to access id like this

HI,

########################################################################

Copyright (c) 2022, STEREOLABS.

All rights reserved.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS

“AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR

A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT

OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,

SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT

LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,

DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY

THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

########################################################################

“”"
This sample shows how to detect a human bodies and draw their
modelised skeleton in an OpenGL window
“”"
import cv2
import sys
import pyzed.sl as sl
import ogl_viewer.viewer as gl
import cv_viewer.tracking_viewer as cv_viewer
import numpy as np

if name == “main”:
print(“Running Body Tracking sample … Press ‘q’ to quit”)

Create a Camera object

zed = sl.Camera()

Create a InitParameters object and set configuration parameters

init_params = sl.InitParameters()
#init_params.enable_tracking = true
init_params.camera_resolution = sl.RESOLUTION.HD1080 # Use HD1080 video mode
init_params.coordinate_units = sl.UNIT.METER # Set coordinate units
init_params.depth_mode = sl.DEPTH_MODE.ULTRA
init_params.coordinate_system = sl.COORDINATE_SYSTEM.RIGHT_HANDED_Y_UP

If applicable, use the SVO given as parameter

Otherwise use ZED live stream

if len(sys.argv) == 2:
filepath = sys.argv[1]
print(“Using SVO file: {0}”.format(filepath))
init_params.svo_real_time_mode = True
init_params.set_from_svo_file(filepath)

Open the camera

err = zed.open(init_params)
if err != sl.ERROR_CODE.SUCCESS:
exit(1)

#sl.PositionalTrackingParameters()

Set initialization parameters

#detection_parameters = sl.detection_parameters()
detection_parameters = sl.ObjectDetectionParameters()
detection_parameters.detection_model = sl.DETECTION_MODEL.HUMAN_BODY_ACCURATE
#detection_parameters = sl.ObjectDetectionParameters()
detection_parameters.enable_tracking = True
detection_parameters.enable_body_fitting = True

Set runtime parameters

detection_parameters_rt = sl.ObjectDetectionRuntimeParameters()
detection_parameters_rt.detection_confidence_threshold = 40

Enable Positional tracking (mandatory for object detection)

if detection_parameters.enable_tracking :
positional_tracking_parameters = sl.PositionalTrackingParameters()
zed.enable_positional_tracking(positional_tracking_parameters)

If the camera is static, uncomment the following line to have better performances and boxes sticked to the ground.

positional_tracking_parameters.set_as_static = True

#zed.enable_positional_tracking(positional_tracking_parameters)
obj_param = sl.ObjectDetectionParameters()
obj_param.enable_body_fitting = True # Smooth skeleton move
obj_param.enable_tracking = True # Track people across images flow
obj_param.detection_model = sl.DETECTION_MODEL.HUMAN_BODY_FAST
obj_param.body_format = sl.BODY_FORMAT.POSE_18 # Choose the BODY_FORMAT you wish to use

Enable Object Detection module

zed.enable_object_detection(obj_param)

obj_runtime_param = sl.ObjectDetectionRuntimeParameters()
obj_runtime_param.detection_confidence_threshold = 40

objects = sl.Objects() # Structure containing all the detected objects# grab runtime parameters
runtime_params = sl.RuntimeParameters()
runtime_params.measure3D_reference_frame = sl.REFERENCE_FRAME.WORLD
if zed.grab(runtime_params) == sl.ERROR_CODE.SUCCESS :
zed.retrieve_objects(objects, obj_runtime_param) # Retrieve the detected objects
for object in objects.object_list:
print(“{} {}”.format(object.position))

Get ZED camera information

camera_info = zed.get_camera_information()

2D viewer utilities

display_resolution = sl.Resolution(min(camera_info.camera_resolution.width, 1280), min(camera_info.camera_resolution.height, 720))
image_scale = [display_resolution.width / camera_info.camera_resolution.width
, display_resolution.height / camera_info.camera_resolution.height]

Create OpenGL viewer

viewer = gl.GLViewer()
viewer.init(camera_info.calibration_parameters.left_cam, obj_param.enable_tracking,obj_param.body_format)

Create ZED objects filled in the main loop

bodies = sl.Objects()
image = sl.Mat()

while viewer.is_available():

Grab an image

if zed.grab() == sl.ERROR_CODE.SUCCESS:

Retrieve left image

zed.retrieve_image(image, sl.VIEW.LEFT, sl.MEM.CPU, display_resolution)

Retrieve objects

zed.retrieve_objects(bodies, obj_runtime_param)

Update GL view

viewer.update_view(image, bodies)

Update OCV view

image_left_ocv = image.get_data()
cv_viewer.render_2D(image_left_ocv,image_scale,bodies.object_list, obj_param.enable_tracking, obj_param.body_format)
cv2.imshow(“ZED | 2D View”, image_left_ocv)
cv2.waitKey(10)

viewer.exit()

image.free(sl.MEM.CPU)

Disable modules and close camera

zed.disable_object_detection()
zed.disable_positional_tracking()
zed.close()

Hi,

please find the attached code, i am trying to access id like this

Sent from my iPhone

On Mar 23, 2023, at 7:32 AM, Antoine Lassagne (Stereolabs) support@stereolabs.com wrote:

Hello,
Did you add my sample ?

objects = sl.Objects() # Structure containing all the detected objectsif zed.grab() == sl.ERROR_CODE.SUCCESS : zed.retrieve_objects(objects, obj_runtime_param) # Retrieve the detected objects for object in objects.object_list: print("{} {}".format(object.id, object.position))

Antoine Lassagne
Senior Developer - ZED SDK
Stereolabs Support

Hi,

yes i am using sample body_tracking.py and in that i have added whatevee you have said, please tell me what more changes and where to do so that i can get person id .

please

Sent from my iPhone

Hi,

yes i have added your sample , for the same i am attaching the code file

Hi again. You did not add my code to the sample. Please add it right after “zed.retrieve_objects(bodies, obj_runtime_param)”.

Regards,

Antoine Lassagne
Senior Developer - ZED SDK
Stereolabs Support

Hi,

Actually in body_tracking.py file we have zed.enable_object_detection(obj_param),
we dont have zed.retrieve(obj_params)

can you please explain me on which puthon file i have to your code

Sent from my iPhone

I can see the line zed.retrieveobjects(bodies, objruntime_param) in the file you sent. Just copy paste my code after it.

Regards,

Antoine Lassagne
Senior Developer - ZED SDK
Stereolabs Support

Hi anitone ,

where i have to add your code

Sent from my iPhone

Hello,

I strongly advise that you learn a bit of python. There are good tutorials on the internet. Stereolab’s tutorial are also very easy to understand. One hour or two should be enough if you’re a fast learner. Without that, you will not be able to go much further with your project.

Best regards,

Antoine Lassagne
Senior Developer - ZED SDK
Stereolabs Support

Hi,

Thanks for your reply

could you please send me your code again.

Sent from my iPhone

Here is the code :

objects = sl.Objects() # Structure containing all the detected objectsif zed.grab() == sl.ERROR_CODE.SUCCESS : zed.retrieve_objects(objects, obj_runtime_param) # Retrieve the detected objects for object in objects.object_list: print("{} {}".format(object.id, object.position))

Antoine Lassagne
Senior Developer - ZED SDK
Stereolabs Support