Hi friends i just now installed opencv and checking the basic code but it results in error. The code is
import numpy as np
import cv2
img=cv2.imread('C:UsersPravinDesktopa.jpeg',1)
cv2.namedWindow('img',cv2.WINDOW_NORMAL)
cv2.Waitkey(10000)
cv2.imshow('cv2.WINDOW_NORMAL',img)
cv2.destoryAllWindows()
The error for cv2.imshow() is
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
cv2.imshow('image',img)
error: ......srcopencvmoduleshighguisrcwindow.cpp:261: error: (-215)
size.width>0 && size.height>0
It was very helpful to me with your answer.
Thanks in advance
asked Apr 3, 2014 at 6:10
1
Most likely, the imread call didn’t succeed. Make sure the image «C:UsersPravinDesktopa.jpeg» exists. (The extension .jpeg seems unusual, maybe it has to be .jpg?)
Also, as Hyperboreus suggests, please, try using forward slashes in the filename «C:/Users/Pravin/Desktop/a.jpg», or escape backslashes
"C:\Users\Pravin\Desktop\a.jpg"
answered Apr 3, 2014 at 6:18
Sergei NosovSergei Nosov
1,63711 silver badges9 bronze badges
3
The error says that the image you opened doesn’t satisfy the condition height > 0
and width > 0
. This may have several reasons.
Most of the times, it is due to an inexistent image address given in imread
.
Sometimes it may be also because the complier failed to load the image. For example, if you write some random strings in notepad and save the file as a.jpg
, the compiler may not be able to load it.
answered Aug 9, 2015 at 1:36
Pranav TotlaPranav Totla
2,0522 gold badges19 silver badges28 bronze badges
Try this…
import numpy as np
import cv2
img = cv2.imread('E:/Images/ece/1.png',1)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Tonechas
13.2k15 gold badges43 silver badges78 bronze badges
answered Mar 7, 2017 at 9:10
1
For me it worked when i just changed jpeg to jpg
Try this, may be it will work
import numpy as np
import cv2
img=cv2.imread('C:UsersPravinDesktopa.jpg',1) #changed image format to jpg
cv2.namedWindow('img',cv2.WINDOW_NORMAL)
cv2.Waitkey(10000)
cv2.imshow('cv2.WINDOW_NORMAL',img)
cv2.destoryAllWindows()
answered Sep 15, 2017 at 19:52
It is because, python compiler cannot find the image in the place. if you copy the image in the python working directory and do this. it worked for me.
# keep image in the current working directory
img=cv2.imread('roi.jpg',1)
cv2.imshow('image',img)
answered May 17, 2017 at 4:39
1
Although this is already answered, for me conda-forge solution worked with a hack.
My workstation is a centos 6 machine, and I use conda virtual environment (anaconda 2). Create an environment
conda create --name test python=2.7
and then activate it
conda activate test
Now install opencv from conda-forge
conda install -c conda-forge opencv
Now install matplotlib in this environment (and this is hack 1)
conda install matplotlib
Let’s check now imshow works or not. In a terminal, activate test environment and start python. In the interpreter, do
import cv2
import matplotlib.pyplot as plt # hack 2
img = cv2.imread('your_image_file',0)
cv2.imshow('image',img)
This should pop up a window showing image. I did not further research how this solved the case.
Note 1: You may see some error related to xkb, then in your .bashrc file add
export QT_XKB_CONFIG_ROOT=/usr/share/X11/xkb
Note 2: You may see some error related to XDG_RUNTIME_DIR, then in your .bashrc file also add
export XDG_RUNTIME_DIR=.tmp/myruntime
and define myruntime by mkdir -p .tmp/myruntime
This is the exact error that I am getting. My OS is Ubuntu 16.10.
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /feedstock_root/build_artefacts/work/opencv-3.1.0/modules/highgui/src/window.cpp, line 545
Traceback (most recent call last):
File «untitled.py», line 7, in
cv2.imshow(‘image’,img)
cv2.error: /feedstock_root/build_artefacts/work/opencv-3.1.0/modules/highgui/src/window.cpp:545: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon 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
my code is:
import numpy as np
import cv2
# Load an color image in grayscale
img = cv2.imread('0002.png',0)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
0002.png is an image in the same directory as the program.
I first installed anaconda with python 3.5, then I installed opencv by using the command
conda install -c conda-forge opencv
I installed libgtk2.0-dev just as the error said to but I still get the same error.
Any help would be much appreciated. I’ve been trying to solve this for several hours.
when using cv2.imread(),
when this error occurs, please check the following information:
is spelling error
is this picture
is added suffix
is 0 absolute path 1
2 what system is this?Consider changing the single slash to and double slash . In general, a backslash
is already supported
image_data = cv2.imread('D:\lab\AgriculturalDisease_trainingset\images\00c5c908-fc25-4710-a109-db143da23112___RS_Erly.B 7778.JPG')
in Windows how to check the address is correct, especially in the loop
can be copied directly in the Windows window, to see if you can read and display the picture.
then checks the address of the program, prints it out, and compares whether the two are the same.
if you encounter Chinese name can’t read, please refer to this website: Chinese path error problem
simply, is to directly rewrite the cv2.imread function, replace it with another function cv_imread:
def cv_imread(filePath):
cv_img=cv2.imdecode(np.fromfile(filePath,dtype=np.uint8),-1)
return cv_img
# The main citation section is as follows: (img_path needs to be given by yourself)
image_data = cv_imread(img_path)