initial commit

sending a RGB image to LabVIEW works
This commit is contained in:
Andy Killorin 2024-12-30 16:50:50 -05:00
commit e336e5ca04
Signed by: ank
GPG key ID: 23F9463ECB67FE8C
3 changed files with 1810 additions and 0 deletions

1232
encoder/Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

10
encoder/Cargo.toml Normal file
View file

@ -0,0 +1,10 @@
[package]
name = "encoder"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow = "1.0.95"
nokhwa = { version = "0.10.7", features = ["input-native"] }
openh264 = "0.6.6"
tokio = { version = "1.42.0", features = ["full"] }

36
encoder/src/main.rs Normal file
View file

@ -0,0 +1,36 @@
use nokhwa::{pixel_format::RgbFormat, utils::{ApiBackend, RequestedFormat, RequestedFormatType, Resolution}, Camera};
use anyhow::{Context, Result};
use openh264::{encoder::Encoder, formats::{RgbSliceU8, YUVBuffer}};
use tokio::sync::Notify;
#[tokio::main]
async fn main() -> Result<()>{
let await_frame = Notify::new();
println!("Hello, world!");
Ok(())
}
async fn camera_manager() -> Result<()>{
let cameras = nokhwa::query(ApiBackend::Auto)?;
let camera = cameras.get(0).context("no cameras")?;
println!("using: {}",camera.human_name());
let requested = RequestedFormat::new::<RgbFormat>(RequestedFormatType::HighestResolution(Resolution::new(320, 240)));
let mut camera = Camera::new(camera.index().clone(), requested)?;
let mut encoder = Encoder::new()?;
loop {
let frame = camera.frame()?;
let resolution = frame.resolution();
let buf = RgbSliceU8::new(&frame.buffer(), (resolution.width_x as usize, resolution.height_y as usize));
let yuv = YUVBuffer::from_rgb8_source(buf);
let data = encoder.encode(&yuv)?;
}
}