-
-
Notifications
You must be signed in to change notification settings - Fork 55.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't open webcan or video file with python3 and opencv #8471
Comments
@alalek what is missing ? |
Provided details is not enough to reproduce the issue. What does "3.2.0-1" mean in OpenCV version? Is it Arch package version? AUR? Please check correctness of loaded modules ( |
Can't open videos or webcam: System information (version) Detailed description Steps to reproduce # Fails with files, direct instantiation
import cv2
camera = cv2.VideoCapture("path/to/a/valid/video.mp4")
print(camera.isOpened()) # False
print(camera.read()) # (False, None) # Fails with files, using .open() method
import cv2
camera = cv2.VideoCapture()
camera.open("path/to/a/valid/video.mp4") # False
print(camera.read()) # (False, None) # Fails with webcam
import cv2
camera = cv2.VideoCapture(0)
print(camera.isOpened()) # False
print(camera.read()) # (False, None) |
Same issue with Python 3.6.0 under MacOS 10.12 Sierra. |
This is still looks like an usage question. OpenCV requires 3rdparty libraries to work with cameras/videos. You need to install them properly before building OpenCV Python bindings.
For more information please refer to this question and others:
(https://pypi.python.org/pypi/opencv-python)
Usage questions should go to Users OpenCV Q/A forum: http://answers.opencv.org |
I have had a comparable issue on Ubuntu, using the pip install opencv-python process. My solution has been to replace the cv2.so library provided by pypi with the one compiled from sources : And I now can play videos with cv2, from my python scripts. Hope this will help those experiencing the same issue (I spent some time on trying to find a solution and never found this suggestion so ...). |
I did a similar thing to @iiAnthony where I compiled OpenCV 3.2.0 from source, double checking with CMake that it can find both python 2 and python 3 then I replaced the compiled
Or better yet, just the Note: Your |
Considering these 2 commands:
In my case opencv-3.3.1/build/lib doesn't have folder python nor python 2.7 nor python 3.6. UPD: ISSUE solved see my last comment here. |
@chutsu thanks. From
I also see, that CmakeCache.txt file has predefined key/values, and I don't know how to tell cmake to know about my Python version. I used this command:
Regarding python-dev it's odd, because I installed Installing OpenCV from source https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_setup/py_setup_in_fedora/py_setup_in_fedora.html In fact Doing double checking of all... I dropped build folder and tried again. I tried:
And now I have now folder btw, I have this
and
So should I create manually or
? |
When I
In output I see trace of some version logic and error:
|
There is build/installation issue of numpy package on your machine. |
BTW,
You have custom python setup (without any information how you get it).
This file set is not generated by original OpenCV. You have installed something else from other sources. |
I recently solved issue for my use case.
And in fact I have Assertion error, as it's described here: ageitgey/face_recognition#191 (comment) Then, I compiled GOOD config - OpenCV from sources (git cloned and checked out 3.3.1 branch) and I had 3.3.1 version. But even with opencv 3.3.0.10 IT WAS NOT working, because
yes, opencv_python installs into So, then there are 2 ways of resolving issue:
And later on I did both, and my application was working in both cases. But still, I am not confident what is the best way. PS. So far I have 2 web cameras: built in and external via USB, and my python code can't access external. It always open built in. If someone know how to do it, please let me know. Here is piece of code:
|
In my case i simply un-installed and installed back opencv-python
|
For future reference: If you have installed either one of the precompiled distributions
Changelogs are available for every release at the |
I had this problem and couldn't find a solution, but on the web, it was working. My solution was almost funny - you can't have two streams. I turned off the web stream and then it was fine! |
I know people don't appreciate you @FilipBielickiPL, but that is certainly my problem, so thx! Basically, I have a configurable program (video vs webcam) and despite the WebcamVideoStream is not used during video mode, it'll disturb the way VideoCapture working. |
it would help if you can share a minimal reproducible example so that people can try out what the error is. Without example code we can't help you. |
@chutsu Why the thumbs down? I solved my error exactly like what @FilipBielickiPL did. Is that not clear enough? |
I have opencv running on cloud, This is not solving my issue. The file is present in the particular location but still unable to open the file.
|
Where is @FilipBielickiPL 's solution. i can't find out |
Great answer! |
Had same issue and found that meeting all these steps made it work on mac:
These are just the basics you could be missing and leading it to error or it could be something else but this is a good checklist for a first step. Good luck! |
System information (version)
Detailed description
Can't open VideoCapture don't work with files and /dev/video
Steps to reproduce
The code don't show webcan or video file
Works with python2 ..
The text was updated successfully, but these errors were encountered: