azure_kinect/
capture.rs

1use crate::*;
2use azure_kinect_sys::k4a::*;
3use std::ptr;
4
5pub struct Capture<'a> {
6    api: &'a azure_kinect_sys::api::Api,
7    pub(crate) handle: k4a_capture_t,
8}
9
10impl<'a> Capture<'a> {
11    #[deprecated(since = "0.2", note = "Factory::capture_create")]
12    pub fn new(factory: &'a Factory) -> Result<Capture<'a>, Error> {
13        let mut handle: k4a_capture_t = ptr::null_mut();
14        Error::from_k4a_result_t(unsafe { (factory.api.funcs.k4a_capture_create)(&mut handle) })
15            .to_result_fn(|| Capture::from_handle(&factory.api, handle))
16    }
17
18    pub(crate) fn from_handle(
19        api: &'a azure_kinect_sys::api::Api,
20        handle: k4a_capture_t,
21    ) -> Capture<'a> {
22        Capture { api, handle }
23    }
24
25    /// Get the color image associated with the capture
26    pub fn get_color_image(&self) -> Image {
27        Image::from_handle(self.api, unsafe {
28            (self.api.funcs.k4a_capture_get_color_image)(self.handle)
29        })
30    }
31
32    /// Get the depth image associated with the capture
33    pub fn get_depth_image(&self) -> Image {
34        Image::from_handle(self.api, unsafe {
35            (self.api.funcs.k4a_capture_get_depth_image)(self.handle)
36        })
37    }
38
39    /// Get the IR image associated with the capture
40    pub fn get_ir_image(&self) -> Image {
41        Image::from_handle(self.api, unsafe {
42            (self.api.funcs.k4a_capture_get_ir_image)(self.handle)
43        })
44    }
45
46    /// Set / add a color image to the capture
47    pub fn set_color_image(&mut self, color_image: &Image) {
48        unsafe { (self.api.funcs.k4a_capture_set_color_image)(self.handle, color_image.handle) }
49    }
50
51    /// Set / add a depth image to the capture
52    pub fn set_depth_image(&mut self, depth_image: &Image) {
53        unsafe { (self.api.funcs.k4a_capture_set_depth_image)(self.handle, depth_image.handle) }
54    }
55
56    /// Set / add an IR image to the capture
57    pub fn set_ir_image(&mut self, ir_image: &Image) {
58        unsafe { (self.api.funcs.k4a_capture_set_ir_image)(self.handle, ir_image.handle) }
59    }
60
61    /// Set the temperature associated with the capture in Celsius.
62    pub fn set_temperature_c(&mut self, temperature_c: f32) {
63        unsafe { (self.api.funcs.k4a_capture_set_temperature_c)(self.handle, temperature_c) }
64    }
65
66    /// Get temperature (in Celsius) associated with the capture.
67    pub fn get_temperature_c(&self) -> f32 {
68        unsafe { (self.api.funcs.k4a_capture_get_temperature_c)(self.handle) }
69    }
70}
71
72impl Drop for Capture<'_> {
73    fn drop(&mut self) {
74        unsafe {
75            (self.api.funcs.k4a_capture_release)(self.handle);
76        }
77        self.handle = ptr::null_mut();
78    }
79}
80
81impl Clone for Capture<'_> {
82    fn clone(&self) -> Self {
83        unsafe {
84            (self.api.funcs.k4a_capture_reference)(self.handle);
85        }
86        Capture::from_handle(self.api, self.handle)
87    }
88}