Vision Basic Follow the line

Hello, I’m doing the unit 3 of this course but I have a problem, when I try to execute the Fourth Step: Get the Centroids, Draw a Circle for the Centroid and Show the Images using two scripts in python(move_robot.py and follow_line_step_hsv.py) in the terminal it show me the next error:

[ERROR] [1641497669.657422, 3545.925000]: bad callback: <bound method LineFollower.camera_callback of <main.LineFollower object at 0x7f48581aedc0>>
Traceback (most recent call last):
File “/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py”, line 750, in _invoke_callback
cb(msg)
File “/home/user/catkin_ws/src/my_following_line_package/scrips/follow_line_step_hsv.py”, line 33, in camera_callback
crop_img = cv_image[(height)/2+descentre:(height)/2+(descentre+rows_to_watch)][1:width]
TypeError: slice indices must be integers or None or have an index method

^C[INFO] [1641497669.691094, 3545.955000]: shutdown time!
Traceback (most recent call last):
File “/home/user/catkin_ws/src/my_following_line_package/scrips/follow_line_step_hsv.py”, line 115, in
main()
File “/home/user/catkin_ws/src/my_following_line_package/scrips/follow_line_step_hsv.py”, line 110, inmain
rate.sleep()
File “/opt/ros/noetic/lib/python3/dist-packages/rospy/timer.py”, line 103, in sleep
sleep(self._remaining(curr_time))
File “/opt/ros/noetic/lib/python3/dist-packages/rospy/timer.py”, line 165, in sleep
raise rospy.exceptions.ROSInterruptException(“ROS shutdown request”)
rospy.exceptions.ROSInterruptException: ROS shutdown request

someone have any idea why it happend? I tryed to copy the same code but is the same, thanks so much

Hi, could post the code here so we can check it? Do you continue having this issue? Normally this error could be because you are not getting the image data correctly, but without seeing the code it’s just a wold guess.

Lets us know if you still experience that issue

The problem still exists. The code is the given one in the notebook, follow_line_step_hsv.py

Just solved it by type casting the indices to int.
crop_img = cv_image[int((height)/2+descentre):int((height)/2+(descentre+rows_to_watch))][1:width]

2 Likes

This topic was automatically closed after 3 days. New replies are no longer allowed.