【发布时间】:2021-12-13 07:23:53
【问题描述】:
我使用ctx.translate() 和ctx.scale() 翻转了一个网络摄像头流以使其镜像,但它也翻转了画布上绘制的所有其他内容。有没有办法翻转网络摄像头视频而不是画布上的其他绘图(如文本)?
这是我目前正在使用的代码(摘录):
const setupcamera = () => {
navigator.mediaDevices
.getUserMedia({
video: { width: 600, height: 400 },
audio: false,
})
.then((stream) => {
video.srcObject = stream;
});
};
const detectpose = async () => {
const poses = await detector.estimatePoses(video, false);
console.log(poses);
ctx.drawImage(video, 0, 0, 600, 400);
ctx.font = "30px Comic Sans MS";
ctx.fillStyle = "green";
ctx.fillText(po, elbowx, elbowy);
setupcamera();
video.addEventListener("loadeddata", async () => {
ctx.translate(600, 0);
ctx.scale(-1, 1);
detector = await poseDetection.createDetector(
poseDetection.SupportedModels.MoveNet
);
setInterval(detectpose, 20);
});
我想过在翻转的画布上画一个新画布,但如果可能的话,我想在同一个画布上画出所有东西。
【问题讨论】:
-
您能否分享您在画布上绘制网络摄像头的代码以及在其上绘制文本的代码?
-
是的,我编辑了代码并添加了相关部分。如果有任何混淆,请告诉我。
-
是否可以在画布上方放一个
div,然后将文字设置为div? -
@TheKNVB 好主意没想到。会尝试
标签: javascript html5-canvas draw