I already copy the cv2 and complete the procedure installing opencv and python and I also think the default python installation is usr/lib64/python2.7 and there is also usr/lib/python2.7 and I also move the cv2 using copy -r usr/lib/python2.7/site-packages/cv2.so to usr/lib64/python2.7/site-packages/ it successfully move but when I run the $python
import cv2 [this is what happen1
am still wondering if there is a default directory for centos 64 bit or i did wrong on my steps? I followed this tutorial http://techieroop.com/install-opencv-in-centos/ and i find it simple and fast yet im still stuck installing opencv
Do the following
yum install numpy opencv*
yum check-update
then
import cv2
print cv2.__version__
Related
Using python3, I am unable to import the imageio module into my python program, which I need, as I try to animate a list of PNG images I have. Thus far I have tried:
"pip3 install imageio" both running as myself and as root. The install succeeded, but it still errors out as in the subject line. I suppose I could try "apt-get install (package name)", but need to determine the package_name.
Any ideas more than welcome - TIA.
Try importing the last version.
import imageio.v3 as iio
im = iio.imread('imageio:chelsea.png')
print(im.shape) # (300, 451, 3)
ref https://imageio.readthedocs.io/en/stable/examples.html
I'm running Ubuntu 18.04LTS:
Firstly, I couldn't install opencv from anaconda on my existing environment (base) as it kept searching for conflicts forever and then getting stuck with an empty window saying "these packages will be modified" while displaying absolutely nothing and with the only choice of pressing the "cancel" button.
I created a new virtual environment named env_opencv and was able to install opencv:
enter image description here
Then, I run a jupyter notebook that imports opencv:
import cv2
import matplotlib.pyplot as plt
import matplotlib.patches as patches
...
And here's what I get:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-8-31cd2c78c525> in <module>
----> 1 import cv2
2 import matplotlib.pyplot as plt
3 import matplotlib.patches as patches
4
5 from align import AlignDlib
ModuleNotFoundError: No module named 'cv2'
No matter what I tried, including reinstalling opencv directly from the conda prompt, I can't get past this error.
Incidentally, I was able to make it work on Windows 10 going through the Anaconda prompt and using conda. However, my Windows machine doesn't have an nVidia GPU and I can't use it for CNN training, so I really need to make it work on Ubuntu.
Any suggestions would be great. Thank you.
I found a workaround to this issue:
I activate the env_opencv environment from the command line, then I launch jupyter notebook and it works.
Maybe, there is a bug with anaconda-navigator that doesn't seem to switch environments from the GUI?
When I try:
>>> from skimage import io
I get at the end the following:
from ..color import rgb2gray
ImportError: cannot import name 'rgb2gray' from 'skimage.color' (C:\Users\user\A
ppData\Local\Programs\Python\Python37-32\lib\site-packages\skimage\color\__init_
_.py)
Although I have installed the packages: matplotlib, scipy, pillow, numpy and six
How can I fix it? Any help would be appreciated
In case you run into this error from inside a Jupyter Notebook, try restarting the kernel as suggested in this GitHub issue.
That solved the problem for me.
It looks like you haven't installed scikit-image package.
Try this on terminal:
pip install -U scikit-image
And then try importing like this:
from skimage import io
from skimage.color import rgb2gray
If you still got the error or you have installed the package previously,
try reinstalling the package first.
If it still don't resolve your issue, then try updating the following packages:
matplotlib, scipy, pil, numpy and six
However, try not to import all of the subpackages to improve loading time. You can however try something like:
from skimage import color
...
gray_img = color.rgb2gray(img)
If you still got errors, make sure that you are using the correct python kernel and dependent modules are updated and installed.
If that did not help either, then try Anaconda, it come with many pre-installed packages.
Leave a comment if you still have a problem :)
three ways to convert RGB2Gray:
opencv:
import cv2
img=cv2.imread("file.jpg",0) [enter link description here][1]
or you can do this:
img=cv2.imread("file.jpg")
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cv2.COLOR_BGR2GRAY beacause it reads BGR mode.
another methods you can look this link:
enter link description here
It happened to me once when I import skimage using env conda on Jupyter. I installed by pip or conda in env, that error happened. However, after restart the Jupyter, it worked.
I searched how to predict my own digit image using Google TensorFlow.
I used 64bit Red Hat Linux.
I installed Python3.4.3, other related development environments and TensorFlow version 0.6.0.
Then, I tried to write code for digit prediction.
Firstly, I need to read images in my python program.
So, I searched how to read images in python then I found OpenCV (http://opencv.org/)
I installed OpenCV(version:3.1.0) using cmake.
After installing OpenCV, I tried to import cv2(OpenCV function) in order to read image.
But I cannot import cv2 and ImportError occured as the following.
ImportError: No module named 'cv2'
I tried to solve this problem by changing default PYTHONPATH.
For example:
export PYTHONPATH=/usr/local/python/lib/python3.4/site-packages:$PYTHONPATH
I tried to add some code in my python program.
import sys
sys.path.append('/usr/local/python/lib/python3.4')
But the above two steps cannot solve the problem ImportError: No module named 'cv2'.
So, I search how to solve this problem and I tried to solve with many other ways. But no success.
How can I import cv2 in my python program?
OpenCV Installation steps are as follow:
>>> yum install cmake
** Download OpenCV latest version from it's official site **
>>> cd /directory of OpenCV/
>>> mkdir release
>>> cd release
>>> cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..
>>> make && make install
>>> echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf
>>> ldconfig
>>> echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig" >> /etc/bash.bashrc
>>> echo "export PKG_CONFIG_PATH" >> /etc/bash.bashrc
This doesn't directly answer your question—perhaps an OpenCV expert can help with that—but TensorFlow includes reasonably comprehensive support for manipulating images. If your images are in JPEG format you can use tf.image.decode_jpeg() to convert them to tensors; likewise tf.image.decode_png() supports PNG images.
I'm trying to run my code and I don't know what specific package I need in order to get my import statement to work. Below is my header and I keep getting an error saying ImportError no module named statistics. I have looked at a bunch of different pages to see where I can download a solution, but I am trapped. I know my code works because I ran it on my schools lab. If anyone can help, that' be great!
Just note I am a beginner and am using Linux on my virtual machine with Python 2.7
import sys
import requests
import matplotlib.pyplot as plt
import statistics as stat
Statistics "A Python 2.* port of 3.4 Statistics Module" (PyPI).
If you use 2.7.9, you will have pip installed, and pip install statistics within the 2.7 directory should install the module for 2.7 (I am not a pip or virtual machine expert, so might be slightly off.)
It comes pre-installed in python --Version 3. To import in python version 2 in Ubuntu, open Terminal and type
sudo pip install statistics
Enter your password and it will get installed.
Ps: you need to have pip already installed.
You need to be using python 3.4 to import statistics. Upgrade to the current version and you should have no problems.