escapi
escapi copied to clipboard
Detecting when webcam was unplugged
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?
Not that I can think of.
On Mon, Sep 4, 2017 at 11:14 PM, Boscop [email protected] wrote:
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?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jarikomppa/escapi/issues/10, or mute the thread https://github.com/notifications/unsubscribe-auth/AEQ_R2BMXxPgWuxXuMKHDHCoraCMcg7mks5sfFo-gaJpZM4PMOWh .
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).
That seems useful! I'd appreciate if that PR got merged.
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?