rename awkward CameraImageBytes to ImageProxy

This commit is contained in:
Brandon Thomas committed 2020-08-15 22:54:15 -04:00
1 parent 67c5c345c2
commit fb78650fbb
6 files changed
+31 -28

No files matched your search

+13 -10
View File
@@ -1,6 +1,6 @@
use anyhow::Result as AnyhowResult;
use kinect::k4a_sys_wrapper;
use point_cloud::debug::camera_image_bytes::CameraImageBytes;
use point_cloud::debug::image_proxy::ImageProxy;
use std::sync::{RwLock, Mutex, PoisonError, MutexGuard, Arc};
use winit::event::VirtualKeyCode::Mute;
@@ -14,19 +14,19 @@ pub struct CaptureProxy {
#[derive(Clone)]
enum UnderlyingStorage {
CameraImageBytes {
color_image: CameraImageBytes,
depth_image: CameraImageBytes,
color_image: ImageProxy,
depth_image: ImageProxy,
},
K4aCapture {
capture: k4a_sys_wrapper::Capture,
color_image: CameraImageBytes,
depth_image: CameraImageBytes,
color_image: ImageProxy,
depth_image: ImageProxy,
}
}
impl CaptureProxy {
pub fn from_image_proxy_pair(color_image: CameraImageBytes, depth_image: CameraImageBytes) -> Self {
pub fn from_image_proxy_pair(color_image: ImageProxy, depth_image: ImageProxy) -> Self {
Self {
storage: UnderlyingStorage::CameraImageBytes {
color_image,
@@ -39,14 +39,17 @@ impl CaptureProxy {
// NB: We need to increase the refcount.
// K4a manages the memory under the hood.
let capture = capture.clone();
Self::consume_k4a_image(capture)
}
pub fn consume_k4a_image(capture: k4a_sys_wrapper::Capture) -> AnyhowResult<Self> {
let color_image = capture.get_color_image()?;
let depth_image = capture.get_color_image()?;
// NB: I tried to lazily unpack these, but interior mutability Sync/Send was a nightmare.
// The poor ergonomics were not worth it.
let color_image_wrapper = CameraImageBytes::from_k4a_image(&color_image);
let depth_image_wrapper = CameraImageBytes::from_k4a_image(&depth_image);
let color_image_wrapper = ImageProxy::from_k4a_image(&color_image);
let depth_image_wrapper = ImageProxy::from_k4a_image(&depth_image);
Ok(Self {
storage: UnderlyingStorage::K4aCapture {
@@ -64,14 +67,14 @@ impl CaptureProxy {
}
}
pub fn get_color_image(&self) -> AnyhowResult<&CameraImageBytes> {
pub fn get_color_image(&self) -> AnyhowResult<&ImageProxy> {
match &self.storage {
UnderlyingStorage::CameraImageBytes { color_image, .. } => Ok(color_image),
UnderlyingStorage::K4aCapture{ color_image, .. } => Ok(color_image),
}
}
pub fn get_depth_image(&self) -> AnyhowResult<&CameraImageBytes> {
pub fn get_depth_image(&self) -> AnyhowResult<&ImageProxy> {
match &self.storage {
UnderlyingStorage::CameraImageBytes { depth_image, .. } => Ok(depth_image),
UnderlyingStorage::K4aCapture{ depth_image, .. } => Ok(depth_image),
@@ -7,7 +7,7 @@ use kinect::k4a_sys_wrapper;
/// Store either raw bytes, or wrap a k4a::Image
/// This is meant to be plumbed through the system instead of a k4a::Image (depth or color image)
#[derive(Clone)]
pub struct CameraImageBytes {
pub struct ImageProxy {
storage: UnderlyingStorage,
}
@@ -24,7 +24,7 @@ enum UnderlyingStorage {
K4aImage(k4a_sys_wrapper::Image),
}
impl CameraImageBytes {
impl ImageProxy {
pub fn from_file(filename: &str, width: usize, height: usize) -> AnyhowResult<Self> {
let mut file = File::open(filename)?;
let metadata = fs::metadata(&filename)?;
+1 -1
View File
@@ -1,2 +1,2 @@
pub mod camera_image_bytes;
pub mod image_proxy;
pub mod capture_proxy;
+2 -2
View File
@@ -22,7 +22,7 @@ use opengl::opengl_wrapper::{Buffer, gl_get_error};
use point_cloud::pixel_structs::DepthPixel;
use files::read_file_string_contents::read_file_string_contents;
use files::write_to_file_from_byte_ptr::write_to_file_from_byte_ptr;
use point_cloud::debug::camera_image_bytes::CameraImageBytes;
use point_cloud::debug::image_proxy::ImageProxy;
pub type Result<T> = std::result::Result<T, PointCloudComputeError>;
@@ -150,7 +150,7 @@ impl GpuPointCloudConverter {
///
pub fn convert(&self,
//depth_image: &k4a_sys_wrapper::Image,
depth_image: &CameraImageBytes,
depth_image: &ImageProxy,
output_texture: &mut Texture,
camera_index: usize
) -> Result<()> {
+2 -2
View File
@@ -26,7 +26,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
use opengl::link_program::link_shader_program;
use point_cloud::debug::camera_image_bytes::CameraImageBytes;
use point_cloud::debug::image_proxy::ImageProxy;
use files::read_file_string_contents::read_file_string_contents;
use files::write_to_file_from_byte_ptr::write_to_file_from_byte_ptr;
@@ -311,7 +311,7 @@ impl PointCloudRenderer {
///
///
pub fn update_point_clouds(&mut self,
color_images: &Vec<CameraImageBytes>,
color_images: &Vec<ImageProxy>,
point_cloud_textures: &Vec<Texture>
) -> Result<()> {
let time = SystemTime::now();
+11 -11
View File
@@ -20,7 +20,7 @@ use point_cloud::pixel_structs::DepthPixel;
use point_cloud::point_cloud_renderer::{PointCloudRenderer, PointCloudRendererError};
use point_cloud::util::{colorize_depth_blue_to_red, get_depth_mode_range, ValueRange};
use point_cloud::viewer_image::ViewerImage;
use point_cloud::debug::camera_image_bytes::CameraImageBytes;
use point_cloud::debug::image_proxy::ImageProxy;
pub type Result<T> = std::result::Result<T, PointCloudVisualizerError>;
@@ -137,8 +137,8 @@ pub struct PointCloudVisualizer {
/// For debugging
/// If present, use these instead of camera captures.
debug_static_color_frames: Vec<CameraImageBytes>,
debug_static_depth_frames: Vec<CameraImageBytes>,
debug_static_color_frames: Vec<ImageProxy>,
debug_static_depth_frames: Vec<ImageProxy>,
}
// TODO: Dedup
@@ -210,12 +210,12 @@ impl PointCloudVisualizer {
}
let mut debug_static_color_frames = Vec::new();
debug_static_color_frames.push(CameraImageBytes::from_file("output/color_src_0", 0, 0).unwrap());
debug_static_color_frames.push(CameraImageBytes::from_file("output/color_src_1", 0, 0).unwrap());
debug_static_color_frames.push(ImageProxy::from_file("output/color_src_0", 0, 0).unwrap());
debug_static_color_frames.push(ImageProxy::from_file("output/color_src_1", 0, 0).unwrap());
let mut debug_static_depth_frames = Vec::new();
debug_static_depth_frames.push(CameraImageBytes::from_file("output/depth_src_0", 3840, 2160).unwrap());
debug_static_depth_frames.push(CameraImageBytes::from_file("output/depth_src_1", 3840, 2160).unwrap());
debug_static_depth_frames.push(ImageProxy::from_file("output/depth_src_0", 3840, 2160).unwrap());
debug_static_depth_frames.push(ImageProxy::from_file("output/depth_src_1", 3840, 2160).unwrap());
let mut visualizer = Self {
num_cameras,
@@ -352,9 +352,9 @@ impl PointCloudVisualizer {
} else {
// TODO: wrt k4a::Image.clone(), k4a should use ref counting. (I did this one other place a few commits ago.
// Hope it's not ref leaking.)
let colorizations: Vec<CameraImageBytes> = self.point_cloud_colorizations.iter()
let colorizations: Vec<ImageProxy> = self.point_cloud_colorizations.iter()
.map(|img| img.as_ref().map(|img| img.clone()).unwrap()) // Potential ref leak #1
.map(|image| CameraImageBytes::from_k4a_image(&image)) // Potential ref leak #2
.map(|image| ImageProxy::from_k4a_image(&image)) // Potential ref leak #2
.collect();
color_captures = colorizations;
@@ -411,12 +411,12 @@ impl PointCloudVisualizer {
//
// Hack to hold onto the K4A ColorImageBytes wrapper.
let mut depth_image_storage : Option<CameraImageBytes> = None;
let mut depth_image_storage : Option<ImageProxy> = None;
let depth_image = if let Some(image) = self.debug_static_depth_frames.get(camera_index) {
image
} else {
let camera_image = CameraImageBytes::from_k4a_image(&depth_image);
let camera_image = ImageProxy::from_k4a_image(&depth_image);
depth_image_storage = Some(camera_image);
depth_image_storage.as_ref().unwrap()
};