I am currently using Anaconda 4.3.27, Python 3.6.2 and OpenCV 3.3.0
When I try
img1 = cv2.imread('D:\Images\3D-Matplotlib.png')
img2 = cv2.imread('D:\Images\mainsvmimage.png')
I get libpng error: Read Errorand a pop-up shows up, indicating that Python stopped working. I already tried replacing the '\' by '\\' and '/', but also in those cases the same error shows up. When I try to read a jpg instead of a png, I do not get the error. Does anybody have an idea what might be the problem here?
Thanks in advance!
Edit:
Also cv2.imwrite gives an error:
libpng error: Write Error
Had the same issue with Anaconda using Matplotlib with Latex. The solution was to update libpng.
https://github.com/ContinuumIO/anaconda-issues/issues/6271
try to add the flags (grayscale,...) that are required by cv2.imread ( https://docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html )
and use r for the path
img2 = cv2.imread(r"D:\Images\mainsvmimage.png",0)
( the 0 loads image as grayscale )
OpenCV Python not opening images with imread()
if this is still not working maybe test with another image as it is possible that there is a problem with the image header cf. libpng error: Read Error or with your libpng version, cf. Libpng conflict on OpenCV?
I had broken images in my directory, removing those images solved the error.
Related
I dont know what to import and how to do this. How do I print and add a image in python.
I have tried nothing im just looking for suggestions.
In the console it's impossible, but you can use OpenCV, PIL, or matplotlib to display images.
With OpenCV you can display the pixel value in the console:
If you are interested in image manipulation check out Pillow. It's an image manipulation/processing library.
You can install it with:
python -m pip install Pillow
To load an image and show it use this:
from PIL import Image
im = Image.open("image.png")
im.show()
For more examples and information check out the official documentation.
I am using the following line in my program
img = cv2.resize(img, dsize=(299, 299), interpolation=cv2.INTER_LINEAR)
It is giving the following error
AttributeError: module 'cv2' has no attribute 'resize'
The type of image img is <class 'imageio.core.util.Array'>
I checked the official documentation of OpenCV and it contains the attribute resize.
Where am I going wrong?
The issue occurred due to the erroneous installation of OpenCV.
Although the system is behaving as OpenCV was properly installed. It wasn't installed properly.
Uninstalling and installing OpenCV again solved the issue.
pip uninstall opencv-python
and then
pip install opencv-python
Maybe your cv2 import is not correct. In a Python console, try
import cv2
help(cv2.resize)
In case it does not show the description of the resize method, the import does not work properly. Your could also check help(cv2)which gives a long list of all methods and attributes contained in the module.
Are you working within a virtual environment that needs activation first?
I've been going round in circles for ages trying to figure this out. Why am I getting this attribute error? I've tried using absolute references, and get the same issue. PyCharm is also highlighting CascadeClassifier, cvtColor and COLOR_BGR2GRAY saying it cannot find reference in cv2.py. I'm not sure if more information is relevant to solving this problem, so please ask if more is needed.
import cv2
face_cascade = cv2.CascadeClassifier('read_only/haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('read_only/haarcascade_eye.xml')
grayed_images = []
for x in np_images:
gray_img = cv2.cvtColor(x, cv2.COLOR_BGR2GRAY)
grayed_images.append(gray_img)
print(x)
If I am correct, you are using an environment different from where you run.
Step1: In command line/terminal where you see the opencv-python when you run pip list:
run python command. Copy your code, check if it works (you can simply import cv2 alternatively)
If it works, my idea should be correct. Otherwise, there is something bigger.
Step 2: (Assuming step1 works.) In Pycharm, Under Run > Edit Configurations, change python interpreter to whichever interpreter is you are that has opencv.
Step2 better alternative: On Pycharm, open the terminal, pip install opencv-python. After that you should have the opencv.
Downgrade opencv to the version 4.5.5.64.
You can install opencv using
pip install opencv-python==4.5.5.64.
This works for me
I am trying to use scikit-image to do some research. The system is Windows 7 64bit, and the python version is 2.7, 64bit.
The first program I run is from: http://scikit-image.org/
The code is
from skimage import data, io, filter
image = data.coins() # or any NumPy array!
edges = filter.sobel(image)
io.imshow(edges)
io.show()
However, the problem happens, and the error message is:
C:\Python27\lib\site-packages\skimage\io_plugins\null_plugin.py:14:
RuntimeWarning: No plugin has been loaded. Please refer to
skimage.io.plugins()
for a list of available plugins.
warnings.warn(RuntimeWarning(message))
I believe that both Python and scikit-image are correctly installed. So, may I know what is wrong with it?
Any suggestion is appreciated. Many thanks.
Just had precisely the same issue on amazon linux. The issue is that skimage requires PIL, and PIL is not installed. In the latest skimage they added the dependency, but the version that I got installed with pip didn't have it yet.
The solution is
pip install Pillow
EDIT: and after that you will probably immediately face another issue, with skimage loading image, but not being able to read it (in particular, shape being empty tuple). Here's the solution
Why does scipy.ndimage.io.imread return PngImageFile, not an array of values
Please see the related question I posted earlier: While upgrading python imaging library (PIL), it tells me "JPEG support not available"
I have installed Pillow instead of PIL to get the Django-Simple-Captcha to work. The image now displays.
But as you can see at the bottom of this page, it is so badly distorted that it is basically unreadable and useless: http://predictstat.com/accounts/register/
I have no clue why this is happening now, nor how to fix it. Can someone please advise?
The cutoff happens because I'm using Pillow 2.2.2.
Django-simple-captcha seems to not play with that version of Pillow. So I installted Pillow 2.0 and the cut-off problem was solved! See: http://github.com/mbi/django-simple-captcha/pull/50