2017-02-26 65 views
0

我試圖使用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) 

回答

0

在你main功能,你應該叫rospy.init_node首先,做任何ROS相關的東西,如創建出版商/訂戶之前。

+0

我改變了主要功能: 'rospy.init_node( 'image_converter',匿名= TRUE) image_converter()' 我stll不能看到OpenCV的圖像 – user1849595

+0

@ user1849595對不起,我遲到的反應。可以肯定的是:你是否仔細檢查了在訂閱主題'/ webcam/image_raw'上發佈的圖像?您可以通過調用'rostopic echo/webcam/image_raw'來完成此操作。 – luator

0

不知道,我缺乏瘋狂的python技能,但你只是調用一個類的「構造函數」而不分配給任何東西,這是不是意味着它會有一個0的refcount並自動被垃圾收集?