Can we use OpenCV on databricks?

I have tried reading image and video data in Azure databricks using OpenCv. When I have checked the type of image, it’s shown as “NonType” and when tried with vedio file, the file itself was not being opened. (Note: these files are stored on azure blob storage and accesssed in databrics after mounting.)

maybe you need to add some example code of what you’re attempting to do… because in principle nothing should be stopping you from using say… OpenCV … the obvious limitation in a place like Dbricks… is it’s compatibility to show outputs like visualization libs

import numpy as np
import cv2
import ffmpeg

# Capture video from file
cap = cv2.VideoCapture('dbfs:/databricks-datasets/cctvVideos/mp4/test/Browse1.mp4', cv2.CAP_V4L)
while True:
    success, img = cap.read()
    print(success)
    if success:
        cv2.imshow("video", img)
        cv2.waitKey(1)
        if 0xFF == ord('q') :
            break   
    else:
        break

This is the code which I was using.

that’s for webcams, not video files. try

cv2.CAP_FFMPEG or cv2.CAP_GSTREAMER instead

I have tried both of them and also cv2.CAP_IMAGES and cv2.CAP_DSHOW. The result is same in all the cases. OpenCV 4.5.5 is the version installed in the cluster I am using. Does it have any dependencies on other libraries?

dbfs: may not be understood by ffmpeg or gstreamer.

you need a local file for this to work.

yes, either on ffmpeg or gstreamer.
check cv2.getBuildInformation() to see what you have builtin

also try to simply f = open('dbfs:/databricks-datasets/cctvVideos/mp4/test/Browse1.mp4') to rule out that it’s a path or fs problem

docs:

[edit] you may need a path like:

'/dbfs/databricks-datasets/cctvVideos/mp4/test/Browse1.mp4'