How to install openCV on windows to work with python - python

Im trying to install OpenCV to run with Visual Studio using python. Im using this link : Installation OpenCV on windows the problem is I cannot find file CV2.pyd.There is folder called CV2 with subfolders of some python versions. Installing using command
pip install opencv-contribute-python
give me totally no result. How to install this im going out of my minds.

Solved this. Found that opencv has problems with latest release of python.
Uninstalled everything and installed version 3.9 and its just working. It took me whole night fighting with this problem I hope it can help somebody.

Related

Import cv2 error but opencv-python is already installed

I've been trying to make a project with opencv, so I followed the YouTube video (It's in python), the video told me to go to cmd (win10) and use the command "pip install opencv-python" so that I can use the command import cv2. But the problem is after I did everything it still gave me an error.
I've done some research on it and nothing seem to work. I tried restarting my laptop or reinstall opencv, but nothing works for me. I'm thinking maybe it's because the PATH was wrong so it couldn't access it? But I've never worked with these before so I don't know what I'm supposed to do. I've seen some people with the same problem but the solution doesn't seem to work.
I'm using:
python 3.10.8
windows 10
IDLE Shell 3.10.1
Welcome to Stack Overflow!
Try installing with pip3
pip3 install opencv-python

Problem importing modul OpenCV in Anaconda

I am a beginner in terms of using python. Currently, I got python 3.7 and I am using anaconda as IDE. For my project, I need to detect the location and brightness of points/dots in an external imported picture. I figure I could use the modul OpenCV. Unfortunately, I am stuck right now with the problem to import the module cv2. I already successfully installed the package using
python -m pip install OpenCV-python
on command prompt. OpenCV Version which was installed is 4.2.0.34. While compiling the test script of OpenCV on Spyder
import cv2
print(cv2.__version__)
I got this message
"ImportError : DLL load failed : The Modul was not found."
Can somebody let me know please how to fix this problem? Is somehow the version of OpenCV I got not compatible with the Python version? I already watched and followed many tutorial videos on Youtube, but I couldn't find the solution. I tried to copy the cv2.pyd to the site-packages folder in
C:/user/Anaconda3/Lib/site-packages directory
still it didn't fix the problem...
I would appreciate any answers and help I could get here. Thank you!
try installing it using these commands in the following order:
conda update anaconda-navigator
conda update navigator-updater
pip install opencv-python
It should work fine.
Try conda install opencv
or conda install -c menpo opencv

Installed OpenCV not working on PyCharms Python 3.8 project

I know there's a lot of answers related to this question, but I really couldn't find the answer so I'm here.
The problem started when I saw cv2 doesn't import on Python 3.8. So I found there's OpenCV whl file available for Python 3.8, I downloaded the whl file, pip installed into Python 3.8 using command:
python3.8 -m pip install opencv_python-4.1.2.30-cp38-cp38-macosx_10_9_x86_64.whl
I confirmed it works on Terminal I opened Python3.8 and entered command: import cv2
And it imported just fine, but when I try import cv2 on my PyCharm project this message keeps showing:
Error message
I looked everywhere and I really can't find answer anymore. If anyone can help me I would be very thankful.

PyCharm code completion doesn't work for installed libraries

I am using PyCharm community edition 2018.2.
Code completion works fine but just for installed modules if I install external library code completion doesn't work for them. However I have no problem with running code based on them.
I checked that my PyCharm is not in the 'PowerSafeMode'.
I have created project both for main and local Python interpreter.
In the IDE I also try to select installed libraries as a source.
I tried this for PIL library and OpenCV library.
Anyone has and idea what I might be missing or doing wrong?
Didn't you installed opencv via terminal?
For example, like this.
$ pip install opencv-python
$ pip install opencv-contrib-python
When I installed opencv through terminal, experienced the same problem.
If so, please try this.
1.Create new Pycharm Project, with new environment using Virtualenv.
2.Install opencv through Pycharm.
File -> Settings... -> Project interpreter -> +

OpenCV: AttributeError: module 'cv2' has no attribute 'face'

I am creating a face recognition system using Python and OpenCV on these versions:
Python 3.6.2 :: Anaconda custom (64-bit)
Anaconda 4.3.23
OpenCV 3.3.0
When I try to train the face recognizer:
face_recognizer = cv2.face.createLBPHFaceRecognizer()
I get this error:
AttributeError: module 'cv2' has no attribute 'face'
Update:
I've tried to do this:
pip install opencv_python‑3.3.0+contrib‑cp36‑cp36m‑win_amd64.whl
Also:
conda install -c menpo opencv3=3.3.0
And I still have the error.
The Menpo project does not have an installer for OpenCV 3.3. The Menpo project is up to 3.1 on macOS and Windows, and 3.2 on Linux. See the Anaconda package for that description and also the list of files for the installer versions. Actually, you can check out the GitHub repo for Menpo's OpenCV3 build and grab the files yourself. You can change the build files to suit your system if needed.
I'm not sure if your pip attempt includes a typo or not---the correct PyPI package wheel file with the contrib module is opencv_contrib_python not opencv_python+contrib, as shown at PyPI. Note that if you're not using Windows the GUI features of OpenCV will not work with the pip installer, including imshow() and other similar features.
You'd be better served just removing and reinstalling fresh with the contrib modules instead of trying to build them in later.
While I was looking for the same solution, I tried out many methods which don't work well with successfully installing OpenCV along with the extra modules i.e., OpenCV Contrib.
Apparently, while using pip install opencv-python windows platforms usually download only OpenCV without the extra modules!
What works, is stable and easy to install:
Download the integrated 'whl' file containing both OpenCV and it's Contrib files, which would be like 'opencv_python‑3.4.3+contrib‑cp36‑cp36m‑win_amd64.whl' which can be downloaded from here.
Install using pip install <whl filename>
I have tried other methods which are unreliable such as the solution suggested by #RoyaumeIX, however ended up with failure.
So is it with using
pip install opencv
pip install opencv-contrib
Installing opencv-contrib does not properly register the opencv package.
I strongly suggest that you directly download the official whl file and install it.
I also had same problem but it got resolved by following these steps:
start anaconda navigator
open CMD.exe prompt, hope you see this **(base) C:\Users\acer>** this may be different for you
write these command >>>**pip install opencv-contrib-python**
Now you can run your code as check!! I have runned my code in Spyder in base enviroment and it worked for me!
my using python 2.7 and opencv 3.3.0
working in code
cv2.face.LBPHFaceRecognizer_create();
Solution, as were found at OpenCV forum (and same at StackOverflow), works well for me:
pip install opencv-python
pip install opencv_contrib_python
And in cv2 version 4.0.0 face recogniser can be created by using different function name, as mentionted above:
face_recognizer = cv2.face.LBPHFaceRecognizer_create()
face_recognizer = cv2.face.EigenFaceRecognizer_create()
face_recognizer = cv2.face.FisherFaceRecognizer_create()
this should fix the problem
pip install opencv-python-headless
pip install opencv-contrib-python-headless
I found the solution to my issue, you have to follow this tutorial OpenCV with extra modules.
The essential steps are:
Go to C:/PythonXX/lib/site-packeges (the site-packages folder where your python is installed), and delete cv2.pyd if present.
Download OpenCV with extra modules
Create a Visual Studio project with CMake
Open Python IDLE and enter import cv2. If there is no error, then the installation is successful.

Categories