Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrupted image #184

Open
Vanello1908 opened this issue Nov 9, 2024 · 2 comments
Open

Corrupted image #184

Vanello1908 opened this issue Nov 9, 2024 · 2 comments

Comments

@Vanello1908
Copy link

Vanello1908 commented Nov 9, 2024

pub fn create_photo(path: &PathBuf) -> Result<(), &'static str>{
    let index: CameraIndex = CameraIndex::Index(0); 
    let requested: RequestedFormat<'_> = RequestedFormat::new::<RgbFormat>(RequestedFormatType::AbsoluteHighestResolution);
    let res: Result<Camera, nokhwa::NokhwaError> = Camera::new(index, requested);
    if res.is_err(){
        return Err("Camera error");
    }
    let mut camera: Camera = res.unwrap();
    let frame = camera.frame().unwrap();
    let decoded = frame.decode_image::<RgbFormat>().unwrap();
    
    match decoded.save_with_format(path, image::ImageFormat::Jpeg){
        Ok(_) => {},
        Err(_) => return Err("Photo write error")
    }
    Ok(())
}

But when I shot something fully black from one laptop, I have
image
But from another
image

Platform: Windows 10
Feature: input-native
nokhwa v.0.10.4

@Vanello1908
Copy link
Author

I've tried different methods:

  • changing decoder
  • entering "closest" format
  • absolute highest framerate
  • entering "exact" format
  • changing output type

@l1npengtul
Copy link
Owner

Did you try opening the camera stream before calling frame()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants