How to take image from kinect and visualize using opencv?

asked 2018-09-28 04:57:00 -0500

asudot gravatar image

I have a kinect set up using openni. I want to use opencv for further processing. When I use imgmsg_to_cv2() and cv2.imshow no image shows up and the terminal freezes. What am I missing?

class Frame:
    def __init__(self):
        self.bridge = cv_bridge.CvBridge()
        cv2.namedWindow("window", 1)
        self.image_sub = rospy.Subscriber('camera/rgb/image_raw',Image, self.img_callback)

    def img_callback(self,data):
        image = self.bridge.imgmsg_to_cv2(data,desired_encoding='bgr8')
        cv2.imshow("window", image)
        cv2.waitKey(3)

if __name__ == '__main__':
    rospy.init_node('image_subscriber', anonymous = True)
    frame = Frame()
    rospy.spin()
edit retag flag offensive close merge delete