Hi @junshengy , I have two more questions, please kindly answer them.
I have been able to use the function pyds.nvds_obj_enc_process in both Deepstream 8.0 with official pyds release, and in Deepstream 6.4 with pyds built using your answer.
Question 1: The changes that I make to image from nvds_buf_surface are also showing up in the image saved by nvds_obj_enc_process. Is this expected?
I was thinking that the changes made by cv2 won’t show up in the saved image as nvds_obj_enc_process saves image from GPU to disk by GPU itself.
Parts of my code:
image_frame = pyds.get_nvds_buf_surface(hash(gst_buffer), frame_meta.batch_id)
# HERE I do some cv2 operations on the above image_frame like drawing bboxes.
# then
if config.SAVE_DIRECTLY_FROM_GPU:
print("Saving directly by GPU")
nvds_enc_args = pyds.NvDsObjEncUsrArgs()
# filling them here: saving frame, no scaling, quality 95
pyds.nvds_obj_enc_process(obj_ctx_handle, nvds_enc_args, hash(gst_bffer), None, frame_meta) # Please note that I am not referring to the above image_frame variable in any manner here.
else:
print("Saving by cv2")
cv2.imwrite(frameloc, image_frame)
Extra context for this question: I am doing the cv2 operations because I want to put the result image in a SharedArray for a different purpose. I was testing nvds_obj_enc_process only for speed boost compared to cv2’s imwrite.
Question 2: nvds_obj_enc_process is taking more time to save the frame compared to cv2 imwrite. Is this expected?
I was thinking hardware encoding by GPU will be faster. I have one NVENC on my GPU. It is GeForce GTX 1650, and has one NVENC engine on it as mentioned here.
The function nvds_obj_enc_process prints the time taken for saving each frame as I set calcEncodeTimeto 1 in NvEncObjUsrArgs. Similarly, I printed time calculated for cv2 imwrite by placing time.perf_counter before and after. Details are mentioned below which are mean and median of several frames.
| Image saver |
Mean time(msec) |
Median time(msec) |
| cv2 imwrite |
2.1936 |
2.0590 |
| nvds_obj_enc_process |
4.6912 |
4.5280 |
Details mentioned above are for DS6.4 (similar difference was seen in DS 8.0 i.e. cv2 being faster, although both were higher compared to their corresponding DS6.4 values.