我試圖使用usb_camera,ros_bridge發佈opencv圖像。主題已發佈,但我看不到任何圖像或錯誤。我可以看到usb_camera圖像無法發佈帶有ROS CvBridge和OpenCV的USB攝像頭圖像
class image_converter:
def __init__(self):
self.image_pub = rospy.Publisher("/image_converter/image_topic_2",Image, queue_size=10)
self.bridge = CvBridge()
self.image_sub = rospy.Subscriber("/webcam/image_raw",Image,self.callback)
def callback(self,data):
try:
cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")
except CvBridgeError as e:
print(e)
grey = cv2.cv_image(cv_image,(7,7))
edges =cv2.canny(grey,15.0,30.0)
try:
self.image_pub.publish(self.bridge.cv2_to_imgmsg(edges, "bgr8"))
except CvBridgeError as e:
print(e)
def main(args):
image_converter()
rospy.init_node('image_converter', anonymous=True)
try:
rospy.spin()
except KeyboardInterrupt:
print("Shutting down")
cv2.destroyAllWindows()
if __name__ == '__main__':
main(sys.argv)
我改變了主要功能: 'rospy.init_node( 'image_converter',匿名= TRUE) image_converter()' 我stll不能看到OpenCV的圖像 – user1849595
@ user1849595對不起,我遲到的反應。可以肯定的是:你是否仔細檢查了在訂閱主題'/ webcam/image_raw'上發佈的圖像?您可以通過調用'rostopic echo/webcam/image_raw'來完成此操作。 – luator