mui安卓拍照人脸识别api返回result为空
wayery 发布于2018-05 浏览:2910 回复:2
0
收藏
最后编辑于2018-07
直接上代码
这是图片转化64base代码
function getBase64Image(img){
var canvas = document.createElement("canvas");
  var width = img.width;
  var height = img.height;
  canvas.width = width;
  canvas.height = height;
  var ctx = canvas.getContext("2d");
  ctx.drawImage(img,0,0,width,width);
  var dataURL = canvas.toDataURL();
return(dataURL);
}
node后台代码

ar AipFace = require('baidu-aip-sdk').face;//引入人脸识别sdk
var express = require('express')
var bodyParser = require('body-parser')
var fs = require('fs')
var http = require('http')


// console.log(AipFace)


var app = express();


var App_Id = "10944604";
var API_Key = "aIgEHzskTphSrxCHqqo3FDGr"
var Secret_Key = "WqqZlGnuqELRqscu3Hs8EYSWPxTMBhPM"
//实例化sdk
var client = new AipFace(App_Id,API_Key,Secret_Key);


var image = fs.readFileSync('images/3.png')
var base64Img = new Buffer(image.toString('base64'))
console.log(base64Img)


app.use('',express.static(__dirname+''))


app.use(bodyParser.urlencoded({limit:'50mb',extended:true}))


//解决跨域问题
app.all('*',function(req,res,next){
    res.header('Access-Control-Allow-Orign','*')
    res.header('Content-Type','application/json;charset = utf-8')
    next()
})

app.post('/', function (req,res){
    var imgData = req.body.URL;
    console.log(imgData)
    var base64Data = imgData.replace(/\s/g,"+");
//     console.log(base64Data)
    var base64Data = base64Data.replace(/^data:image\/\w+;base64,/,"")
//     console.log(base64Data)
    client.match([imgData,base64Img]).then(function(result){
        console.log(result)
        var score = result.result[0].score;


        res.json({score:score})
    })
}).listen(8000)

收藏
点赞
0
个赞
共2条回复 最后由秒1818回复于2018-07
#3秒1818回复于2018-07

现在都用V3版本了

0
#2秒1818回复于2018-07

需要注意的是,图片的base64编码是不包含图片头的

0
TOP
切换版块