How to have constant or persistent object id even if it moves or is covered for few seconds

Hello All,
I am using a YOLOv8 code where I am detecting some object. What I have noticed is that the object ID changes frequently on the same object. I want it to stay persistent through the project. In my case the object gets covered or is moved.

Can someone guide me what am I doing wrong? or what should I change?

Regards.

detector.py (13.3 KB)

Hi @tmehta,

As you have noticed, our tracking algorithm does not save any features of tracked objects to be able to recover from occlusions.

I would recommend looking into deep learning solutions such as Deep SORT or others that allow to track object features and be more robust to occlusions:

Hello @mattrouss,
Thank you for the idea. I have tried using deep sort. The results are not 100% stable but works. only if i cover my object the ID changes. I dont know if thats normal or not.

I have another doubt. I am using the following code, I am getting the window of point cloud and depth map open with ZED object detection. Unfortunately I am not seeing any output in those window. So I cant understand if the Point cloud and Depth map is working or not. Can you help me improve or tell me what mistake i am making?

Regards.

detector_v9.py (13.7 KB)

I have taken a look at your script and there doesn’t seem to be an issue at first glance. I would suggest printing the data from the images and point cloud to make sure the data is correctly retrieved, and maybe comparing with our official samples’ code to see any differences.

ok I will try. For me it live camera feed that i am trying to use for point cloud. The funny things is the window for point cloud and depth map pops up but I cant see anything happening in this windows. So I don’t know if it is working or not.

Today I will try comparing the codes with official sample codes and see if it works or not.

detector_v10.py (14.9 KB)
Hello @mattrouss, I am getting following errors for the above code. I havent changed anything in ogl viewer’s viewer file. But from the error it seems something is wrong with interpretation of GLUT from viewer code (I might be wrong but its just my interpretation). Can you please help? I am basically trying to view the point cloud output.

The error is PS C:\Program Files (x86)\ZED SDK\zed-sdk-master> & C:/Users/TarangMehta/AppData/Local/Programs/Python/Python310/python.exe “c:/Program Files (x86)/ZED SDK/zed-sdk-master/object detection/custom detector/python/pytorch_yolov8/detector_SAHI_V9_Only_SAHI.py”
Initializing Network…
Initializing Camera…
11/11/2024 11:52:37 - INFO - deep_sort_realtime.embedder.embedder_pytorch - MobileNetV2 Embedder for Deep Sort initialised
11/11/2024 11:52:37 - INFO - deep_sort_realtime.embedder.embedder_pytorch - - gpu enabled: True
11/11/2024 11:52:37 - INFO - deep_sort_realtime.embedder.embedder_pytorch - - half precision: True
11/11/2024 11:52:37 - INFO - deep_sort_realtime.embedder.embedder_pytorch - - max batch size: 16
11/11/2024 11:52:37 - INFO - deep_sort_realtime.embedder.embedder_pytorch - - expects BGR: True
11/11/2024 11:52:38 - INFO - deep_sort_realtime.deepsort_tracker - DeepSort Tracker initialised
11/11/2024 11:52:38 - INFO - deep_sort_realtime.deepsort_tracker - - max age: 30
11/11/2024 11:52:38 - INFO - deep_sort_realtime.deepsort_tracker - - appearance threshold: 0.3
11/11/2024 11:52:38 - INFO - deep_sort_realtime.deepsort_tracker - - nms threshold: OFF
11/11/2024 11:52:38 - INFO - deep_sort_realtime.deepsort_tracker - - max num of appearance features: None
11/11/2024 11:52:38 - INFO - deep_sort_realtime.deepsort_tracker - - overriding track class : No
11/11/2024 11:52:38 - INFO - deep_sort_realtime.deepsort_tracker - - today given : No
11/11/2024 11:52:38 - INFO - deep_sort_realtime.deepsort_tracker - - in-build embedder : Yes
11/11/2024 11:52:38 - INFO - deep_sort_realtime.deepsort_tracker - - polygon detections : No
[2024-11-11 10:52:38 UTC][ZED][INFO] Logging level INFO
[2024-11-11 10:52:39 UTC][ZED][INFO] Using USB input… Switched to default resolution HD720
[2024-11-11 10:52:39 UTC][ZED][INFO] [Init] Depth mode: ULTRA
[2024-11-11 10:52:40 UTC][ZED][INFO] [Init] Camera successfully opened.
[2024-11-11 10:52:40 UTC][ZED][INFO] [Init] Camera FW version: 1523
[2024-11-11 10:52:40 UTC][ZED][INFO] [Init] Video mode: HD720@60
[2024-11-11 10:52:40 UTC][ZED][INFO] [Init] Serial Number: S/N 35084232
Traceback (most recent call last):
File “C:\Users\TarangMehta\AppData\Local\Programs\Python\Python310\lib\site-packages\OpenGL\GLUT\special.py”, line 130, in safeCall
return function( *args, **named )
File “c:\Program Files (x86)\ZED SDK\zed-sdk-master\object detection\custom detector\python\pytorch_yolov8\ogl_viewer\viewer.py”, line 591, in draw_callback
self.draw()
File “c:\Program Files (x86)\ZED SDK\zed-sdk-master\object detection\custom detector\python\pytorch_yolov8\ogl_viewer\viewer.py”, line 639, in draw
glUseProgram(self.shader_pc.get_program_id())
File “C:\Users\TarangMehta\AppData\Local\Programs\Python\Python310\lib\site-packages\OpenGL\platform\baseplatform.py”, line 415, in call
return self( *args, **named )
File “src\errorchecker.pyx”, line 58, in OpenGL_accelerate.errorchecker._ErrorChecker.glCheckError
OpenGL.error.GLError: GLError(
err = 1281,
description = b’invalid value’,
baseOperation = glUseProgram,
cArguments = (4,)
)
GLUT Display callback <bound method GLViewer.draw_callback of <ogl_viewer.viewer.GLViewer object at 0x000002CCF0593FD0>> with (),{} failed: returning None GLError(
err = 1281,
description = b’invalid value’,
baseOperation = glUseProgram,
cArguments = (4,)
)

