Home > Blockchain >  Pass video uploaded via django to cv2
Pass video uploaded via django to cv2

Time:11-30

I am uploading video via django and want to process it using cv2. This is how video uploaded via django is accessed.

video_obj = request.FILES['file_name']

Next i want to pass it to opencv. I dont want to save video in disk first and then acess it via cv2 using following code

cap = cv2.VideoCapture(vid_path) 

I tried passing this video_obj to VideoCapture this way

video_obj = request.FILES['file_name']
cap = cv2.VideoCapture(video_obj) 

But i got following error

Can't convert object of type 'TemporaryUploadedFile' to 'str' for 'filename'
VideoCapture() missing required argument 'apiPreference' (pos 2)

CodePudding user response:

Seems like cv2.VideoCapture can only work with filepath. So to get the path from TemporaryUploadedFile object you can use temporary_file_path() method.

  • Related