stereolabs / zed-python-api

Python API for the ZED SDK
https://www.stereolabs.com/docs/app-development/python/install/
MIT License
209 stars 95 forks source link

Camera timeout when a different camera is opened on Gstreamer #196

Closed ChealsieBains01 closed 2 years ago

ChealsieBains01 commented 2 years ago

Preliminary Checks

Description

I have 2 zed cameras plugged in, 1 zed mini, and 1 zed 2. The zed mini is being opened as a v4l2 device using a gstreamer pipeline:

    gst-launch-1.0 v4l2src device=/dev/video2 ! video/x-raw,format=YUY2,width=2560,height=720,framerate=60/1 ! xvimagesink

When I try to open the zed 2 in sdk while the mini is running, I get:

[ZED][Init][Info] Camera opening timeout reached

this is the code to open the zed 2. It works fine when the zed mini isn't running:

def main():
    # Create a Camera object
    zed = sl.Camera()
    # Create a InitParameters object and set configuration parameters
    init_params = sl.InitParameters()
    init_params.camera_resolution = sl.RESOLUTION.HD720  # Use HD1080 video mode    
    init_params.coordinate_units = sl.UNIT.METER
    init_params.camera_fps = 60                          # Set fps at 30
    init_params.coordinate_system = sl.COORDINATE_SYSTEM.RIGHT_HANDED_Y_UP
    init_params.enable_right_side_measure = True
    init_params.set_from_serial_number(24659869)
    runtime_parameters = sl.RuntimeParameters()

    # Open the camera
    err = zed.open()
    if err != sl.ERROR_CODE.SUCCESS:
        exit(1)

    # Set object detection parameters
    obj_param = sl.ObjectDetectionParameters()
    obj_param.enable_tracking = True
    obj_param.image_sync = True

    # Enable positional tracking
    if obj_param.enable_tracking:

        zed.enable_positional_tracking()

    # Enable object detection
    err = zed.enable_object_detection(obj_param)
    if err != sl.ERROR_CODE.SUCCESS :
        print (repr(err))
        zed.close()
        exit(1)

    objects = sl.Objects()
    obj_runtime_param = sl.ObjectDetectionRuntimeParameters()
    obj_runtime_param.detection_confidence_threshold = 40

    # Grab an image from the camera and detect objects on it
    while zed.grab() == sl.ERROR_CODE.SUCCESS:
        err = zed.retrieve_objects(objects, obj_runtime_param)
        if objects.is_new :
            obj_array = objects.object_list

            print(str(len(obj_array))+" Object(s) detected\n")

            if len(obj_array) > 0 :
                first_object = obj_array[0]

                # Make sure the mask is available for the detected object
                if first_object.mask.is_init():
                    print(" 2D mask available")
                    mask_data = first_object.mask.get_data()
                    # Display the extracted mask
                    cv2.imshow("2D Mask", mask_data)
                    cv2.waitKey(5)
                    print(first_object.bounding_box_2d[0][0])
                    # Save the mask as a jpeg file  
                    # cv2.imwrite("mask.jpg", mask_data, [cv2.IMWRITE_JPEG_QUALITY, 100])

                else:
                    print("2D mask not available")

                # input('\nPress enter to continue: ')

    cv2.destroyAllWindows()

    # Close the camera
    zed.close()

if __name__ == "__main__":
    main()  

Steps to Reproduce

  1. Plug in 2 zed cameras, and open one in a gstreamer pipeline as v4l2 device
  2. Open second zed camera in sdk using the set_from_serial_number function ...

Expected Result

I expect both the zed mini to open and the zed 2 to run in the code

Actual Result

the zed 2 doesn't open with error code: [ZED][Init][Info] Camera opening timeout reached

ZED Camera model

ZED Mini

Environment

OS: Ubuntu
GPU: Jetson Xavier NX
ZED SDK: 3.6.1

Anything else?

No response

Myzhar commented 2 years ago

Hi @ChealsieBains01 this is indeed strange. By opening the ZED2 by using its own serial number you should be sure to not have resources conflicts. Can you try to use guvcview or cheese to open the ZED Mini and then start your Python code to understand if that happens anyway? @qt-truong can you test it too?

ChealsieBains01 commented 2 years ago

I fixed this. Just had to put init_params in err = zed.open(init_params)

Myzhar commented 2 years ago

You are right, sorry, I missed that "simple" lack. I close the issue. Enjoy your devices