Comments (4)
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.
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.
Hey!
I've just found that this only happens on cameras that do not have any MJPEG modes (only YUYV modes)
from nokhwa.
This is being fixed in 0.10
from nokhwa.
Related Issues (20)
- Failure to compile nokhwa core v0.1.1 on windows.
- Failure to compile in windows HOT 1
- Compile issue on linux HOT 7
- V4L performance divide by two when starting stream HOT 1
- Compile issue in capture example HOT 2
- Cannot compile on Windows in any version HOT 2
- Support for set Focus distance,not only auto focus
- Not compiling on mac os. HOT 9
- Cannot compile on Windows and Linux at current HEAD ( 4c75bd7e2f77dc40dcfb9f8baa67475955d111a1 ) HOT 3
- "Failed to Fufill" on Original Pi/Pi Zero HOT 3
- How to set the number of buffers to read from the camera? HOT 2
- (Obsolete?) Windows Camera Capture Always Uses 1FPS HOT 1
- Heavy Processing on one frame
- Build Error: error[E0308]: mismatched types - Apple M2
- Error compiling example code. HOT 2
- Wrong `frame_rate` on Windows HOT 5
- Multiple AVFoundation cameras on macOS panics with an NSException
- yuv422 confusions? HOT 2
- Compile issues on v4l2_pix_format in linux kernel 6.2 HOT 3
- Can't compile on archlinux 6.5.5-arch1-1 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nokhwa.