当前位置:网站首页>Case of camera opening by tour
Case of camera opening by tour
2022-07-01 21:37:00 【Desperately_ petty thief】
<!doctype html>
<html lang="en">
<head>
<title>js Call the camera to take photos and upload pictures </title>
<meta charset="utf-8">
</head>
<body>
<button onclick="openMedia()"> Turn on camera </button>
<video id="video" width="500px" height="500px" autoplay="autoplay"></video>
<canvas id="canvas" width="500px" height="500px"></canvas>
<button onclick="closeMedia()"> Turn off camera </button>
<script>
let mediaStreamTrack=null; // Video object ( overall situation )
function openMedia() {
let constraints = {
video: { width: 500, height: 500 },
audio: true
};
// get video camera
let video = document.getElementById('video');
let promise = navigator.mediaDevices.getUserMedia(constraints);
promise.then((mediaStream) => {
mediaStreamTrack = typeof mediaStream.stop === 'function' ? mediaStream : mediaStream.getTracks()[1];
video.srcObject = mediaStream;
video.play();
});
setInterval(sendImage, 3000);
}
// Taking pictures
function takePhoto() {
// get Canvas object
let video = document.getElementById('video');
let canvas = document.getElementById('canvas');
let ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0, 500, 500);
// toDataURL --- Can be introduced into 'image/png'--- Default , 'image/jpeg'
let img = document.getElementById('canvas').toDataURL();
// there img Is the picture you get
console.log('img-----', img);
document.getElementById('imgTag').src=img;
}
// Turn off camera
function closeMedia() {
mediaStreamTrack.stop();
}
// Send data to the back end
function sendImage(){
// Create asynchronous objects
var xhr = new XMLHttpRequest();
// Set the type of request and url
xhr.open('get', 'http://localhost:8000/sys/test', true);
//post The request must add a request header or an error will be reported
xhr.setRequestHeader("Content-type","application/json");
// Send a request
// xhr.send({image:document.getElementById('canvas').toDataURL()});
xhr.send();
xhr.onreadystatechange = function () {
// This step is to determine whether the server responds correctly
if (xhr.status == 200) {
console.log(xhr.responseText);
}
};
};
</script>
</body>边栏推荐
- burpsuite简单抓包教程[通俗易懂]
- Difference and use between require and import
- 图片拼图微信小程序源码_支持多模板制作和流量主
- 最近公共祖先(LCA)在线做法
- 最近公共祖先离线做法(tarjan)
- Target detection - Yolo series
- 基于LSTM模型实现新闻分类
- [multithreading] realize the singleton mode (hungry and lazy) realize the thread safe singleton mode (double validation lock)
- Slf4j打印异常的堆栈信息
- 【STM32】STM32CubeMX教程二–基本使用(新建工程点亮LED灯)
猜你喜欢
随机推荐
深度学习 常见的损失函数
2022年低压电工考试试题及答案
idea中类中显示成员变量和方法
“丝路正青春 风采看福建”在闽外籍青年短视频大赛火热征集作品中
300 linear algebra Lecture 4 linear equations
最近公共祖先(LCA)在线做法
多个张量与多个卷积核做卷积运算的输出结果
Comprehensive evaluation and detailed inventory of high-quality note taking software (I) note, obsedian, remnote, flowus
【Opencv450】HOG+SVM 与Hog+cascade进行行人检测
考虑关系的图卷积神经网络R-GCN的一些理解以及DGL官方代码的一些讲解
Vulnerability recurrence - Net ueeditor upload
deb文件安装
Architect graduation summary
Flume面试题
【商业终端仿真解决方案】上海道宁为您带来Georgia介绍、试用、教程
Uniapp uses Tencent map to select points without window monitoring to return users' location information. How to deal with it
burpsuite简单抓包教程[通俗易懂]
cmake工程化相关
PMP证书真的有用吗?
latex如何打空格









