2

I am following this tutorial

The suggested code is:

import numpy as np
import cv2

# Load an color image in grayscale
img = cv2.imread('messi5.jpg',0)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

I want to load an image located in my desktop so I changed the

img = cv2.imread('messi5.jpg',0)

line to this line:

img = cv2.imread('/home/Desktop/1.jpg',0) 

when I run the code through terminal it produces error:

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/sohib/Documents/OpenCV/modules/highgui/src/window.cpp, line 312
Traceback (most recent call last):
  File "1.py", line 6, in <module>
    cv2.imshow('image',img)
cv2.error: /home/sohib/Documents/OpenCV/modules/highgui/src/window.cpp:312: error: (-215) size.width>0 && size.height>0 in function imshow

Have I included the wrong path to the image in the imread part?

How can I solve this issue?

Notes:

I am on Ubuntu 16.04.LTS

The tutorial documentation is for OpenCV 3.0.0, but I am using 3.2.0

2
  • I am pretty sure '/home/Desktop/1.jpg' does not exist. It should be '/home/yourname/Desktop/1.jpg', unless Desktop is your name :). don't use $HOME or ~. Mar 27, 2017 at 6:28
  • Great, I'll make it an answer. Mar 27, 2017 at 6:46

1 Answer 1

2

The path you are using

I am pretty sure '/home/Desktop/1.jpg' does not exist. It should be '/home/yourname/Desktop/1.jpg', unless Desktop is your name :).

Using paths in a python script in general

You are probably confusing /home with $HOME which you also cannot use, just like ~.

In a python script, you cannot simply use relative- or variable paths.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .