-3

I am trying to load image using openCV in python but I am getting error like:

error: C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:325: error: (-215) size.width>0 && size.height>0 in function cv::imshow

Does it has to do any thing with the size of the image? What can be possible solution of this error?

I am sending you the trace back in attachment. Thanksenter image description here

import cv2 , time
import numpy as np


img =  cv2.imread ('C:\Users\Ravi\.spyder\Ravi_Pic.jpc', 0)
cv2.imshow('Ravi',img) 
Ravi Mevada
  • 63
  • 3
  • 13
  • It seems like your image has a width and height of 0. Can you show us what `img.shape` is? – ikkuh Dec 20 '17 at 12:43
  • it looks like the image was not loaded, either the image cannot be opened due to the image type which maybe OpenCV cannot open it, or the path is wrong (it is always recommend to pass raw string or escape the \) or the file does not have the right permissions to be opened – api55 Dec 20 '17 at 12:45
  • Excuse me, what is `.jpc`? – Kinght 金 Dec 20 '17 at 13:09
  • my bad, it was .jpg. sorry.. – Ravi Mevada Dec 20 '17 at 13:17
  • duplicate: https://stackoverflow.com/questions/43572387/error-215-size-width0-size-height0-occurred-when-attempting-to-display-a/43593124#43593124 – mrk May 30 '18 at 12:04

1 Answers1

3

I'm pretty sure this is your issue:

img =  cv2.imread ('C:\Users\Ravi\.spyder\Ravi_Pic.jpc', 0)

You need to use double backslashes on windows, you may also want to remove the . in spyder but that may make no difference.

img =  cv2.imread ('C:\\Users\\Ravi\\.spyder\\Ravi_Pic.jpc', 0)
GPPK
  • 6,546
  • 4
  • 32
  • 57
  • I have used double backslashes and it worked. Thanks GPPK. – Ravi Mevada Dec 20 '17 at 13:13
  • If it helped, please accept the answer! – GPPK Dec 20 '17 at 13:23
  • did it really help? - or was it the .jpc typo, which should have been .jpg? – mrk May 30 '18 at 12:05
  • @vanilla it was almost definitly both, but bearing in mind this question has long been downvoted and closed as duplicate (as it should have been) there's probably no point mulling over it for to long. – GPPK May 30 '18 at 12:10
  • true, just came here with a similar question. And wanted to clarify this, since it is a shame wasting time trying stuff that actually doesn't make a difference. – mrk May 30 '18 at 12:26
  • @vanilla double backslashes are still important when working on windows though. – GPPK May 30 '18 at 12:36
  • Working on Windows here - made no difference though when using 'path/Folder/' – mrk May 30 '18 at 12:58