read video

Niaussat
Niaussat Registered Posts: 3 ✭✭✭
edited July 16 in Using Dataiku

Hello,

I want to read a video from a folder using the python package OpenCV but I have this error :

OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'VideoCapture'
> Overload resolution failed:
>  - Can't convert object to 'str' for 'filename'
>  - Required argument 'apiPreference' (pos 2) not found
>  - Argument 'index' is required to be an integer
>  - Required argument 'apiPreference' (pos 2) not found

Have you got a solution ?

Thanks

Tagged:

Best Answer

  • Sarina
    Sarina Dataiker, Dataiku DSS Core Designer, Dataiku DSS Adv Designer, Registered Posts: 317 Dataiker
    edited July 17 Answer ✓

    Hi @Niaussat
    ,

    It will depend on if cv2.VideoCapture() can read in a file-like object, which is what you are currently passing into it, and it seems like it may not be able to. Because of this, I would focus on:

    • reading your images from a managed file stored on the DSS server, which will allow you to read in your videos directly based on their filepaths (example below).
    • if your video files are stored remotely (i.e. S3) and this cannot be modified, as part of your loop, you can download the video file to your DSS server, process the file based on the local video file, and then remove the locally downloaded copy of the file after your processing is complete. This should allow you to read in the file locally, as it seems like cv2 requires, instead of from the file-like object.

    If you could use help on the latter part, can you clarify what type of connection your managed folder is using, so that I might provide an example?

    Here is an example of reading in the videos based on the "locally stored" video files:

    Screen Shot 2022-04-07 at 6.25.40 PM.png

    import cv2
    import dataiku 
    
    video = dataiku.Folder('YKDPuZkg')
    folder_path = video.get_info()['path']
    
    for vid in video.get_path_details()['children']:
        full_vido_path = folder_path + vid['fullPath']
        cap = cv2.VideoCapture(full_vido_path)
    
    cap.read()


    I hope that's helpful.

    Thanks,
    Sarina

Answers

Setup Info
    Tags
      Help me…