Hi @tmehta,

Can you please run the unchanged sample from this link: zed-sdk/object detection/custom detector/python/pytorch_yolov8 at master · stereolabs/zed-sdk · GitHub

And share if you have the same errors and displays that are not functioning correctly? As we have tested this sample internally this would maybe mean that there is an issue with your opengl installation.

Hello @mattrouss ,
I have run the original file and have no error and the code runs perfectly. Below is the image of the output of original file.

I dont know why my code gives the error. Can you suggest what is the things i am doing wrong in my code?

Regards.

In this case I would suggest reverting the changes you’ve made until you’ve found what changes the behavior.

From what I have seen the changes that could have an impact on the application would be:

l.98      img = cv2.cvtColor(image_net, cv2.COLOR_BGRA2RGB)

Which was previously cv2.COLOR_RGBA2RGB

And you’ve changed the init_parameters coordinate units

l.144    init_params.coordinate_units = sl.UNIT.MILLIMETER

Which will change the scale of the point cloud if you have not touched the opengl viewer

Yes I have changed this just a while ago but it only works with ZED files. It still gives the previous error when i use open3D for point cloud.

Create Open3D visualizer

vis = o3d.visualization.Visualizer()
vis.create_window()

Also, Can I use this ZED point cloud data to compare it to the CAD model I have?Any suggestion to match the detected object to CAD files data?

What’s surprising here is that adding the open3d visualizer impacts the original opengl viewer that works in the sample on its own. Maybe the open3d viewer conflicts with the initial viewer? Does removing the references to the Stereolabs viewer help?

I’m sorry we do not have too much experience with comparing the point cloud with CAD, I would suggest finding ways to convert .obj or .ply files to CAD format.

Hello @mattrouss ,
Can you guide me here what should i try?
Regrads.

What I recommed you do is remove all of the references to the gl.GLViewer in the code, as this should remove an eventual conflict between the viewer.
You can start by removing these lines:

    # Rest of your initialization code
    viewer = gl.GLViewer()
...
    viewer.init(camera_infos.camera_model, point_cloud_res, obj_param.enable_tracking)

And all of those referencing the viewer variable