예제 #1
0
    def device_get_serialnum(self):
        """Get the Azure Kinect device serial number.

		Parameters:
		None
			
		Returns:
		A return of ::K4A_BUFFER_RESULT_SUCCEEDED means that the serial_number has been filled in. If the buffer is too
		small the function returns ::K4A_BUFFER_RESULT_TOO_SMALL and the size of the serial number is
		returned in the serial_number_size parameter. All other failures return ::K4A_BUFFER_RESULT_FAILED.
		
		Remarks:
		Queries the device for its serial number. If the caller needs to know the size of the serial number to allocate
		memory, the function should be called once with a NULL serial_number to get the needed size in the 
		serial_number_size output, and then again with the allocated buffer.

		Only a complete serial number will be returned. If the caller's buffer is too small, the function will return
		::K4A_BUFFER_RESULT_TOO_SMALL without returning any data in serial_number.
		"""
        # First call to get the size of the buffer
        serial_number_size = ctypes.c_size_t()
        result = self.k4a.k4a_device_get_serialnum(self.device_handle, None,
                                                   serial_number_size)

        if result == _k4a.K4A_BUFFER_RESULT_TOO_SMALL:
            serial_number = ctypes.create_string_buffer(
                serial_number_size.value)

        _k4a.VERIFY(
            self.k4a.k4a_device_get_serialnum(self.device_handle,
                                              serial_number,
                                              serial_number_size),
            "Read serial number failed!")

        return serial_number.value.decode("utf-8")
예제 #2
0
    def image_create(self, image_format, width_pixels, height_pixels,
                     stride_bytes, image_handle):
        """Create an image.

		Parameters:
		image_format(k4a_image_format_t): The format of the image that will be stored in this image container.
		width_pixels(int): Width in pixels.
		height_pixels(int): Height in pixels.
		stride_bytes(int): The number of bytes per horizontal line of the image.
						   If set to 0, the stride will be set to the minimum size given the format and width_pixels.
		image_handle(k4a_image_t): Pointer to store image handle in.

		Returns:
		Returns #K4A_RESULT_SUCCEEDED on success. Errors are indicated with #K4A_RESULT_FAILED.
		
		Remarks:
		This function is used to create images of formats that have consistent stride. The function is not suitable for
		compressed formats that may not be represented by the same number of bytes per line.

		For most image formats, the function will allocate an image buffer of size height_pixels * stride_bytes.
		Buffers #K4A_IMAGE_FORMAT_COLOR_NV12 format will allocate an additional height_pixels / 2 set of lines (each of 
		stride_bytes). This function cannot be used to allocate #K4A_IMAGE_FORMAT_COLOR_MJPG buffers.
		"""
        _k4a.VERIFY(
            self.k4a.k4a_image_create(image_format, width_pixels,
                                      height_pixels, stride_bytes,
                                      image_handle), "Create image failed!")
예제 #3
0
    def transformation_depth_image_to_color_camera(
            self, transformation_handle, input_depth_image_handle,
            transformed_depth_image_handle):
        """Transforms the depth map into the geometry of the color camera.

		Parameters:
		transformation_handle (k4a_transformation_t): Transformation handle.
		input_depth_image_handle (k4a_image_t): Handle to input depth image.
		transformed_depth_image_handle (k4a_image_t): Handle to output transformed depth image.

		Returns:
		K4A_RESULT_SUCCEEDED if transformed_depth_image was successfully written and ::K4A_RESULT_FAILED otherwise.
		
		Remarks:
		This produces a depth image for which each pixel matches the corresponding pixel coordinates of the color camera.

		transformed_depth_image must have a width and height matching the width and height of the color camera in the mode
		specified by the k4a_calibration_t used to create the transformation_handle with k4a_transformation_create().
		"""

        _k4a.VERIFY(
            self.k4a.k4a_transformation_depth_image_to_color_camera(
                transformation_handle, input_depth_image_handle,
                transformed_depth_image_handle),
            "Transformation from depth to color failed!")
예제 #4
0
	def transform_depth_image_to_point_cloud(self, depth_image_handle: _k4a.k4a_image_t):
		"""Transforms the depth map to point clouds

		Parameters:
		depth_image_handle (k4a_image_t): Handle to the Image

		Returns:
		point_cloud (k4a_image_t): Handle to point cloud
		"""
		calibration = _k4a.k4a_calibration_t()
		self.getDepthSensorCalibration(calibration)
		transformation_handle = self.transformation_create(calibration)
		point_cloud = _k4atypes.k4a_image_t()

		self.image_create(
			_k4atypes.K4A_IMAGE_FORMAT_CUSTOM,
			self.image_get_width_pixels(depth_image_handle),
			self.image_get_height_pixels(depth_image_handle),
			self.image_get_width_pixels(depth_image_handle) * 6,
			point_cloud
		)

		_k4a.VERIFY(self.k4a.k4a_transformation_depth_image_to_point_cloud(
			transformation_handle,
			depth_image_handle,
			_k4atypes.K4A_CALIBRATION_TYPE_DEPTH,
			point_cloud
		), "Error Occur When Make Point Cloud")

		return point_cloud
