I’m trying to implement a video classification application for which I’m using 3 files [labels, trained model and input video]. I’m hardcoding the file paths of labels.txt file and trained model however I’m allowing the user to select the input video they want using the file_uploader() component. Now the problem is that the cv2.VideoCapture() requires a filename along with extension to read the local video file but with file_uploader() I get a BytesIO stream (if I’m not wrong) of the selected file.
I referred a couple of threads on this forum on the similar issue and found this one to be helpful in reading the uploaded file and then playing it by using
tempfile to create a temporary file and passing that to cv2.VideoCapture().
Now the problem is I need to extract certain number of frames from the input video, pre-process them, create a blob of those frames (using cv2.dnn.blobFromImages()) and then pass this blob to the trained model to get classification. I’m struggling with the part where I need to extract frames from the video stream and unfortunately this is the core of my application.
I’m attaching the python code that I’m trying to convert into a web app here
So can someone please help me implement this, I’d really appreciate it.