Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sigmasd/camera
A cross platform video capture library with a focus on machine vision. (Deno ffi bindings to openpnp-capture)
https://github.com/sigmasd/camera
camera deno javascript openpnp
Last synced: 24 days ago
JSON representation
A cross platform video capture library with a focus on machine vision. (Deno ffi bindings to openpnp-capture)
- Host: GitHub
- URL: https://github.com/sigmasd/camera
- Owner: sigmaSd
- License: mit
- Created: 2024-04-05T18:49:12.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2024-04-07T06:12:46.000Z (7 months ago)
- Last Synced: 2024-04-07T13:36:32.632Z (7 months ago)
- Topics: camera, deno, javascript, openpnp
- Language: TypeScript
- Homepage: https://jsr.io/@sigma/camera
- Size: 59.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Camera
A cross platform video capture library with a focus on machine vision. (Deno ffi
bindings to openpnp-capture)## Usage
```ts
import { Camera } from "jsr:@sigma/camera";if (import.meta.main) {
console.log("OpenPnp Camera Test Program");
console.log("Using openpnp version:", Camera.getLibraryVersion());
//Camera.setLogLevel(7);
using cam = new Camera();const device = cam.devices().at(0);
if (!device) throw new Error("no device found");console.log("Device name:", device.name());
console.log("Device formats:", device.formats());// choose the format with the highest resolution
const formatInfo = device.formats().sort((a, b) => b.width - a.width).at(0);
if (!formatInfo) throw new Error("no format found");using stream = device.stream(formatInfo);
if (!stream) throw new Error("no stream found");let frameNum = 0;
for await (const frame of stream.next({ delay: 100 })) {
if (frameNum === 5) break;
writeBufferAsPPM(++frameNum, formatInfo.width, formatInfo.height, frame);
console.log(`Written frame to frame_${frameNum}.ppm`);
}
}function writeBufferAsPPM(
frameNum: number,
width: number,
height: number,
buffer: Uint8Array,
): boolean {
const ENCODER = new TextEncoder();
const fname = `frame_${frameNum}.ppm`;
const fout = Deno.createSync(fname);
fout.writeSync(ENCODER.encode(`P6 ${width} ${height} 255\n`));
fout.writeSync(buffer);
fout.close();
return true;
}
```This library exports 3 levels of abstractions:
- ffi: raw deno bindings to openpnp
- openpnp: thin javascript wrapper over the raw bidings
- default export: high level javascript apiThe default export is the recommended to use.