nannou-org / nannou

A Creative Coding Framework for Rust.
https://nannou.cc/
6.04k stars 305 forks source link

Camera / webcam Support #464

Open mitchmindtree opened 4 years ago

mitchmindtree commented 4 years ago

This is an issue for tracking camera/webcam support!


Desired Features

Nice-to-haves


Existing Work

Unfortunately a lot of these boil down to using C/C++ bindings under the hood. rscam looks nice in that at least v4l seems to be the way to get access to cameras on linux.

Perhaps it's worth starting a project similar to CPAL, but for camera input rather than audio input/output? CPCL - cross-platform camera library?

mulimoen commented 4 years ago

Hi, I am the author of the libuvc bindings. I believe libuvc fulfills all the desired features, apart from being implemented in c, and not having event notifcation (this could be implemented through libusb). The bindings should be in a usable state right now, although still somewhat incomplete.

Is there anything this community would like from the libuvc bindings, or some wanted features? I would be happy to discuss how our libraries may be developed to meet the need of nannou and users

Niko-La commented 4 years ago

Hi, I am the author of the libuvc bindings. I believe libuvc fulfills all the desired features, apart from being implemented in c, and not having event notifcation (this could be implemented through libusb). The bindings should be in a usable state right now, although still somewhat incomplete.

Is there anything this community would like from the libuvc bindings, or some wanted features? I would be happy to discuss how our libraries may be developed to meet the need of nannou and users

Can we access a uvc webcam on mobile using otg cable through wasm?

Webrtc does not support this yet. The goal is to build pwa with usb webcam as input without the need to make native android app.

mulimoen commented 3 years ago

I am not sure if libusb would function on wasm, given that runtimes would need to passthrough the usb devices. webusb never really got implemented other than in Chrome, but maybe one could use emscripten here.

mofeing commented 3 years ago

I found nokhwa, that seems to tick some of the desired features.

The library basically unifies multiple backends (Video4Linux, libuvc, OpenCV, GStreamer, ...) into a common API. MSMF (Windows) & WASM support is experimental and AVFoundation (macOS) is planned/WIP.

  • Enumerate available camera devices on the system.

query_devices function.

  • Enumerate device info and capabilities.
    • Info should include a unique identifier / human-readable name.
    • Capabilities should include supported resolution, rate and format combos.

CameraInfo returned by query_devices contains human-readable name. Capabilities like resolution, rate and format are known once you create a Camera with resolution, frame_rate and frame_format methods.

  • Captured frame should provide size, format and pointer to data. We can create an easy/efficient API for loading this data into a wgpu::Texture.

Can directly copy a frame to a wgpu texture with Camera.frame_texture method.

  • Play/pause API. This could be worked around by destroying the stream and creating a new one.

Camera.open_stream, Camera.stop_stream 🙂

The only features that do not seem to be available are the async results and frame capture via callback or iterator (frame capture must be explicitly called via Camera.frame method).

l1npengtul commented 3 years ago

Hello, I am the maintainer of nokhwa.

I am interested in helping, feel free to open a issue over on nokhwa's issue board. For now, I will implement a method that allows a direct capture into a nannou wgpu texture.

Hopefully the new features required can be merged in by either 0.4 or 0.5.

E: I have also taken over maintainership of libuvc-rs. I plan to update libuvc after the 0.4 release of nokhwa (The libuvc backend is currently due to some compilation errors associated with it).

l1npengtul commented 3 years ago

There might be one issue - nokhwa's licensing is MPL-2.0, while nannou's licensing is MIT/APL2. If there is a need to change the license, let me know.

l1npengtul commented 3 years ago

I've updated nokhwa to 0.4 - it checks all the tickboxes now!

patrick91 commented 2 years ago

@l1npengtul do you have an example of using nokhwa with nannou? 😊

l1npengtul commented 2 years ago

@l1npengtul do you have an example of using nokhwa with nannou? 😊

Sorry, I was busy (and assumed this was dead) so not yet, but I'll work on it!

vvzen commented 2 years ago

Hi all! any progress on this? this functionality would be quite cool to have in nannou! Thanks!

V