Robotics StackExchange | Archived questions

How to open Kinect V2 camera instead of webcam?

I have a code written in Python and OpenCV. The code works fine on my laptop but how do I open Kinect V2 IR/Depth/RGB camera instead of the laptops webcam?

Here is my code for webcam.py

cap = cv2.VideoCapture(0)
count = 0

while True:
    ret, frame = cap.read()
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
    lower_blue = np.array([0, 10, 60])
    upper_blue = np.array([20, 150, 255])

    mask = cv2.inRange(hsv, lower_blue, upper_blue)
    res = cv2.bitwise_and(frame, frame, mask=mask)

    ref = fill_blacks(mask)

What could be the equivalent of cv2.VideoCapture(0)? I have a little ROS subscribing code that subscribe to the Kinect V2 IR camera:

class PositionTracker:
    def __init__(self):
        # subscribe to kinect image messages
        self.sub = rospy.Subscriber("kinect2/sd/image_ir", Image, self.image_callback, queue_size=1)
        self.bridge = CvBridge()

    def image_callback(self,data):
        try:
            cv_image = self.bridge.imgmsg_to_cv2(data)
        except CvBridgeError as e:
            print(e)
        cv2.imshow("Image window", cv_image)

If I try to do anything inside the def image_calback function, the Kinect camera will hang. Can anybody help me with this?

Asked by hassanyf on 2018-01-29 10:36:49 UTC

Comments

Answers