l1npengtul / nokhwa

Cross Platform Rust Library for Powerful Webcam/Camera Capture
Apache License 2.0
502 stars 121 forks source link

Incorrect colors #90

Open br0kenpixel opened 1 year ago

br0kenpixel commented 1 year ago

I'm using the following code to capture an image and save it to file:

fn capture_webcam() {
    let index = CameraIndex::Index(0);
    let requested = RequestedFormat::new::<RgbFormat>(RequestedFormatType::None);
    let mut camera = Camera::new(index, requested).unwrap();
    println!("{}", camera.info().human_name());

    camera.open_stream().expect("Permission denied");
    let frame = camera.frame().unwrap();
    camera.stop_stream().unwrap();
    let decoded = frame.decode_image::<RgbFormat>().unwrap();

    decoded.save("img.png").unwrap();
    println!("Captured webcam");
}

The result is a pink-ish image: img

I tried:

Also, according to the documentation, camera.open_stream() should be called internally by camera.frame(), however, deleting the camera.open_stream().expect("Permission denied"); line makes camera.frame() hang forever.

macOS 12.6.1 (21G217), Intel nokhwa = { version = "0.10.3", features = ["input-native"] } image = "0.24.5" rustc 1.66.0

gennyble commented 1 year ago

This could be due to #78. I tested the 0.10.3 code and it's still reporting as NV12 despite being successfully decoded as YUV422. I'm not sure, though, because decode_image() fails with "bad input buffer size". Just a lead, maybe?

l1npengtul commented 1 year ago

Hey, I'll take a look at this after finals, please hold

yamt commented 10 months ago

might be related: https://github.com/l1npengtul/nokhwa/pull/151