cv_bridge opencv4 running slow
I have been able to built the package by adding this two lines into catkin_ws/src/vision_opencv/cv_bridge/CMakeLists.txt
set(PYTHON_NUMPY_INCLUDE_DIR ~/.local/lib/python3.6/site-packages/numpy/core/include)
set(PYTHON_INCLUDER_PATH /usr/include/python3.6)
But when I run my code it seems that cv_bridge is too slow for video streaming real time. Do you know how can I improve it?
this is my code:
#!/usr/bin/env python3
import numpy as np
import cv2
import rospy
from std_msgs.msg import String
from sensor_msgs.msg import Image
import sys
from cv_bridge import CvBridge bridge = CvBridge()
def cam_test():
cap = cv2.VideoCapture(-1)
pub = rospy.Publisher('chatter', Image, queue_size=1000)
rospy.init_node('talker', anonymous=True)
rate = rospy.Rate(100)
while True:
ret, img = cap.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.circle(img,(320,240),15,(0,0,255),2)
image_message = bridge.cv2_to_imgmsg(img, encoding="passthrough")
rospy.loginfo(image_message)
pub.publish(image_message)
rate.sleep()
#cv2.imshow('img',img)
k = cv2.waitKey(30) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
try:
cam_test()
except rospy.ROSInterruptException:
pass