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

Detecting when webcam was unplugged #10

Open
Boscop opened this issue Sep 4, 2017 · 4 comments
Open

Detecting when webcam was unplugged #10

Boscop opened this issue Sep 4, 2017 · 4 comments

Comments

@Boscop
Copy link

Boscop commented Sep 4, 2017

How can I detect when the webcam was unplugged?

In my loop I could check if countCaptureDevices() changed from last frame, and if it did, I can check if the currently opened cam is still in the list of connected ones, but is there a better way?

@jarikomppa
Copy link
Owner

jarikomppa commented Sep 6, 2017 via email

@codec-abc
Copy link

codec-abc commented Sep 18, 2017

Has someone looked at this pull request? From the commits it suggests that someone solved this problem, plus there are some other goodies (like having a unique identifier for each camera).

@Boscop
Copy link
Author

Boscop commented Sep 19, 2017

That seems useful! I'd appreciate if that PR got merged.

@Boscop
Copy link
Author

Boscop commented Sep 19, 2017

Btw, what I do at the moment to check if the camera was disconnected since the last frame (with my Rust bindings) is:

	// TODO: count_devices() might be expensive, don't do every frame
	pub fn is_connected(&mut self) -> bool {
		let n = Capture::count_devices();
		if self.camera_count == n {
			true // might not be true if this cam got unplugged and another one plugged in since last frame
		} else { // check if this cam is still plugged in
			self.camera_count = n;
			for i in 0..n {
				if Capture::get_device_name(i) == self.cam_name {
					return true;
				}
			}
			false
		}
	}

It works but it's not elegant. Btw, do you know if count_devices() / countCaptureDevices() is an expensive function call?

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

3 participants