]> OzVa Git service - rust_fft/commitdiff
Windows compatibility changes
authorMax Value <greenwoodw50@gmail.com>
Mon, 12 Jan 2026 11:44:03 +0000 (11:44 +0000)
committerMax Value <greenwoodw50@gmail.com>
Mon, 12 Jan 2026 11:44:03 +0000 (11:44 +0000)
Cargo.toml
build.rs
src/color.cpp
src/image_array.rs
src/main.rs
src/process.cpp

index aa48132892bcb2a0cf9b8bf4c0c0509ca56b7156..9532aec354840ba5bc2631f31aaab1dfb68ff936 100644 (file)
@@ -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"
index 016c4c91d06e6bd91a150f1f1a2c4c40621a6da0..dd58d6f08a12a6ac1d41184121e77baed7af4351 100644 (file)
--- 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");
index 82ad0ec6735d7af22588a3041852b3e4dfea0370..6cdd2ba447d5e392444c4fa86a4b4b93770ef59b 100644 (file)
@@ -1,11 +1,9 @@
 #include <cmath>
 #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
 
index d7049e5071f988f6d32542a504d42198b694e9ac..d2de10fb12367cf87c5af0f688daf98f5200a395 100644 (file)
@@ -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::<RgbFormat>(
-                       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::<YuyvFormat>(
+                       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::<RgbFormat>().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 (
index 8c6895a10d60916b43fcef1080cdc69422cb969e..5184f4d62950e82e47e0fcf9f5adb5b090967b3c 100644 (file)
@@ -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.
index 178dfb112d6bc77549bb827262c11934d1f56099..229981c17fd648565dc66faf4fb6e3d6a4df5a0d 100644 (file)
@@ -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")