Created
March 26, 2023 14:55
-
-
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,
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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