12 #include <emscripten.h>
27 console.log(
"[WebCamera] Requesting stream...");
30 if ($0 == 0) facingMode =
"user";
31 else if ($0 == 1) facingMode =
"environment";
33 navigator.mediaDevices.getUserMedia({
"video": {
"facingMode": facingMode } })
35 console.log(
"[WebCamera] Stream acquired");
37 let video = document.querySelector(
"#capture-video");
38 video.srcObject = stream;
41 console.log(
"[WebCamera] Failed to acquire stream");
73 if (size.width == 0 || size.height == 0)
74 return CVMat(0, 0, CV_8UC3);
77 if (size.width !=
_image.cols || size.height !=
_image.rows)
87 let video = document.querySelector(
"#capture-video");
88 let canvas = document.querySelector(
"#capture-canvas");
92 let ctx = canvas.getContext(
"2d",
true,
false,
"srgb",
true);
94 let width = video.videoWidth;
95 let height = video.videoHeight;
97 if (width == 0 || height == 0)
100 canvas.width = width;
101 canvas.height = height;
102 ctx.drawImage(video, 0, 0, width, height);
103 let imageData = ctx.getImageData(0, 0, width, height);
105 writeArrayToMemory(imageData.data, $0);
130 let video = document.querySelector(
"#capture-video");
131 let width = video.videoWidth;
132 let height = video.videoHeight;
134 setValue($0, video.videoWidth,
"i32");
135 setValue($1, video.videoHeight,
"i32");
160 if (size.width ==
_image.cols && size.height ==
_image.rows)
167 let video = document.querySelector(
"#capture-video");
168 let stream = video.srcObject;
174 let constraints = {};
175 constraints[
"width"] = $0;
176 constraints[
"height"] = $1;
178 stream.getVideoTracks().forEach(track => {
179 track.applyConstraints(constraints);
182 console.log(
"[WebCamera] Applied resolution " + $0 +
"x" + $1);
183 }, size.width, size.height);
196 let video = document.querySelector(
"#capture-video");
197 let stream = video.srcObject;
199 if (stream ===
null) {
200 console.log(
"[WebCamera] Stream is already closed");
203 stream.getVideoTracks().forEach(track => {
204 if (track.readyState ==
"live") {
206 stream.removeTrack(track);
210 console.log(
"[WebCamera] Stream closed");
Interface to access the camera through the browser.
WebCameraFacing
Facing modes for the camera.
void close()
Closes the video stream.
bool isReady()
Returns whether the video stream has been acquired.
void open(WebCameraFacing facing)
Acquires a video stream.
CVMat read()
Reads the current frame.
void setSize(CVSize2i size)
Requests a video size from the browser.
CVSize2i getSize()
Gets the size of the video input.