Tencent 图像识别 API - 优图
注册帐号:http://open.youtu.qq.com/
得到AppSecret 和 Key
安装 SDK:
npm install tencentyoutuyun
写一个service module
/**
* Tencent Youtu service
* Get API docs from
*/
var logger = require('../common').logging.getLogger('service/youtu');
var config = require('../config');
var youtusdk = require('tencentyoutuyun'),
youtuconf = youtusdk.conf,
youtu = youtusdk.youtu;
youtuconf.setAppInfo(config.youtu.appId, config.youtu.secretId, config.youtu.secretKey, config.youtu.userId, 0);
exports = module.exports = youtu;
写一个 testcase - test/youtu.js
var request = require('supertest');
var assert = require('chai').assert;
var expect = require('chai').expect;
var path = require('path');
require('chai').should();
var logger = require('../common').logging.getLogger('test/youtu');
var config = require('../config');
var youtu = require('../services/youtu');
describe('YouTu API', function() {
this.timeout(10000);
it('get image tag', function(done) {
youtu.imagetag(path.join(__dirname, '/a.jpeg'), function(data) {
logger.info(JSON.stringify(data));
if (data.code !== 200) {
done(new Error(JSON.stringify(data)));
} else {
done();
}
});
})
})
a.jpeg
run testcase
mocha test/youtu.js
结果:
{
"httpcode": 200,
"code": 200,
"message": "HTTP OK",
"data": {
"errorcode": 0,
"errormsg": "OK",
"tags": [
{
"tag_name": "天空",
"tag_confidence": 54
},
{
"tag_name": "建筑",
"tag_confidence": 14
},
{
"tag_name": "高楼",
"tag_confidence": 46
}
],
"faces": []
}
}
从上可以看出,tag_confidence用来体现识别的自信度,哪个对象是主体。还可以看到,是可以识别人脸的,“faces”。
上个微信之父 …
it('get image face', function(done) {
youtu.imagetag(path.join(__dirname, '/zxl.png'), function(data) {
logger.info(JSON.stringify(data));
if (data.code !== 200) {
done(new Error(JSON.stringify(data)));
} else {
done();
}
});
})
zxl.png
结果:
{
"httpcode": 200,
"code": 200,
"message": "HTTP OK",
"data": {
"errorcode": 0,
"errormsg": "OK",
"tags": [
{
"tag_name": "大头照",
"tag_confidence": 13
},
{
"tag_name": "男孩",
"tag_confidence": 65
}
],
"faces": []
}
}
其他
优图还有很多其他API,值得研究!