Mask is inconsistent

I’m trying to get the mask of humans, but it is inconsistent.


import cv2
import sys
import time
import pyzed.sl as sl
import numpy as np
import argparse
import math
import numpy as np
from matplotlib import pyplot as plt
from skimage.measure import label, regionprops, regionprops_table
import pygame
from pygame.locals import *

from OpenGL.GL import *
from OpenGL.GLU import *

def main():

   
    print("Running Body Tracking sample ... Press 'q' to quit, or 'm' to pause or restart")

    # Create a Camera object
    zed = sl.Camera()

    # Create a InitParameters object and set configuration parameters
    init_params = sl.InitParameters()
    #init_params.camera_fps = 30  # Set fps at 30

    init_params.camera_resolution = sl.RESOLUTION.HD1080  # Use HD1080 video mode
    init_params.coordinate_units = sl.UNIT.CENTIMETER          # Set coordinate units
    init_params.depth_mode = sl.DEPTH_MODE.QUALITY
    init_params.coordinate_system = sl.COORDINATE_SYSTEM.RIGHT_HANDED_Y_UP
    
    # Open the camera
    err = zed.open(init_params)
    if err != sl.ERROR_CODE.SUCCESS:
        exit(1)

    # Enable Positional tracking (mandatory for object detection)
    positional_tracking_parameters = sl.PositionalTrackingParameters()
    # If the camera is static, uncomment the following line to have better performances
    # positional_tracking_parameters.set_as_static = True
    zed.enable_positional_tracking(positional_tracking_parameters)
    
    body_param = sl.BodyTrackingParameters()
    body_param.enable_segmentation = True
    body_param.enable_tracking = True                # Track people across images flow
    body_param.enable_body_fitting = False            # Smooth skeleton move
    body_param.detection_model = sl.BODY_TRACKING_MODEL.HUMAN_BODY_FAST
    body_param.body_format = sl.BODY_FORMAT.BODY_18  # Choose the BODY_FORMAT you wish to use

    # Enable Object Detection module
    zed.enable_body_tracking(body_param)

    body_runtime_param = sl.BodyTrackingRuntimeParameters()
    body_runtime_param.detection_confidence_threshold = 40

    # Get ZED camera information
    camera_info = zed.get_camera_information()
    # 2D viewer utilities
    
    
    bodies = sl.Bodies()
    image = sl.Mat()
    depth = sl.Mat()
    display_resolution = sl.Resolution(min(camera_info.camera_configuration.resolution.width, 1280), min(camera_info.camera_configuration.resolution.height, 720))
    key_wait = 10 

   
    while True:
        # Grab an image
        time_temp=time.time()

        if zed.grab() == sl.ERROR_CODE.SUCCESS:
            print("TIME",time.time()-time_temp)
            # Retrieve left image
            zed.retrieve_image(image, sl.VIEW.LEFT, sl.MEM.CPU)
            # Retrieve bodies
            zed.retrieve_measure(depth, sl.MEASURE.DEPTH)
            zed.retrieve_bodies(bodies, body_runtime_param)
            bodies_list=bodies.body_list 
            image_left_ocv = image.get_data()
            key = cv2.waitKey(key_wait)
            cv2.imshow("ZED | 2D View", image_left_ocv)
            cv2.waitKey(1)
            print("FPS : ",zed.get_current_fps())
            if key == 113: # for 'm' key
                for body in bodies_list:
                    print("body ID ",body.id, " Position ",body.keypoint_2d[2])
                    mask=body.mask
                    temp=mask.get_data()
                    if body.mask.is_init():
                        print(temp)
                        plt.imshow(temp)
                        plt.show()
                        print(temp.shape)

                break
    
    image.free(sl.MEM.CPU)
    zed.disable_body_tracking()
    zed.disable_positional_tracking()
    zed.close()
    cv2.destroyAllWindows()
    
if __name__ == '__main__':
    
    main() 

Sometime the mask is completely captured.


But mostly, the mask is not fully captured.

@Gopi-htic,
Thanks for reporting this, we’ll investigate it and get back to you.
Do you have the issue with all depth modes / body models?

Hi @Gopi-htic

We’ve reproduced and fixed this issue thanks to another user that sent us a SVO. It will be part of the next release. If you are interested in a early version, you can ask me.