How to show the Color image feed from kinect using freenect2-python

554 views Asked by At

I'm using freenect2-python to read frames from kinectv2. Following is my code:

from freenect2 import Device, FrameType
import cv2
import numpy as np

def callback(type_, frame):
    print(f'{type_}, {frame.format}') 
    if type_ is FrameType.Color: # FrameFormat.BGRX
        rgb = frame.to_array().astype(np.uint8)
        cv2.imshow('rgb', rgb[:,:,0:3])

device = Device()
while True:
    device.start(callback)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        device.stop()
        break

The color frame format is FrameFormat.BGRX, so I'm taking the first 3 channels to show the image. But it shows a blank black window.

I used PIL but it opens a new window for each frame it receives. Is there a way to show frames in the same window in PIL?

1

There are 1 answers

0
paul-shuvo On

The cv2.imshow couldn't display anything because it was continuously getting updated with a new frame. I added cv2.waitkey(100) after cv2.imshow and it worked.

def callback(type_, frame):
    print(f'{type_}, {frame.format}') 
    if type_ is FrameType.Color: # FrameFormat.BGRX
        rgb = frame.to_array().astype(np.uint8)
        cv2.imshow('rgb', rgb[:,:,0:3])
        # added the following line of code
        cv2.imshow(100)