Skip to content

Instantly share code, notes, and snippets.

@kalwalt
Created March 26, 2023 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kalwalt/44ed3da14928cd2983ffe9fccb011bfe to your computer and use it in GitHub Desktop.
Save kalwalt/44ed3da14928cd2983ffe9fccb011bfe to your computer and use it in GitHub Desktop.
This .ts file is a mock of VideoCapture from Opencv.js, modified to fit my needs,
export function VideoCapture(videoSource: any) {
var video: any = null;
if (typeof videoSource === 'string') {
video = document.getElementById(videoSource);
} else {
video = videoSource;
}
if (!(video instanceof HTMLVideoElement)) {
throw new Error('Please input the valid video element or id.');
return;
}
var canvas = document.createElement('canvas');
canvas.width = video.width;
canvas.height = video.height;
var ctx = canvas.getContext('2d');
ctx!.drawImage(video, 0, 0, video.width, video.height);
return ctx!.getImageData(0, 0, video.width, video.height)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment