I am trying to use OpenCV 3.0 with Anaconda Python3.4. I compiled the opencv sources from Github together with the accompanying opencv_contrib repository and installed them inside a local directory.
Now, starting python I am able to import the cv2 module and do stuff like loading and displaying images. However it seems that the submodule xfeatures2d doesn't exist.
>>> import cv2
>>> cv2.xfeatures2d
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'xfeatures2d'
Interestingly I get no error if I try to import cv2.xfeatures2d (although I still can't use it then)
The shared library file exists in ~/MyOpenCV3Install/lib/libopencv_xfeatures2d.so.3.0.0. My first guess was that it is not being loaded for some reason, so I tried to force it using the LD_PRELOAD environment variable prior to launching python. However still no luck so far.
For me it doesn't work using the python3.4 environment. However, when using a python2.7 environment everything works just fine. After importing the cv2 module I can call functions like cv2.xfeatures2d.SURF_create() without errors.
Does anybody have an idea why the xfeatures2d submodule is not available when using python3.4? Is it possible that the python bindings created for opencv_contrib are not compatible with python3 yet?
EDIT:
I used the following options for the cmake configuration step:
BUILD_opencv_python3=ON
PYTHON3_EXECUTABLE=/home/mi/anaconda/envs/env3.4/bin/python3.4
PYTHON3_INCLUDE_DIR=/home/mi/anaconda/envs/env3.4/include/python3.4.m
PYTHON3_LIBRARY=/home/mi/anaconda/envs/env3.4/lib/libpython3.4m.so
PYTHON3_NUMPY_INCLUDE_DIR=/home/mi/anaconda/envs/env3.4/lib/python3.4/site-packages/numpy/core/include
PYTHON3_PACKAGES_PATH=/home/mi/anaconda/envs/env3.4/lib/python3.4/site-packages
Related
I have installed caffe from source. I have used the Cmake for installation. I have updated the respective paths as well.
My caffe root directory is: /home/ashj/caffe
I have updated the PYTHON path as:
export PYTHONPATH=<caffe-home>/python:$PYTHONPATH
which is by using
**export PYTHONPATH=/home/ashj/caffe/python:$PYTHONPATH**
I could load import the module caffe. However I am not able to access any methods or any layers inside the caffe like set_mode_gpu(), set_mode_cpu() or layers or params. I am getting errors like:
When I used
import caffe
caffe.set_mode_gpu()
I am getting following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'caffe' has no attribute 'set_mode_gpu'
PS: I have also tried using caffe.__caffe.set_mode_gpu() as mentioned in this link. but it is not working for me.
My system specs: Ubuntu 18.04
TIA
Though may be late, but I encountered this same problem and found a way work around:
sys.path.insert(0, '/path/to/caffe/python')
import caffe
caffe.set_mode_gpu()
namely, add the caffe/pathon path to you sys.path before import caffe.
Wrote a post here for detailed analysis, hope helpful.
This problem may be the results of package caffe's path.
For me, if I do the following from the Ubuntu Terminal, everything goes fine:
but if I do from the Pycharm IDE, errors occur:
note that I tested the package caffe's path in both ways, and got different results:
- in the Ubuntu terminal, namely the way which goes fine, I got
'/home/CVAR-B/softwares/caffe/caffe/python/caffe/__init__.pyc'
which is the expected result;
- in the Pycharm IDE way, namely the way error occurs, I got
'/usr/local/lib/python2.7/dist-packages/caffe/__init__.pyc'
which is not the expected result.
In view of this discovery, I did this one more thing to handle the error:
sys.path.insert(0, '/path/to/caffe/python')
import caffe
caffe.set_mode_gpu()
namely, add the caffe/pathon path to you sys.path before import caffe.
and the result shows this can be a workaround:
(source: ax2x.com)
See the caffe.__file__'s result, now returns the expected path.
Try these steps and then set your python PATH:
You might've already done steps 1 and 3.
make all
make pycaffe
make distribute
mkdir ~/python
mv distribute/python/caffe ~/python
Set your PYTHONPATH after this — this should be some dir like caffe/python/caffe
I am using the tensorflow object detection api from https://github.com/tensorflow/models and I am trying to make an object detection program using open cv with tensorflow. When the code reaches at line 30 (see code below), the program will get an error and will print:
Traceback (most recent call last):
File "C:\Users\xxx\Documents\models\research\object_detection\object_detection.py", line 31, in
from object_detection.utils import ops as utils_ops
File "C:\Users\xxx\Documents\models\research\object_detection\object_detection.py", line 31, in
from object_detection.utils import ops as utils_ops
ImportError: No module named 'object_detection.utils'; 'object_detection' is not a package
I tried the solutions that are in this link (Tensorflow Object Detection API on Windows - error "ModuleNotFoundError: No module named 'utils'") step by step, but it still didn't work. I don't know what should be targeted in order to solve this problem. Also, I am not that familiar with machine learning, tensorflow, and opencv, I just start learning it now. Can anyone please help me with this? Thanks in advance.
Btw, this is the part of the code where I got a problem with.
# This is needed since the notebook is stored in the object_detection folder.
sys.path.append("..")
from object_detection.utils import ops as utils_ops
I tried the 'export path' method on python and the 'Develop' method for Conda but nothing worked.
Finally tried installing this API and the tutorial worked. Maybe I missed this step during the installation. You try this too
pip install tensorflow-object-detection-api
I have followed below steps:
For every new terminal, append PYTHONPATH as follows:
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
from directory C:\Users\xxx\Documents\models\research
Else, add that particular line to ~/.bashrc file in order to avoid running for every new terminal.
I successfully installed dlib for python, following instructions here. However, when I try to import the library I get this message:
>>> import dlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/dlib/__init__.py", line 1, in <module>
from .dlib import *
ImportError: dlopen(/usr/local/lib/python2.7/site-packages/dlib/dlib.so, 2): Library not loaded: #rpath/libpng16.16.dylib
Referenced from: /usr/local/lib/python2.7/site-packages/dlib/dlib.so
Reason: image not found
I previously had(and uninstalled) anaconda and had the same issue in python 3.6. Looking at similar questions and responses it sounds like I would have to use install_name_tool command. However I do not know what the new path would be. I do not quite understand why this is necessary either. From what I know, the path that was referenced should have been fine. Why will dlib not import and what can I do to make it import successfully? Let me know. Thanks
I don't know if I would call this a solution, since I still have issues, but what I did was: install_name_tool -change #rpath/libpng16.16.dylib "/Library/Python/2.7/site-packages/dlib/dlib.so" /usr/local/lib/python2.7/site-packages/dlib/dlib.so
Although there was an additional problem with my installation, this fixed the problem at hand. I had dlib in my default python library rather than with a path similar to one in my virtual machine. So I changed the path to fit my VM and all my other installation packages(e.g boost and cmake)
I'm using Blender 2.78 (64bit) with Python 3.5.2 on Windows 7 (64bit). My situation is that I want to use opencv in combination with python in Blender. I went in serious trouble trying so and was working for days without any obvious success..
However from googling I found that there is a way to install pip as a module for blenders python and with pip I was able to install modules such as numpy oder scipy. This indeed also worked with opencv as it got successfully installed (including positive checks). It looked fine. But as I tried to import cv2 in a Console in Blender I got the error like the thread starter above:
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
File "C:\Program Files\Blender Foundation\Blender\2.78\python\lib\site-packages\cv2\__init__.py", line 7, in <module>
from . import cv2
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
I then tried to start blender python in an external shell and retried the import process resulting in the same error.
Next was retrying the complete procedure for my system python (same version 3.5.2) and everything worked perfectly.
From now on I was a bit confused as "pypi.python.org/pypi/opencv-python" towards opencv-python states that everything is linked statically and everything you have to do is what I have done. Looking in the FAQ the error is mentioned. You get the advise to check visual c++ redistributable and c runtime library. I did so, however, both is up to date and on system python opencv works perfectly that way.
Next try. As the system python works perfectly with opencv I removed blender python and pasted a copy of the system python instead. According to "blender.stackexchange.com/questions/5287/using-3rd-party-python-modules"
this is an alternative from using blenders own python.
Numpy, Scipy imports work perfectly. Importing cv2 leads to the same error as before.
If I now start the system-python copy that now is blenders python from a command shell cv2 can be imported.
Where is the difference here in the environment blender creates and the one from the shell??
I have installed a tool named listDlls to list all the dlls loaded by specific processes in order to compare blender-python and python. You can see some differences but I dont understand the matter of those except from the absence of the cv2 pyd in blenders python.
Any ideas?
First list is the python-process list, second the blender list:
https://ufile.io/uidy1
https://ufile.io/1eshi
I'm getting the error
Traceback (most recent call last):
File "ghs.py", line 1, in <module>
import stdio
ImportError: No module named stdio
When I try to run my script. I can run my script on other machines just fine. I have installed python using homebrew. And I've tried everything I can think of to get it to recognize my modules! I've uninstalled and reinstalled using brew. I've tried changing the path (though I don't fully understand this). I get no issues using brew doctor.
I've also tried using a python virtual environment but to no avail.
Any ideas on how to fix this issue or else 'start fresh' from a fresh version of python?
When you import a module, Python looks for it at the directory your code is, and the directory in which the built-in libraries are (C:\Users\pc\AppData\Local\Programs\Python\Python35-32\Lib in my case, I'm using Windows 10 and Python 3.5). If it can't find it, it raises ImportError.
I couldn't find a module named stdio in my computer. I also know some C++ and as far as I know, stdio is the library for inputs and outputs(prints). In python, there is no need to import such a library.
You can use try,except statement to test if your code works without importing the module like this.
try:
import stdio
except:
#rest of your code goes here
You will need to indent your whole code however this can be done easily with a text editor in which you can edit more than one line at a time.