I am trying to keep track of all nose key points of the closest person to the camera and show the results using cv2.imshow.
Something like this:
I came up with below code to save previous objects in a copy of “bodies.object_list” which I called “Tbodies”. Then append each new detected one to it with a new id (as an example I just used a counter). But the problem is that I cannot find any method to append an element to “sl.Objects()”. As you see the body lists is an instance of sl.Objects().
I will appreciate any help.
def detect(self):
# Create OpenGL viewer
viewer = gl.GLViewer()
viewer.init(self.camera_info.calibration_parameters.left_cam, self.obj_param.enable_tracking,self.obj_param.body_format)
# Create ZED objects filled in the main loop
bodies = sl.Objects()
Tbodies = bodies
image = sl.Mat()
obj_id_counter = 1000
while viewer.is_available():
# Grab an image
if self.zed.grab() == sl.ERROR_CODE.SUCCESS:
# Retrieve left image
self.zed.retrieve_image(image, sl.VIEW.LEFT, sl.MEM.CPU, self.display_resolution)
# Retrieve objects
self.zed.retrieve_objects(bodies, self.obj_runtime_param)
# Find closest body and send it to the robot
nose = self.__find_close_body_nose(bodies)
self.__send_body_data(nose)
# Update GL view
viewer.update_view(image, bodies)
# Update OCV view
image_left_ocv = image.get_data()
#-------------------------
for obj in bodies.object_list:
temp_obj = obj
temp_obj.id = obj_id_counter
obj_id_counter+=1
# To do
#Tbodies.object_list.appnd(temp_obj)
print(temp_obj.id)
#--------------------------
cv_viewer.render_2D(image_left_ocv,self.image_scale,bodies.object_list, self.obj_param.enable_tracking, self.obj_param.body_format)
cv2.imshow("ZED | 2D View", image_left_ocv)
cv2.waitKey(10)
viewer.exit()
image.free(sl.MEM.CPU)