var video = document.querySelector(".bar_video");
var canvas = document.createElement("canvas");
var context = canvas.getContext("2d");
canvas.width = 640;
canvas.height = 480;
var constraints = { video: { facingMode: "environment" } };
navigator.mediaDevices
.getUserMedia(constraints)
.then(function (mediaStream) {
video.srcObject = mediaStream;
video.onloadedmetadata = function (e) {
video.play();
};
})
.catch(function (err) {
console.log(err.name + ": " + err.message);
});
setInterval(function () {
context.drawImage(
video,
0,
0,
(canvas.width = video.videoWidth),
(canvas.height = video.videoHeight)
);
var image = canvas.toDataURL("image/png");
$.ajax({
url: "/product/code",
type: "post",
data:{
phoneCode:image
},
success:function(res) {
},
error:function (err) {
console.log(err)
}
})
}, 5000);
imgbase = kw.get("phoneCode") # 接受的图片
imgbase=imgbase.split(",")[1]
imgdata = base64.b64decode(imgbase)#解码
url =os.path.join(os.path.abspath(os.path.dirname(__file__)),"0.png")
file = open(url, 'wb')#保存为0.png的图片
file.write(imgdata)
file.close()
image=cv2.imread(url)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
texts = pyzbar.decode(gray)
print(texts)
if texts == []:
return json.dumps({"state": 400})
for text in texts:
code = text.data.decode("utf-8")
print(code)
后端参考文章 https://blog.csdn.net/qq_37924224/article/details/109582507
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有