pip install pykinect_azure
import os
import cv2
import time
import pykinect_azure as pykinect
import numpy as np
from dlabsim import DLABSIM_ROOT_DIR
class k4a_driver:
def __init__(self, model_path='/usr/lib/x86_64-linux-gnu/libk4a.so'):
pykinect.initialize_libraries(model_path)
self.device_config = pykinect.default_configuration
self.device_config.camera_fps = pykinect.K4A_FRAMES_PER_SECOND_30
self.device_config.color_resolution = pykinect.K4A_COLOR_RESOLUTION_1080P
self.device_config.depth_mode = pykinect.K4A_DEPTH_MODE_WFOV_2X2BINNED
self.depth_scale = [0.25, 1.]
self.device = pykinect.start_device(config=self.device_config)
def update(self):
return self.device.update()
if __name__ == "__main__":
k4a = k4a_driver()
cv2.namedWindow("img")
cv2.namedWindow("depth")
while True:
capture = k4a.update()
ret_color, color_img = capture.get_color_image()
ret_depth, depth_img = capture.get_transformed_depth_image()
if not ret_color or not ret_depth or color_img is None or depth_img is None:
continue
cv2.imshow("img", color_img)
depth_img_color = cv2.applyColorMap(cv2.convertScaleAbs(depth_img, alpha=0.255), cv2.COLORMAP_JET)
cv2.imshow("depth", depth_img_color)
key = cv2.waitKey(1000//30)
if key == ord("q"):
break
cv2.destroyAllWindows()