I read nearly all of questions about this subject but I didn't solve it. I am working on Linux/Mint. I tried to open my webcam (or any video it does not matter) with opencv and read a frame from the video. And I write this code:
import cv2
cap = cv2.VideoCapture(0)
while(True):
ret, frame = cap.read()
print ret #It returns always false
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
--> I read the problem might can be because of opencv installation. I checked the installation, it seems true. When I write 'pip freeze', the result list contained opencv-python module so I thought the installation is correct and it isn't the reason for my problem.
--> I tried to change the index in videoCapture(0) to -1 and 1, and it again failed.
--> And then, I read that the other cause can be FFmpeg or codec. But I also installed FFmpeg and the problem didn't change.
--> cv2.VideoCapture() didn't give any error but I want to install cv2 module on the Poject>Settings>Project Interpreter, it gave me an error (executed command: pip install cv2) But when I run this command, it gave me this error : Could not find a version that satisfies the requirement cv2 (from versions: ) No matching distribution found for cv2 I checked the cv2 module in my virtualenv and it seems there. (/cv_env/lib/python2.7/site-packages/cv2)
--> I also tried it with "skvideo.io.VideoCapture()" but I failed again.
So, I didn't understand the problem and I am really new in this subject. What is the problem?