I am a beginner to programming and so as I was following a tutorial I had to download opencv-python. So I followed all the steps and downloaded it.
opencv-python 4.3.0.38
That is what is displayed on my terminal(mac) when I check to see if opencv is installed or not using the command pip list | grep opencv
So I write a test code(on pycharm)
import cv2
print('Code Completed')
it works fine and prints out Code Completed, but when I run the same code on terminal(I am on the correct directory) using the command python Face_Detector.py it displays an error message saying
Traceback (most recent call last):
File "Face_Detector.py", line 1, in <module>
import cv2
ImportError: No module named cv2
How do I resolve this issue?
Any help would be greatly appreciated.
run this in the terminal where you work this will add the path and directory directly to the terminal you are using maybe it's happening because of the environment path
pip install opencv-python
Related
I'm working with intel's openvino 2020.
I get this error I searched and tried a lot of solutions online, but It didn't work.
and honestly, I'm new to working with python, openvino. So I don't really understand the error.
this is the error:
Traceback (most recent call last):
File "face_recognition_demo.py", line 27, in <module>
from ie_module import InferenceContext
File "C:\Program Files (x86)\Intel\openvino_2020.3.194\deployment_tools\open_model_zoo\demos\python_demos\face_recognition_demo\ie_module.py", line 20, in <module>
from openvino.inference_engine import IECore
File "C:\Program Files (x86)\Intel\openvino\python\python3.6\openvino\inference_engine\__init__.py", line 1, in <module>
from .ie_api import *
ImportError: DLL load failed: Le module spécifié est introuvable.
my imports:
import logging as log
import os.path as osp
import sys
import time
from argparse import ArgumentParser
import cv2
import numpy as np
from ie_module import InferenceContext
from landmarks_detector import LandmarksDetector
from face_detector import FaceDetector
from faces_database import FacesDatabase
from face_identifier import FaceIdentifier
I hope you can help me
Have you verified your installation of OpenVINO by running the Image Classification Verification Script? Refer to the documentation from the link below and please verify your installation first since this error looks like a configuration mistake in the environment.
https://docs.openvinotoolkit.org/2020.3/_docs_install_guides_installing_openvino_windows.html#Using-Demo-Scripts
Make sure to complete all steps given on the Installation Guide for Windows. Once verified done, then you can run the Interactive Face Recognition Demo. Here is the workaround to run the demo:
Setup OpenVINO environment.
cd <INSTALL_DIR>\openvino_2020.3.194\deployment_tools\bin
Run setupvars.bat
2.Navigate to the face recognition demo folder
cd <INSTALL_DIR>\openvino_2020.3.194\deployment_tools\open_model_zoo\demos\python_demos\face_recognition_demo
Run pip install -r requirement.txt
Run the demo
python./face_recognition_demo.py -m_fd "<INSTALL_DIR>\openvino_2020.3.194\deployment_tools\tools
model_downloader\intel\face-detection-retails-0004\FP16\face-detection-retail-0004.xml" -m_lm "<INSTALL_DIR>\openvino_2020.3.194\deployment_tools\tools
model_downloader\intel\landmarks-regression-retail-0009\FP16\landmarks-regression-retail-0009.xml" -m_reid "<INSTALL_DIR>\openvino_2020.3.194\deployment_tools\tools
model_downloader\intel\face-reidentification-retail-0095\FP16\face-reidentification-retail-0095.xml" -i 0 -fg "<IMAGE_DIR>\Pictures\image_name"
Check out the Interactive Face Recognition Demo documentation for more details.
Could you please reinstall the OpenVINO 2020.3 and run the verification script successfully. Then, follow again steps from the previous reply since I have validated this on my side and everything works fine. Make sure you restart your computer after the installation of OpenVINO and Microsoft Visual Studio.
so yeah I followed these steps
Setup OpenVINO environment.
cd <INSTALL_DIR>\openvino_2020.3.194\deployment_tools\bin
setupvars.bat
result:
runnigsetupvars
so I always get this warning about the libmmd.dll, again I researched for a solution, but I couldn't find the source of this problem.
2.Navigate to the face recognition demo folder
cd <INSTALL_DIR>\openvino_2020.3.194\deployment_tools\open_model_zoo\demos\python_demos\face_recognition_demo
`pip install -r requirements.txt`
results
and finallyerror
now I get this error, although OpenCV-python is downloaded, I tried to follow this solution I found:
pip uninstall opencv-python
opencv-contrib-python
but the same cv2 error is showing
I'm using anaconda with spyder on Win 10. I installed opencv by pip-install opencv-python.
If I do
import cv2
in the default directory (C:\ProgramData\Anaconda3), it will work.
However, if I do the same command anywhere else I'll have an error :
import cv2
Traceback (most recent call last):
File "<ipython-input-3-c8ec22b3e787>", line 1, in <module>
import cv2
ImportError: DLL load failed: Le module spécifié est introuvable.
If I want to run a script which needs cv2, I have to go in C:\ProgramData\Anaconda3 , then import cv2 and finally run my script in whatever directory I want.
I don't have this problem with other modules, like pygame or pillow.
This may be because the IDE may contain many Interpreter and the cv2 library is not installed for the python Interpreter which is set for the system, try to install the cv2 with command prompt using pip install opencv-python. then it may work for you from any location.
Ok, thanks to Abhishek-Saini.
Following this video where pip directory is added to PATH, I added C:\opencv\build\x64\vc15\bin to path. And, it works ! (for now, then)
While running a simple code on Open CV:
import cv2
import freenect
device = cv2.CV_CAP_OPENNI
capture = cv2.VideoCapture(device)
While running the above python code.I am getting following error:
Traceback (most recent call last):
File "hello.py", line 4, in <module>
device = cv2.CV_CAP_OPENNI
AttributeError: 'module' object has no attribute 'CV_CAP_OPENNI'
Please look into the code
I have already installed OPENNI.
Thanks in advance.
Try cv2.CAP_OPENNI instead of cv2.CV_CAP_OPENNI
To make it work properly, the installation should be proper and the method is as follows:
Make is using the proper repository. The link to the repository is:
https://github.com/jmendeth/PyOpenNI
You can directly use the code below to download and make
git clone https://github.com/jmendeth/PyOpenNI.git
mkdir PyOpenNI-build
cd PyOpenNI-build
cmake ../PyOpenNI
After installing, dont use "make install", instead copy the lib/openni.so found in the folder you have installed(PyOpenNI-build if you have used the above code to install).
Finally copy it your python install folder. In my case "/usr/lib/python2.7/dist-packages".
Testing
Test using the following python code:
import openni
Now the above code will also start running.
I'm using Kivy on Mac OS X. I installed opencv under Kivy's virtualenv. But then when I tried
import cv2
it gave me this Import Error:
Traceback (most recent call last):
File "", line 1, in
ImportError: dlopen(/Applications/Kivy.app/Contents/Resources/venv/lib/python2.7/site-packages/cv2.so, 2): Library not loaded: lib/libopencv_reg.3.1.dylib
Referenced from: /Applications/Kivy.app/Contents/Resources/venv/lib/python2.7/site-packages/cv2.so
Reason: image not found
But if I move to: cd /path/to/opencv/build
then run python and import cv2, it works fine.
It looks like Python couldn't find the library files from the build/lib directory.
Everything looked fine during the cmake bulding and installation process. What am I missing here?
Thank you!!
So my case is a tricky one.
I first installed OpenCV2.4.8 and started it using for python2.7. Later I planned to migrate to OpenCV3.0.0. Both the times during installation I followed the official documentation procedure. Everything was working fine until I realized that OpenCV3 doesn't have SIFT() and SURF() modules. After a bit of searching I found they are present in opencv_contrib. First I tried to install that but for some reason I couldn't.
Later I found that these modules are present in OpenCV2.4.11 and planned to install that. Again following the official procedure I installed OpenCV2.4.11 got the same SIFT() importerror. Upon checking the OpenCV __version__ in python2 and python3 I found the following
python2: "2.4.8"
python3: "3.0.0"
For checking the version I used the following code:
from cv2 import __version__
print(__version__)
Unfortunately I don't have a lot of memory in /home, so I had deleted OpenCV2.4.8 and OpenCV3.0.0 build folders after installing. Therefore, I tried to manually remove OpenCV2.4.8 and OpenCV3.0.0 and deleted all opencv the libs from /usr/local/libs/ and sub-directories and all the opencv bins from /usr/local/bins/ (following answer in this question).
After removing all opencv files I again reinstalled OpenCV2.4.11 and tried to run my code. It failed at the import step in python2 giving
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libopencv_core.so.2.4: cannot open shared object file: No such file or directory
in python3
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libopencv_core.so.3.0: cannot open shared object file: No such file or directory
I again checked if OpenCV2.4.11 is present or not and its there but the python hasn't updated the previously stored link to opencv lib. I'm stuck at this error since 2 days with no solution. Any help will be appreciated.
EDIT:
Is there some shared library lookup file which python uses to store all the locations of shared libraries? If not how does this work (how python recognizes where to look for opencv as opencv is not listed in pip freeze)
EDIT2:
I found another mistake. I hadn't enabled -D BUILD_SHARED_LIBS=ON before. This time I kept it ON and rand sudo ldconfig after make and make install. Now I have a libopencv_core.so.2.4 in my /usr/local/lib/. It is a symlink to libopencv_core.so.2.4.11 present in the same folder. After ldconfig when I checked for python2 import cv2 didn't show any error but __version__ still shows '2.4.8'. I double checked for any OpenCV2.4.8 .so file and there are none. How is it still pointing to version '2.4.8'?
Steps for removal:
remove opencv libs by : sudo apt-get purge libopencv*
Verify that whether cv2 is uninstalled by trying import cv2 in python. It should show no cv2 module present
Install opencv2.4.11 by following this sh file
Run sudo ldconfig after sudo make install
Things should usually work but it didn't work in my case because cv2.so was missing from /usr/local/lib/python2.7/dist-packages/. For that manually copy from /<opencv-2.4.11 unzip locaiton>/release/lib/cv2.so to /usr/local/lib/python2.7/dist-packages/. Use sudo for permissions.
Now import cv2 will work and __version__ is '2.4.11'.