Image publisher gives numpy error
Hi, I am running the code from the directory of the file. After initiating both the publisher and subscriber the code works perfectly for 15sec and then give the error shown bellow.
Code:
#!/usr/bin/env python
import cv2
import rospy
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError
def read_video():
video_publisher = rospy.Publisher("tennis_ball_image", Image, queue_size=100)
video_capture = cv2.VideoCapture("video/tennis-ball-video.mp4")
while not rospy.is_shutdown():
_,rgb_frame = video_capture.read()
ros_image = CvBridge().cv2_to_imgmsg(rgb_frame, "bgr8")
video_publisher.publish(ros_image)
cv2.waitKey(10)
video_capture.release()
if __name__ == '__main__':
try:
rospy.init_node("tennis_ball_publisher", anonymous=True)
read_video()
rospy.spin()
except rospy.ROSInterruptException:
rospy.loginfo("node terminated.")
Error:
Traceback (most recent call last):
File "./image_publisher_node.py", line 21, in <module>
read_video()
File "./image_publisher_node.py", line 12, in read_video
ros_image = CvBridge().cv2_to_imgmsg(rgb_frame, "bgr8")
File "/opt/ros/melodic/lib/python2.7/dist-packages/cv_bridge/core.py", line 246, in cv2_to_imgmsg
raise TypeError('Your input type is not a numpy array')
TypeError: Your input type is not a numpy array
Do you have an example of a duplicate question? If this isn't actually a duplicate question, then it shouldn't be closed. If the answer I provided was correct, then the answer should be marked as such. If you figured out something else, it would be great if you answered your own question. We hope to get questions with correct answers to help others facing similar issues rather than closing questions. Thanks!
It got closed by mistake i am unable to reopen it
Got it... just re-opened. Thanks for getting back to me