Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pass video uploaded via django to cv2

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading