How to take photo (How to save frame image)

• Hardware Platform (Jetson / GPU) Jetson Nano
• DeepStream Version 5.1
• JetPack Version (valid for Jetson only) 4.5.1
• TensorRT Version 7.1.3+cuda10.2
• Issue Type( questions, new requirements, bugs) Question

Hi,
I modified deepstream_test1_usb.py little. I wonder how can I take pictures with detection.

Thanks

deepstream_test_1_usb_2.py (17.0 KB)

Can you elaborate your requirement? You want to save the frame image which some objects are detected?

I want to save frame image when person and helmet count not equal.

There is image save sample deepstream-imagedata-multistream.

1 Like

Thank you. I will check.

Hi,

I edit my code like below.

            if obj_counter[PGIE_CLASS_ID_PERSON] != obj_counter[SGIE_CLASS_ID_HELMET]:
                track_id = obj_meta.object_id
                now = time.time()
                if flag==0 and track_id != last_track_id:
                    #print(str(track_id) + ' -- ' + str(last_track_id))
                    n_frame = pyds.get_nvds_buf_surface(hash(gst_buffer), frame_meta.batch_id)
                    frame_copy = np.array(n_frame, copy=True, order='C')
                    frame_copy = cv2.cvtColor(frame_copy, cv2.COLOR_RGBA2BGRA)
                    last_track_id = track_id
                    save_image = True
                    print('Photo')
                    takenow = time.time()
                    flag = 1
                    TAKE_PHOTO = True
                if now>takenow+5:
                    print('Reset')
                    flag = 0
            else:
                TAKE_PHOTO = False
            try: 
                l_obj=l_obj.next
            except StopIteration:
                break
        if save_image:
            img_path = "{}/stream_{}_frame_{}.jpg".format(folder_name, frame_meta.pad_index, frame_number)
            print(img_path)
            cv2.imwrite(img_path, frame_copy)

Its works like I wanted.

But I had problem with orginal img_path provided in example below. frame_{} folder wasnt created. I don’t know if I missed the part for that folder creation but I changed it to stream_{}_frame{}

            img_path = "{}/stream_{}/frame_{}.jpg".format(folder_name, frame_meta.pad_index, frame_number)

Thank you

hello I have tried using deepstream-imagedata-multistream but for me it shows bus error , segmentation fault after saving 1-2 frames . If I comment n_frame = pyds.get_nvds_buf_surface(hash(gst_buffer), rame_meta.batch_id)
Then there is no probelm arising, could you help me to figure out this problem. I have been stuck with it for long . I have tesla k40 gpu, and all other applications are working fine except when I try to extract frame meta…

Hey @bhatiyaarpit95 . I am sure if you open new topic you can find faster solution.

But you missed ‘f’ in rame_meta below.

n_frame = pyds.get_nvds_buf_surface(hash(gst_buffer), rame_meta.batch_id)

I am not sure if this is the cause of your problem but you can try.

Edit: I saw yor py file here. It seems ok to me.

Thanks

1 Like

Thanks for your time, yes that ‘f’ missing is not problem btw… Did it worked fine in your system.

It works fine but I didn’t use source _bin and draw_bounding_boxes. Problem might be one of them

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