ibaiGorordo / pyKinectAzure

Python library to run Kinect Azure DK SDK functions
MIT License
460 stars 114 forks source link

Record color point cloud #84

Closed MichalZuraw closed 1 year ago

MichalZuraw commented 1 year ago

Hello, i want to record frame by frame color point cloud. I made using Github something like this :

` def save_data2(filename, points,color): N = points.shape[0] vertex = [] for i in range(N): vertex.append((points[i, 0], points[i, 1], points[i, 2],color[i, 0], color[i, 1], color[i, 2])) vertex = np.array(vertex, dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4'),('red', 'u1'), ('green', 'u1'), ('blue', 'u1')]) el = PlyElement.describe(vertex, 'vertex') PlyData([el], text=True).write(filename)

video_filename = "2022-12-09-12-54-46.mkv"
pykinect.initialize_libraries()
# Start playback
playback = pykinect.start_playback(video_filename)
playback_config = playback.get_record_configuration()
#print(playback_config)
while playback.isOpened():
    # Get camera capture
    capture = playback.update()
    # Get the colored depth
    ret, depth_image=capture.get_depth_image()
    ret, color_image=capture.get_color_image()
    r_color_image=cv2.resize(color_image,(512,512))
    resized_color_image=np.reshape(cv2.cvtColor(r_color_image, cv2.COLOR_BGR2RGB),(262144,3))
    ret, pointcloud = capture.get_pointcloud()
    filename = '{date:%Y-%m-%d-%H-%M-%S}.ply'.format(date=datetime.datetime.now())
    save_data2(filename,pointcloud,resized_color_image)

`

Using azure_kinect_recorder and config { "camera_fps" : "K4A_FRAMES_PER_SECOND_30", "color_format" : "K4A_IMAGE_FORMAT_COLOR_MJPG", "color_resolution" : "K4A_COLOR_RESOLUTION_2160P", "depth_delay_off_color_usec" : "0", "depth_mode" : "K4A_DEPTH_MODE_WFOV_2X2BINNED", "disable_streaming_indicator" : "false", "subordinate_delay_off_master_usec" : "0", "synchronized_images_only" : "false", "wired_sync_mode" : "K4A_WIRED_SYNC_MODE_STANDALONE" } It doesn't work because i put image without depth to point cloud, but to be honest i have no idea to fix it.

Thank you

MichalZuraw commented 1 year ago

Used Pyk4a to solve