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: 2 months 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 (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-04-07T06:12:46.000Z (about 2 years ago)
- Last Synced: 2025-03-18T04:31:21.662Z (over 1 year ago)
- Topics: camera, deno, javascript, openpnp
- Language: TypeScript
- Homepage: https://jsr.io/@sigma/camera
- Size: 59.6 KB
- Stars: 2
- Watchers: 2
- 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 api
The default export is the recommended to use.