Skip to content

Instantly share code, notes, and snippets.

@kalwalt
Created March 26, 2023 15:00
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/fc9a57d55a8897cc154dcf06f5018254 to your computer and use it in GitHub Desktop.
Save kalwalt/fc9a57d55a8897cc154dcf06f5018254 to your computer and use it in GitHub Desktop.
const convertImageData = (
imageData: ImageData,
frame: any,
cv: any,
videoSize: any
) => {
if (!(frame instanceof cv.Mat)) {
throw new Error("Please input the valid cv.Mat instance.");
return;
}
if (frame.type() !== cv.CV_8UC4) {
throw new Error("Bad type of input mat: the type should be cv.CV_8UC4.");
return;
}
if (frame.cols !== videoSize.width || frame.rows !== videoSize.height) {
throw new Error(
"Bad size of input mat: the size should be same as the video."
);
return;
}
console.log(imageData);
return frame.data.set(imageData.data);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment