Giter Club home page Giter Club logo

Comments (4)

hamaluik avatar hamaluik commented on June 1, 2024

Hmm.. I have been able to get it working by manually supplying a known good camera format and then after opening the camera, changing the format appropriately based on what formats are compatible, a la:

use nokhwa::*;

fn main() {
    let cameras = query().expect("can query cameras");
    println!("cameras: {:#?}", cameras);
    let camera = Camera::new(
        0,
        Some(CameraFormat::new(
            Resolution::new(640, 480),
            FrameFormat::YUYV,
            30,
        )),
    );
    match camera {
        Ok(mut c) => {
            let formats = c.compatible_camera_formats();
            println!("compatible formats: {:?}", formats);

            if let Ok(formats) = formats {
                let mut formats: Vec<CameraFormat> = formats
                    .into_iter()
                    .filter(|f| {
                        f.frame_rate() > 20
                            && f.frame_rate() < 40
                            && f.format() == FrameFormat::YUYV
                            && f.width() <= 1920
                    })
                    .collect();
                formats.sort_by(|a, b| a.width().cmp(&b.width()));
                let format = formats.pop().expect("can have a large format");
                println!("choosing format: {:#?}", format);
                c.set_camera_format(format).expect("can set frame format");

                println!("capturing frame");
                match c.frame() {
                    Ok(f) => println!("frame captured! {:?}", f.dimensions()),
                    Err(e) => println!("failed to capture frame: {:?}", e),
                }
            }
        }
        Err(e) => eprintln!("camera open error: {:?}", e),
    }
}

(which works fine and captures the frame successfully)

So I suspect something is going wrong with the "automatic format detection" when calling Camera::new(index, None), or the API seems a bit unintuitive that I have to supply a camera format before I know what camera formats are supported?

From stepping through things with the debugger it seems that Nokhwa is maybe only looking for MJPEG formats, but this camera only supports YUYV formats?

To be clear however, even this approach doesn't always work. The built-in cameras on a surface touch simply do not want to load, no matter what formats I throw at them. I continue to get the same errors as above.

from nokhwa.

l1npengtul avatar l1npengtul commented on June 1, 2024

Yes, the camera API sets the default format to 640x480, MJPEG at 15FPS (for a consistent experience). Considering changing it so that the open camera returns the camera format in 0.10

If you can do any more diggin, that would be great!

from nokhwa.

harryjph avatar harryjph commented on June 1, 2024

Hey!

I've just found that this only happens on cameras that do not have any MJPEG modes (only YUYV modes)

from nokhwa.

l1npengtul avatar l1npengtul commented on June 1, 2024

This is being fixed in 0.10

from nokhwa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.