当前位置:网站首页>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>边栏推荐
- TOPS,处理器运算能力单位、每秒钟可进行一万亿次
- 新版Free手机、PC、平板、笔记本四端网站缩略展示图在线一键生成网站源码
- Significance and measures of security encryption of industrial control equipment
- [multithreading] realize the singleton mode (hungry and lazy) realize the thread safe singleton mode (double validation lock)
- MySQL清空表数据
- Learn white box test case design from simple to deep
- 名单揭晓 | 2021年度中国杰出知识产权服务团队
- Practical project notes (I) -- creation of virtual machine
- leetcode刷题:栈与队列04(删除字符串中的所有相邻重复项)
- 薛定谔的日语学习小程序源码
猜你喜欢

Review notes of Zhang Haifan in introduction to software engineering (Sixth Edition)

合成大西瓜小游戏微信小程序源码/微信游戏小程序源码

leetcode刷题:栈与队列03(有效的括号)

8K HDR!| Hevc hard solution for chromium - principle / Measurement Guide

九章云极DataCanvas公司蝉联中国机器学习平台市场TOP 3

基于K-means的用户画像聚类模型

PMP与NPDP之间的区别是什么?

深度学习 常见的损失函数

EMC-电路保护器件-防浪涌及冲击电流用
![[multithreading] realize the singleton mode (hungry and lazy) realize the thread safe singleton mode (double validation lock)](/img/bf/524e78473625a31c024783ccec8d46.png)
[multithreading] realize the singleton mode (hungry and lazy) realize the thread safe singleton mode (double validation lock)
随机推荐
目标检测——Yolo系列
名单揭晓 | 2021年度中国杰出知识产权服务团队
require与import的区别和使用
统计字符中每个字符出现的个数
杰理之蓝牙耳机品控和生产技巧【篇】
burpsuite简单抓包教程[通俗易懂]
物联网rfid等
面试题:MySQL的union all和union有什么区别、MySQL有哪几种join方式(阿里面试题)[通俗易懂]
ngnix基础知识
Is it safe to open an account online? Can a novice open a stock trading account.
MySQL清空表数据
【深度学习】利用深度学习监控女朋友的微信聊天?
Gaussdb (for MySQL):partial result cache, which accelerates the operator by caching intermediate results
Introduction à l'ingénierie logicielle (sixième édition) notes d'examen de Zhang haifan
Difference and use between require and import
PHP 读取ini或env类型配置
开环和闭环是什么意思?
升级版手机检测微信工具小程序源码-支持多种流量主模式
杰理之、产线装配环节【篇】
Manually implement function isinstanceof (child, parent)