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
Related
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.
My code keeps breaking only at points where I use the cv2.imshow() function. It displays this error:
error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'
It was working fine until after I installed another library, but I'm not sure how that would mess it up. I tried uninstalling that extra library but that didn't do anything to fix the issue. Any ideas? Some of the solutions I've found online are to install with pip install opencv-python, but that's how I installed it initially. I have also tried uninstalling and reinstalling opencv to no avail.
Additional details based on follow-up questions: I'm on a Windows computer using the Pycharm IDE, and I've been installing libraries using pip in the Miniconda app.
Here is what the code looks like. The error happens anytime I try to use imshow, so here's one example of code I run that causes the error:
import cv2
img = cv2.imread("Tropical-tree.jpg")
cv2.imshow("Image", img)
cv2.waitKey(0)
For future reference if anyone else has this issue, here's how I solved it
I had been using an environment I made in the Miniconda3 program. To fix the issue, I made a new environment (also in Miniconda) using this command:
conda create --name new_env python=3.6
Opencv works best with python 3.6 rather than the newest update, so it's important to specify the version when creating the environment. Then I went in the environment and reinstalled opencv using pip install opencv-python, and then in Pycharm I switched to use that environment and it worked fine. Hope this helps anyone else who runs into this!
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.
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.
I'm trying to get opencv for python on my mac running mavericks. After googling/stack overflow seraching I tried:
brew install homebrew/science/opencv
Based on the terminal output it looks like that worked.
To verify I wrote a python script that simply contains:
import cv2
print("Hello")
I get no module named cv2. When I try looking at the installed modules by typing help('modules') I don't see cv or cv2. This leaves me with two conclusions: either I didn't properly install opencv or import cv2 isn't actually importing cv2 and python is looking in the wrong location for cv2. Any suggestions would be appreciated.
According to this guide, if you add the following to your .bash_profile it should fix your issue:
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
You could update your pythonpath,
but you would probably be better served running 'brew install python' so that you are not using system python. System python and brewed python look for modules in different locations.
EDIT:
Asked questions, updated the above.
This worked for me. Install X code from App Store.
Uninstall Homebrew
Uninstall and clean Anaconda
Reinstall Anaconda and Homebrew
Install OpenCV using conda install -c menpo opencv3
It should be good to go. Remember import it as import cv2
In case of any library errors try this conda install -c conda-forge basemap fiona
Hope it helped