예제 #5
0
    def device_get_imu_sample(self, timeout_in_ms=_k4a.K4A_WAIT_INFINITE):
        """Reads an IMU sample.

		Parameters:h
		timeout_in_ms (int):Specifies the time in milliseconds the function should block waiting for the capture. If set to 0, the function will
							return without blocking. Passing a value of #K4A_WAIT_INFINITE will block indefinitely until data is available, the
							device is disconnected, or another error occurs.

		Returns:
		None

		Remarks:
		Gets the next sample in the streamed sequence of IMU samples from the device. If a new sample is not currently
		available, this function will block until the timeout is reached. The API will buffer at least two camera capture
		intervals worth of samples before dropping the oldest sample. Callers needing to capture all data need to ensure they
		read the data as fast as the data is being produced on average.

		Upon successfully reading a sample this function will return success and populate imu_sample.
		If a sample is not available in the configured timeout_in_ms, then the API will return ::K4A_WAIT_RESULT_TIMEOUT.
		"""
        if self.imu_running:
            _k4a.VERIFY(
                self.k4a.k4a_device_get_imu_sample(self.device_handle,
                                                   self.imu_sample,
                                                   timeout_in_ms),
                "Get IMU failed!")
예제 #6
0
	def device_open(self, index=0):
		"""Open an Azure Kinect device.

		Parameters:
		index (int): The index of the device to open, starting with
			
		Returns:
		None
		
		Remarks:
		If successful, k4a_device_open() will return a device handle in the device_handle parameter.
		This handle grants exclusive access to the device and may be used in the other Azure Kinect API calls.

		When done with the device, close the handle with k4a_device_close()
		"""
		_k4a.VERIFY(self.k4a.k4a_device_open(index,self.device_handle),"Open K4A Device failed!")
예제 #7
0
	def device_get_calibration(self, depth_mode, color_resolution,calibration):
		"""Get the camera calibration for the entire Azure Kinect device.

		Parameters:h
		depth_mode(k4a_depth_mode_t): Mode in which depth camera is operated.
		color_resolution(k4a_color_resolution_t): Resolution in which color camera is operated.
		calibration(k4a_calibration_t):Location to write the calibration

		Returns:
		K4A_RESULT_SUCCEEDED if calibration was successfully written. ::K4A_RESULT_FAILED otherwise.

		Remarks:
		The calibration represents the data needed to transform between the camera views and may be
		different for each operating depth_mode and color_resolution the device is configured to operate in.

		The calibration output is used as input to all calibration and transformation functions.
		"""
		_k4a.VERIFY(self.k4a.k4a_device_get_calibration(self.device_handle,depth_mode,color_resolution,calibration),"Get calibration failed!")
예제 #8
0
	def bodyTracker_project_skeleton(self, skeleton):
		# Project using the calibration of the camera for the image
		position_2d = _k4a.k4a_float2_t()
		valid = ctypes.c_int()
		skeleton2D = _k4abt.k4abt_skeleton2D_t()

		for jointID,joint in enumerate(skeleton.joints):
			_k4a.VERIFY(self.k4a.k4a_calibration_3d_to_2d(
										self.body_tracker.sensor_calibration, 
										joint.position, 
										_k4a.K4A_CALIBRATION_TYPE_DEPTH, 
										_k4a.K4A_CALIBRATION_TYPE_DEPTH, 
										position_2d,
										valid),
										 "Project skeleton failed")

			skeleton2D.joints2D[jointID].position = position_2d
			skeleton2D.joints2D[jointID].confidence_level = joint.confidence_level
					
		return skeleton2D
예제 #9
0
	def device_start_cameras(self, device_config=None):
		"""Starts color and depth camera capture.

		Parameters:
		device_config (k4a_device_configuration_t): The configuration we want to run the device in. This can be initialized with ::K4A_DEVICE_CONFIG_INIT_DEFAULT.
			
		Returns:
		None
		
		Remarks:
		Individual sensors configured to run will now start to stream captured data..

		It is not valid to call k4a_device_start_cameras() a second time on the same k4a_device_t until
		k4a_device_stop_cameras() has been called. 		
		"""
		if device_config is not None:
			self.config = device_config
		
		if not self.cameras_running:
			_k4a.VERIFY(self.k4a.k4a_device_start_cameras(self.device_handle,self.config.current_config),"Start K4A cameras failed!")
			self.cameras_running = True
예제 #10
0
	def device_start_imu(self):
		"""Starts the IMU sample stream.

		Parameters:
		None

		Returns:
		None
		
		Remarks:
		Call this API to start streaming IMU data. It is not valid to call this function a second time on the same
		k4a_device_t until k4a_device_stop_imu() has been called.

		This function is dependent on the state of the cameras. The color or depth camera must be started before the IMU.
		K4A_RESULT_FAILED will be returned if one of the cameras is not running.
		"""
		if self.cameras_running:
			if not self.imu_running:
				_k4a.VERIFY(self.k4a.k4a_device_start_imu(self.device_handle),"Start K4A IMU failed!")
				self.imu_running = True	
		else:
			print("\nTurn on cameras before running IMU.\n")