Reputation: 1942
I am using Python 2.7.11 and OpenCV 2.4.9. I cannot read a video by using cv2.imread() or cv2.VideoCapture().
import cv2
cap = cv2.VideoCapture('cam.avi')
print ("open = ",cap.isOpened())
OR
import cv2
cap = cv2.imread('cam.avi')
print ("open = ",cap.isOpened())
It will return false. I don't know why. I am sure that the cam.avi is here.
Upvotes: 2
Views: 5573
Reputation: 515
imread()
does not support reading from video files directly.
See also the documentation of OpenCV.
If you want to read a video with imread
you will first have to convert it to single images, either via a serperate program (ffmpeg
comes to mind) or using OpenCV and store the images in memory.
Upvotes: 2
Reputation: 2160
Try providing full path to video, like:
import cv2
cap = cv2.VideoCapture(r'C:\Users\e01069\Downloads\drop.avi')
print ("open = ",cap.isOpened())
If you run following in your same file, you would know that python is looking for your file on some different location.
import os
print os.path.abspath(__file__) #this is your current working directory
Note: .imread
wouldn't work this way.
Upvotes: 1