Reputation: 2959
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)
Upvotes: 0
Views: 669
Reputation: 205
@Abdul Niyas P M's answer is right but here's an example for people like me:
video_obj = request.FILES['file_name']
vid_path = video_obj.temporary_file_path()
cap = cv2.VideoCapture(vid_path)
Upvotes: 2
Reputation: 24922
Seems like cv2.VideoCapture
can only work with filepath.
So to get the path from TemporaryUploadedFile
object you can use temporary_file_path()
method.
Upvotes: 1