0

When I opened the .py file in colab using:

from google.colab import files

uploaded = files.upload()

for fn in uploaded.keys():
    print('User uploaded file "{name}" with length {length} bytes'.format(
    name=fn, length=len(uploaded[fn])))

the file loaded and saved properly. but when I was opening it using the command:

python "mypuppy.py"

it loaded but an error occurred in Open CV:

Traceback (most recent call last): File "mypuppy.py", line 4, in cv2.imshow('puppy.jpg',img) cv2.error: OpenCV(3.4.3) /io/opencv/modules/highgui/src/window.cpp:356: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'

The Original .py file is as follows:

import cv2
img = cv2.imread('puppy.jpg')
while True:
    from google.colab.patches import cv2_imshow
    cv2_imshow(img) 
    #If we've waited atleast 1ms AND we've pressed the ESC

    if cv2.waitkey(1) & 0xFF == 27:
       break
cv2.destroyAllWindows()
Ami Hollander
  • 2,435
  • 3
  • 29
  • 47
Ashhad
  • 9
  • 1
  • Does this answer your question? [How to solve "cv2. error: (-215) size.width>0 && size.height>0 in function imshow" Error in Python?](https://stackoverflow.com/questions/48739788/how-to-solve-cv2-error-215-size-width0-size-height0-in-function-imsho) – pseudomonas Oct 30 '19 at 15:19

1 Answers1

0

image can't be readed. check if img is not empty first. you can upload image using this command:

!wget "copy paste the image address here"
Peyman habibi
  • 680
  • 1
  • 6
  • 17