spring cloud 与人脸识别项目记录一

最近在进行人脸识别的项目,是利用spring cloud框架及基础进行开发的,开始真的是一头雾水,什么都不懂,网上的资料很多,但是很多感觉大家都不是很认真的就拿出来写上,搞得自己很烦。我想把自己学习到的东西记录一下,顺便帮助大家学习一点知识。目前就记录一下自己在项目中学习到的新知识,不敢把源码亮出来,因为这毕竟是一个项目,多多体谅,但是尽量能让大家用起来。希望大佬们可以指教我,我这个人特别虚心接收指教,就怕学不够,嘿嘿。




一、前端摄像头拍照问题

PC端拍照,主要需要利用摄像头,但是存在浏览器兼容的问题,之前参照H5拍照,发现我的谷歌浏览器不能出现摄像头,后面找到一篇大佬的源码程序大佬vue摄像头拍照才发现,之前的H5拍照的一个函数已经过时了,根本不行,根据大佬的源程序,我进行改造。贴出源码,希望大家能用到。

1.在<template>里面


<div style="margin-left: 50px;width: 85%">

  <p style="margin-bottom: 2px">请拍摄1张自拍图像

    <div class="takePhotostyle" id="takeindex">

      <i class="el-icon-plus" @click="handleChange">

    <div id="imgindex" >

      <img  v-if="imageUrl" :src="imageshow" class="avatar" >

  <el-dialog title="拍摄图像"  :visible.sync="visibleCamera" placement="bottom" trigger="click" ref="dialog" width="45%">

    <div style="display: flex; width: 970px">

      <div class="cameraBox">

        <div style="text-align: center;font-size: 14px;font-weight: bold;margin-bottom: 10px;">摄像头

        <video id="video" width="550" height="440" style="border: 1px solid #ccc" ref="myvedio">

        <div class="iCenter" style="margin-top: 20px">

          <el-Button type='primary' long size='large' @click="takePhone" style='width: 200px;'>

            拍照

        <div style="text-align: center;font-size: 14px;font-weight: bold;margin-bottom: 10px;">

          拍摄效果

        <canvas id='canvas' width='350' height='440' style="display: block;border: 1px solid #ccc"

                ref="mycanvas">

        <div class="iCenter" style="margin-top: 20px">

          <el-Button type='primary' long size='large' @click="takePhoneUpfile"

                    style='width: 200px;' v-if="preViewVisible" >保存

</div>

</template>

2.<script>里面

data(){

return {

isMultiple:true,

    formDate:'',

    imageUrl:false,

    show:true,

    visibleCamera:false,

    preViewVisible:false,

    blobFile:null,

    canvas:null,

    video:null,

    MediaStreamTrack:null,

    memberInit: {}, //form标记

    formface:{

input:'',

    }

}

},

mounted() {

this.memberInit = Object.assign({}, this.form);

  // 摄像头

  this.canvas = document.getElementById('canvas');

  this.video = document.getElementById('video');

  //this.setHeaders() // 上传token

//this.handleCamera();

},

methods: {

handleChange() {

//console.log(this.$refs.dialog);

    this.visibleCamera =true;

    this.preViewVisible =false;

    setTimeout(() => {

this.canvas =this.$refs.mycanvas;

      this.video =this.$refs.myvedio;

      //console.log(this.canvas);

      this.canvas.getContext('2d').clearRect(0, 0, this.canvas.width, this.canvas.height);

      let that =this;

      if (navigator.getUserMedia || navigator.mediaDevices.getUserMedia) {

navigator.mediaDevices.getUserMedia({

video:true,

          //audio: true

        }).then(function (stream) {

that.MediaStreamTrack =typeof stream.stop ==='function' ? stream : stream.getTracks()[1];

          that.video.srcObject = stream;

          that.video.play()

}).catch(function (err) {

console.log(err)

})

}else if (navigator.getMedia) {

navigator.getMedia({

video:true

        }).then(function (stream) {

that.MediaStreamTrack = stream.getTracks()[1];

          that.video.srcObject = stream;

          that.video.play()

}).catch(function (err) {

console.log(err)

})

}else if (navigator.webkitGetUserMedia) {

navigator.webkitGetUserMedia({

video:true

        }).then(function (stream) {

that.MediaStreamTrack = stream.getTracks()[1];

          that.video.srcObject = stream

that.video.play()

}).catch(function (err) {

console.log(err)

})

}else {

navigator.mozGetUserMedia({

video:true

        }).then(function (stream) {

that.MediaStreamTrack = stream.getTracks()[1];

          that.video.srcObject = stream;

          that.video.play()

}).catch(function (err) {

console.log(err)

})

}

}, 0);

  },

  takePhone() {

let that =this

    //console.log(that.canvas);

    that.canvas.getContext('2d').drawImage(this.video, 140, 0, 350, 440, 0, 0, 350, 440)// context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);

    let dataurl = that.canvas.toDataURL('image/jpeg')

that.blobFile = that.dataURLtoFile(dataurl, 'camera.jpg')

that.preViewVisible =true

  },

  //保存图片

  takePhoneUpfile() {

let that =this

    // let formData = new FormData()

// formData.append('file', that.blobFile)

    let type ='png';

    that.canvas.getContext('2d').drawImage(this.video, 140, 0, 350, 440, 0, 0, 350, 440)// context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);

    let dataurl = that.canvas.toDataURL(type);

    dataurl = dataurl.replace(this._fixType(type),'image/octet-stream');

    console.log(dataurl);

    //let save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');

    that.imageshow = dataurl;

    let divposition = document.getElementById('takeindex');

    let imgposition = document.getElementById('imgindex');

    divposition.style.margin ="0 150px 0 ";

    imgposition.style.margin ="-148px 0 1px 0 ";

    that.imageUrl =true;

    that.visibleCamera=false;

    //将图片放在上传的list中

    // that.onSubmit(formData) // formdata方式上传图片

  },

  _fixType(type){

type = type.toLowerCase().replace(/jpg/i, 'jpeg');

    let r = type.match(/png|jpeg|bmp|gif/)[0];

    return 'image/' + r;

  },

  dataURLtoFile(dataurl, filename) {

let arr = dataurl.split(',')

let mime = arr[0].match(/:(.*?);/)[1]

let bstr =atob(arr[1])

let n = bstr.length

    let u8arr =new Uint8Array(n)

while (n--) {

u8arr[n] = bstr.charCodeAt(n)

}

return new File([u8arr], filename, {type: mime})

},


3.style里面

.index{

width:85%;

  height:auto;

  margin-left:50px;

}

.centerbu{

text-align:center;

  width:85%;

  height:auto;

  margin-top:20px;

}

.centerbu >.buttonnum{

width:60%;

  margin-top:15px;

}

.el-dialog{

width:970px;

}

.takePhotostyle{

display:inline-block;

  text-align:center;

  cursor:pointer;

  outline:0;

  background-color:#fbfdff;

  border:1px dashed #c0ccda;

  border-radius:6px;

  -webkit-box-sizing:border-box;

  box-sizing:border-box;

  width:148px;

  height:148px;

  line-height:146px;

  vertical-align:top;

}

.takePhotostyle i{

font-size:30px;

  color:#8c939d;

  font-style:normal;

  font-weight:400;

  font-family:element-icons!important;

}

.avatar{

width:148px;

  height:148px;

  line-height:146px;

}

基本上该程序能在各个浏览器运用,并且能够实现弹窗拍照。大家记得引入element-ui,进行使用

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,736评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,167评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,442评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,902评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,302评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,573评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,847评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,562评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,260评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,531评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,021评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,367评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,016评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,068评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,827评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,610评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,514评论 2 269

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,102评论 0 10
  • 教程一:视频截图(Tutorial 01: Making Screencaps) 首先我们需要了解视频文件的一些基...
    90后的思维阅读 4,491评论 0 3
  • 超高速音视频编码器用法: ffmpeg [options] [[infile options] -i infile...
    吉凶以情迁阅读 4,406评论 0 4
  • 一、什么是企业社工? 答:“把社工专业服务延伸到企业领域,运用社会工作的方法服务企业员工、管理者和消费者,倡导企业...
    小社工阅读 934评论 0 0
  • 老甲与老乙是一对夫妻,老甲为夫,老乙为妇,都快到了知天命的年纪,日子过得不紧不慢,他们年轻的时候遇上了计...
    小徐有点洋阅读 261评论 0 2