Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to change color image and transformed color image to bgra32 format? #107

Open
ERICXUCHI opened this issue May 18, 2023 · 1 comment
Open

Comments

@ERICXUCHI
Copy link

hi, when I run examplePlayback.py, this line "ret_color, color_image = capture.get_transformed_color_image()" would generate error: [error] [t=20928] D:\a\1\s\extern\Azure-Kinect-Sensor-SDK\src\sdk\k4a.c (1253): k4a_transformation_color_image_to_depth_camera(). Require color image and transformed color image both have bgra32 format.
Can anyone tell me how to convert color image and transformed color image to bgra32 format?
Thank you very much!

@lienzzzz
Copy link

lienzzzz commented Jul 17, 2023

import cv2
import ctypes
from pykinect_azure.k4a import _k4a
from pykinect_azure.k4a.image import Image

_, m = color_image.to_numpy()
bgra = cv2.cvtColor(m, cv2.COLOR_BGR2BGRA)
bgra_image_handle = _k4a.k4a_image_t()
image_format = _k4a.K4A_IMAGE_FORMAT_COLOR_BGRA32
buffer = bgra.ctypes.data_as(ctypes.POINTER(ctypes.c_uint8))
_k4a.VERIFY(_k4a.k4a_image_create_from_buffer(image_format, bgra.shape[1], bgra.shape[0], bgra.shape[1]*4, buffer, bgra.nbytes, ctypes.c_void_p(0), ctypes.c_void_p(0), bgra_image_handle), "MJPG to BGRA32 ERROR")
bgra_image = Image(bgra_image_handle)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants