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

Rust API suggestions, finding device id from its name #9

Open
Boscop opened this issue Jul 7, 2017 · 3 comments
Open

Rust API suggestions, finding device id from its name #9

Boscop opened this issue Jul 7, 2017 · 3 comments

Comments

@Boscop
Copy link

Boscop commented Jul 7, 2017

In the Rust API it would be useful to be able to enumerate the capture devices so that one can get a device's name and id (and possibly max resolution) before initializing the capture on it with init().
Because the installed devices on a system change over time and don't always have the same ID, so I store the camera that I want to use by its name in my application's config file and then I want to iterate over the available cameras and find its ID by its name before calling init() with that id.
This could be done by having an Iterator that yields DeviceInfo which has .id() -> usize, .name() -> String, .max_resolution() -> (u32, u32).

What do you think?

(Btw, I love ESCAPI, it makes dealing with a webcam so much easier.)

@codec-abc
Copy link

codec-abc commented Sep 18, 2017

I might need it at some time too. I only use the C++ library (I don't use the Rust wrapper at all ,not that I don't want to, but I can't) and consume it a C# "side" using PInvoke calls to do what I want to achieve. To get the cameras info and properties I used protocol buffers to exchange data in a big bytes array.

This is the proto file I written to exchange data between C++ and C#:

syntax = "proto3";

package camera;

enum CaptureEncoding {
    UNKNOWN = 0;
    RGBA32 = 1;
    RGB24 = 2;
    YUY2 = 3;
    NV12 = 4; 
    MJPG = 5;
}

message CaptureFormat {
    uint32 width = 1;
    uint32 height = 2;
    double framerate = 3;
    CaptureEncoding encoding = 4;
}

message Camera {
    string cameraName = 5;
    repeated CaptureFormat formats = 6;
}

message CameraList {
    repeated Camera cameras = 7;
}

With that, I got all the info I need on the C# side to choose the camera with the capture format I want.

Since there are multiples Rust libraries for protobuf it may be a viable road to solve this issue. Or we may use an alternative format like JSON for instance (because integrating Protobuf is not that easy). @jarikomppa What is your opinion on the matter?

@Boscop
Copy link
Author

Boscop commented Sep 19, 2017

Btw, what I do at the moment to find the camera ID from its name (with my Rust bindings) is:

		let cam_id = (|| {
			for i in 0..camera_count {
				if Capture::get_device_name(i) == cam_name {
					return Some(i);
				}
			}
			return None;
		})().ok_or("webcam not found")?;

@codec-abc
Copy link

Yeah it is the same idea. My solution is easier to use from a client point of view because I know almost all the properties of each camera upfront with a single API call but I have to admit that it is quite cumbersome to integrate into the code. I think it might worth taking a look at this pull request because it seems that we could have a unique identifier per camera which is more robust to identify a camera than a bare index in a list.

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