简体   繁体   English

如何使用javascript捕获网络摄像头上的特定坐标?

[英]how to capture specific coordinate on webcam using javascript?

i know how to capture video , this is my code我知道如何捕捉视频,这是我的代码

var context = canvas.getContext('2d');
snap.addEventListener("click", function() {
    context.drawImage(video, 0, 0, 1000, 500);

});

but how to capture specific coordinates ?但是如何捕获特定坐标?

change drawImage() function parametere just resize the picture but still capture whole picture更改 drawImage() 函数参数只是调整图片大小但仍捕获整个图片

You can't avoid capturing the entire camera frame, because that's just how the camera API works.您无法避免捕获整个相机帧,因为相机 API 就是这样工作的。 But you can use the overload of drawImage that takes a source rectangle as an argument:但是您可以使用将源矩形作为参数drawImage重载

context.drawImage(video, sx, sy, sWidth, sHeight, 0, 0, 1000, 500);

Here, sx, sy, sWidth, sHeight indicates the rectangle inside the video frame that you want to draw.这里, sx, sy, sWidth, sHeight表示要绘制的视频帧内的矩形。 This is then stretched to fit inside the destination rectangle;然后将其拉伸以适合目标矩形; if you don't want any stretching, make sure the width and height are the same.如果您不想拉伸,请确保宽度和高度相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM