OpenCV basics for Robtics. OpenCV error Assertion failed

Getting the following error while running exercise 2.1 of OPENCV basics of robotics

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/highgui/src/window.cpp, line 331

[ERROR] [1595052799.695411, 185.208000]: bad callback: <bound method LoadImage.camera_callback of <main.LoadImage object at 0x7f3809605bd0>>
Traceback (most recent call last):
File “/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/topics.py”, line 750, in _invoke_callback
cb(msg)
File “/home/user/catkin_ws/src/unit2/src/load_image.py”, line 26, in camera_callback
cv2.imshow(‘image’,img)
error: /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/highgui/src/window.cpp:331: error: (-215) size.width>0 && size.height>0 in function imshow

Can someone please me here. Is this has something to do with the incompatibility of the python version and the opencv version used for the course. I want to solve this issue ASAP so that I can start working. Thanks in advance.

Hello @ronakbhagat0907,

I’ve had a look at your code and the error I’m getting is:

Traceback (most recent call last):
  File "/home/user/catkin_ws/src/unit2/src/load_image.py", line 8, in <module>
    class LoadImage(Object):
NameError: name 'Object' is not defined 

This can be solved by removing the capital O in order to have class LoadImage(object).

About the error you mention, it looks like you didn’t had the repository downloaded to your workspace, so the code was not able to find the image in the expected path. If you use the code provided in the solution of the exercise, it should work OK (I just tested it).

Best,