NVTRACKER - update caption

DS 6.4
dGPU T4

This issue is not really a critical one, but I have a little doubt how to update a bounding box caption of an NVTRACKER detection.

To make it more “complicated” I’m doing it in GOLANG and before somebody says: BOOO, not supported… Yes I know that, but I can assure you: IT WORKS :)

I’m taking a probe from the NVTRACKER src pad and doing some annotation “improvements” (different colours per object type, print out detection object name and probability into the caption).

In order to modify the caption of a detection bounding box I’m using this snippet, kindly provided by @junshengy

Note: The original code was modifying the caption in the NVINFER provided element, but if I do this, the modification doesn’t appear:

	// Copy the new label
	C.strcpy(&objMeta.ptr.obj_label[0], cLabel)

So my variant uses this sequence, and it generally works, but has an issue (see below):

func modifyObjLabel(objMeta *NvDsObjectMeta, label string) {
	// Ensure the new label size does not exceed MAX_LABEL_SIZE
	if len(label) >= C.MAX_LABEL_SIZE {
		label = label[:C.MAX_LABEL_SIZE-1]
	}
	// Convert Go string to C string (capitalize)
	cLabel := C.CString(strings.ToUpper(string(label[0])) + label[1:])
	defer C.free(unsafe.Pointer(cLabel))
	// Copy the new label
	C.strcpy(objMeta.ptr.text_params.display_text, cLabel)
}

The issue is: Sooner or later the entire app crashes with free(): invalid pointer. GDB shows, that it always crashes for the same reason:

INFO[2024-05-07T10:04:21Z] Topic: 'test-inference', TS: 2024-05-07T10:04:21.213839098Z, Frame: 36600, Object: truck, L: 1178, T: 297 W: 102, H: 91, dc: 0.81, tc: 0.81 
free(): invalid pointer

Thread 28 "nvv4l2h264enc0:" received signal SIGABRT, Aborted.
[Switching to Thread 0x7fff055fa640 (LWP 9387)]
__pthread_kill_implementation (no_tid=0, signo=6, threadid=140733283542592) at ./nptl/pthread_kill.c:44
44	./nptl/pthread_kill.c: No such file or directory.
(gdb) backtrace full
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=140733283542592) at ./nptl/pthread_kill.c:44
        tid = <optimized out>
        ret = 0
        pd = 0x7fff055fa640
        old_mask = {__val = {0, 16, 140733283539456, 140733283539344, 0 <repeats 12 times>}}
        ret = <optimized out>
#1  __pthread_kill_internal (signo=6, threadid=140733283542592) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=140733283542592, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x00007ffff7842476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
        ret = <optimized out>
#4  0x00007ffff78287f3 in __GI_abort () at ./stdlib/abort.c:79
        save_stage = 1

                  act = {__sigaction_handler = {sa_handler = 0x0, sa_sigaction = 0x0}, sa_mask = {__val = {0, 0, 0, 0, 0, 0, 0, 0, 0, 18188203059170661668, 140736092326347, 0, 15720566905470065920, 140732190849864, 140732190849840, 11622848}}, sa_flags = 0, sa_restorer = 0x7ffec8027d80}
        sigs = {__val = {32, 0 <repeats 15 times>}}
#5  0x00007ffff7889676 in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7ffff79dbb77 "%s\n") at ../sysdeps/posix/libc_fatal.c:155
        ap = {{gp_offset = 24, fp_offset = 32767, overflow_arg_area = 0x7fff055f9940, reg_save_area = 0x7fff055f98d0}}
        fd = <optimized out>
        list = <optimized out>
        nlist = <optimized out>
        cp = <optimized out>
#6  0x00007ffff78a0cfc in malloc_printerr (str=str@entry=0x7ffff79d9744 "free(): invalid pointer") at ./malloc/malloc.c:5664
#7  0x00007ffff78a2a44 in _int_free (av=<optimized out>, p=<optimized out>, have_lock=0) at ./malloc/malloc.c:4439
        size = 0
        fb = <optimized out>
        nextchunk = <optimized out>
        nextsize = <optimized out>
        nextinuse = <optimized out>
--Type <RET> for more, q to quit, c to continue without paging--
        prevsize = <optimized out>
        bck = <optimized out>
        fwd = <optimized out>
        __PRETTY_FUNCTION__ = "_int_free"
#8  0x00007ffff78a5453 in __GI___libc_free (mem=<optimized out>) at ./malloc/malloc.c:3391
        ar_ptr = <optimized out>
        p = <optimized out>
        err = 0
#9  0x00007ffff7ab487f in release_obj_meta () at /opt/nvidia/deepstream/deepstream/lib/libnvds_meta.so
#10 0x00007ffff7ab465b in nvds_clear_meta_list () at /opt/nvidia/deepstream/deepstream/lib/libnvds_meta.so
#11 0x00007ffff7ab46f5 in release_frame_meta () at /opt/nvidia/deepstream/deepstream/lib/libnvds_meta.so
#12 0x00007ffff7ab3ffd in nvds_destroy_meta_pool () at /opt/nvidia/deepstream/deepstream/lib/libnvds_meta.so
#13 0x00007ffff7ab2da5 in nvds_destroy_batch_meta () at /opt/nvidia/deepstream/deepstream/lib/libnvds_meta.so
#14 0x00007ffff7e91b48 in gst_buffer_foreach_meta () at /lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#15 0x00007ffff7e9708c in gst_buffer_pool_release_buffer () at /lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#16 0x00007ffff7e97178 in  () at /lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#17 0x00007ffff7ec9c25 in gst_mini_object_unref () at /lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#18 0x00007fffaccadeb6 in gst_video_codec_frame_unref () at /lib/x86_64-linux-gnu/libgstvideo-1.0.so.0
#19 0x00007fffacca37ff in gst_video_encoder_finish_frame () at /lib/x86_64-linux-gnu/libgstvideo-1.0.so.0
#20 0x00007fff819ad6bd in  () at /usr/lib/x86_64-linux-gnu/gstreamer-1.0/deepstream/libgstnvvideo4linux2.so
#21 0x00007ffff7efd127 in  () at /lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#22 0x00007ffff7d2e6b4 in  () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#23 0x00007ffff7d2ba51 in  () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
#24 0x00007ffff7894ac3 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
        ret = <optimized out>
        pd = <optimized out>

                      unwind_buf = {cancel_jmp_buf = {{jmp_buf = {140733300313280, -1274144647770067997, 140733283542592, 0, 140737346357200, 140733300313632, 1274341186633673699, 1274161504072051683}, mask_was_saved = 0}}, priv = {pad = {0x0, 0x0, 0x0, 0x0}, data = {prev = 0x0, cleanup = 0x0, canceltype = 0}}}
--Type <RET> for more, q to quit, c to continue without paging--
        not_first_call = <optimized out>
#25 0x00007ffff7926850 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
(gdb) 

So the reason seems to be clear: I’m somehow corrupting the memory with my caption overwrite mechanism. In fact, this is true, because if I comment this manipulation and replace it by the original one, the crash doesn’t happen. But of course, also the changed caption does not appear.

Question is: How can I change the caption of an NVTRACKER managed object (I hope this makes it clear)…

Looks like I have a bit more to do if I’m trying to change it this way…

https://docs.nvidia.com/metropolis/deepstream/6.1.1/dev-guide/python-api/PYTHON_API/NvDsMeta/NvDsDisplayMeta.html

Disregard. I think I know what I have to do.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.