From d46488996782aa7c3e31fd177297abb14a44c17d Mon Sep 17 00:00:00 2001 From: Max Value Date: Mon, 12 Jan 2026 11:44:03 +0000 Subject: [PATCH] Windows compatibility changes --- Cargo.toml | 1 + build.rs | 2 ++ src/color.cpp | 6 ++--- src/image_array.rs | 61 ++++++++++++++++++++++++++++++++++++---------- src/main.rs | 2 +- src/process.cpp | 4 ++- 6 files changed, 57 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index aa48132..9532aec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ npyz = "0.8.4" rand = "0.9.2" nokhwa = {version = "0.10.10", features = ["input-native"]} relative-path = "2.0.1" +yuv = "0.8.9" [build-dependencies] cc = "1.0" diff --git a/build.rs b/build.rs index 016c4c9..dd58d6f 100644 --- a/build.rs +++ b/build.rs @@ -16,6 +16,8 @@ fn main() { .define("IMAGE_HEIGHT", "1080") .define("LUT_SIZE", "12") + //.define("USE_LUT", None) + .compile("process.a"); println!("cargo::rustc-flags=-lopencv_core -lopencv_highgui -lopencv_xfeatures2d -lopencv_calib3d -lopencv_videoio -lopencv_imgcodecs -lopencv_imgproc -lopencv_features2d"); diff --git a/src/color.cpp b/src/color.cpp index 82ad0ec..6cdd2ba 100644 --- a/src/color.cpp +++ b/src/color.cpp @@ -1,11 +1,9 @@ #include #include "opencv4/opencv2/core.hpp" -#include "opencv4/opencv2/highgui.hpp" -#include "opencv4/opencv2/xfeatures2d.hpp" -#include "opencv4/opencv2/calib3d.hpp" -#include "opencv4/opencv2/imgproc.hpp" #ifndef LUT_SIZE +const int IMAGE_WIDTH = 1920; +const int IMAGE_HEIGHT = 1080; const int LUT_SIZE = 12; #endif diff --git a/src/image_array.rs b/src/image_array.rs index d7049e5..d2de10f 100644 --- a/src/image_array.rs +++ b/src/image_array.rs @@ -1,11 +1,21 @@ -use nokhwa::Camera; -use nokhwa::utils::{RequestedFormat, CameraIndex}; -use nokhwa::pixel_format::RgbFormat; +use image::ImageFormat; +use nokhwa::{Camera, FormatDecoder}; +use nokhwa::utils::{ + RequestedFormat, + CameraIndex, + CameraFormat, + Resolution, + FrameFormat, + RequestedFormatType +}; +use nokhwa::pixel_format::{RgbFormat, YuyvFormat}; use rustfft::num_complex::Complex; use npyz::NpyFile; +use yuv::{yuyv422_to_rgb, YuvPackedImage, YuvRange, YuvStandardMatrix}; + use std::io::BufReader; use std::fs::File; @@ -15,12 +25,15 @@ use crate::{ LUT_LENGTH, SPECTOGRAM_AREA, IMAGE_AREA, + IMAGE_WIDTH, + IMAGE_HEIGHT, VOLUME_MIN, VOLUME_REL, AMPLITUDE_REL, AMPLITUDE_MIN, ANGLE_REL, - ANGLE_MIN + ANGLE_MIN, + FPS }; pub struct ImageArray { @@ -43,16 +56,18 @@ impl ImageArray { let lut: [u8; LUT_LENGTH] = npy.into_vec().unwrap().try_into().unwrap(); // setup the camera - let index = CameraIndex::Index(0); - let requested = RequestedFormat::new::( - nokhwa::utils::RequestedFormatType::AbsoluteHighestFrameRate + let index = CameraIndex::Index(2); + let format = CameraFormat::new( + Resolution { width_x: 1920, height_y: 1080 }, + FrameFormat::YUYV, + FPS as u32 + ); + let requested = RequestedFormat::new::( + RequestedFormatType::Closest(format) ); let mut camera = Camera::new(index, requested).unwrap(); - - camera.set_resolution( - nokhwa::utils::Resolution { width_x: 1920, height_y: 1080} - ).expect("Resolution problem!"); + camera.open_stream().unwrap(); // self Self { @@ -68,9 +83,29 @@ impl ImageArray { pub fn read_camera (&mut self) { let frame = self.camera.frame().unwrap(); - println!("{}", frame.resolution()); + // some code to turn the yuyv into rgb if we need it! + // let stride = (IMAGE_WIDTH * 3) as u32; + // let vuvy = YuvPackedImage{ + // yuy: frame.buffer(), + // yuy_stride: stride, + // width: IMAGE_WIDTH as u32, + // height: IMAGE_HEIGHT as u32 + // }; + // let mut rgb = [0u8; IMAGE_AREA]; + // yuyv422_to_rgb( + // &vuvy, + // &mut rgb, + // stride, + // YuvRange::Full, + // YuvStandardMatrix::Bt601 + // ).unwrap(); + + let decoder = frame.decode_image::().unwrap(); + + decoder.save_with_format("./image.png", ImageFormat::Png).unwrap(); + + self.camera_buffer = decoder.into_vec()[..].into(); // something is wrong here - self.camera_buffer = frame.buffer()[..].into(); unsafe { ProcessCapture ( diff --git a/src/main.rs b/src/main.rs index 8c6895a..5184f4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,7 @@ const SPECTOGRAM_AREA: usize = WINDOW_SIZE * CHUNK_SIZE; const IMAGE_WIDTH: usize = 1920; const IMAGE_HEIGHT: usize = 1080; const IMAGE_AREA: usize = IMAGE_WIDTH * IMAGE_HEIGHT * 3; -// const FPS: usize = 30; +const FPS: usize = 5; // maximum and minimum pixel values of angle and amplitude. could be confined to // improve performance for quiet sounds. diff --git a/src/process.cpp b/src/process.cpp index 178dfb1..229981c 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -23,7 +23,9 @@ extern "C" */ ApplyHomography(camera_ptr, buffer_ptr, homography_ptr); - //ApplyCorrection(buffer_ptr, lut_ptr); + #ifdef USE_LUT + ApplyCorrection(buffer_ptr, lut_ptr); + #endif } // get homography function (see "homography.cpp") -- 2.39.2