咱們知道前段時間有報道說Facebook說他們的人臉識別技術達到,甚至超過了人類識別人臉的能力。很酷是否是。今天介紹個能夠直接用的更酷的東西:物體識別。html
若是你想讓程序知道這張圖大概是講什麼的,怎麼辦?Rekognition(是的,破名字...)就能夠作到。他們家提供了最普通的人臉識別之外,還提供了場景識別,明星識別,以及今天要講的概念識別。
先直觀感覺一下Demo。經過這張圖,Rek能夠識別出70%機率這張圖講的是beach。segmentfault
This image is about : beach:70.65% cloud:66.57% sky:33.56% island:10.88% shore:7.56%
「丫絕對是找了個special case!」,是的我也這麼想的。好,我決定用個人narrative拍的照來測試下。這是我18號在路上的一張照片。其中很明顯的有兩種東西:汽車和路牌。api
分析結果以下測試
basketball court:60.2% car:31.89% street sign:29.07% motor scooter:20.09% pop bottle:12.09%
看到第一個失望了吧。籃球個毛啊,哪隻眼睛看到籃球了...但日後看就以爲我靠,還挺準。汽車,路牌,小摩托。ui
自動我買了Narrative之後,就一直在思考怎麼把這些圖片數據用起來。那就讓我用Rekognition的Concept API來下手吧。API很簡單,若是不傳圖片信息而用URL來表示,就用GET就ok了。
遇到一個問題:若是按Docs填寫jobs參數就永遠沒有結果,只能照抄Demo頁面裏的參數,Concept的jobs寫scene_understanding_3。
我用15張照片作了一個批處理,算出這15張照片對應的Concept的數據,都添加到一個統一的results裏。url
var request = require('request'), qs = require('querystring'); var pictures = [ 'xxx.jpg', 'xxxx.jpg', ]; var results = {}; for (var i = 0; i < pictures.length; i++) { processImg(pictures[i]); } function processImg(pic) { calculate('http://xxx.qiniudn.com/' + pic, function (info) { for (var i = 0; i < info.scene_understanding.matches.length; i++) { var match = info.scene_understanding.matches[i]; if (results[match.tag]) { results[match.tag] += match.score; } else { results[match.tag] = match.score; } } }) } function calculate(url, cb) { var params = { api_key: "4321", api_secret: "8765", name_space: "apiDemo", user_id: "apiDemo", jobs: "scene_understanding_3", urls: url }; request.get({ url: 'http://rekognition.com/func/api/?' + qs.stringify(params) }, function (error, response, body) { if (!error && response.statusCode == 200) { var info = JSON.parse(body); if (cb) cb(info); } } ) }
照片存在七牛了,每次傳一個URL就ok。最後獲得的結果以下。spa
{ "awning":0.0556, "architecture":0.0099, "dorm room":0.11510000000000001, "people":0.0508, "face":0.1062, "finger":0.1521, "jeans":0.1502, "cat":0.0189, "pet":0.0087, "seat belt":0.21689999999999998, "document":0.0095, "human":0.0722, "flare":0.0093, "laptop":0.3152, "batting helmet":0.0095, "desk":0.0174, "molding":0.1219, "pc":0.1488, "television":0.0394, "flight":0.0098, "person":0.0095, "loudspeaker":0.0295, "apartment room":0.0094, "rat":0.1126, "lecture":0.0112, "aquarium":0.0104, "underpants":0.0089 }
其中最高的是0.3152,是...laptop...=.=|||。你丫是猴子派來黑個人嗎!
第二名是比較奇怪的seat belt。第三名是手指(不不不,我只放算了幾張白天的照片!)。後面還有牛仔褲,PC等等。基本仍是能夠斷定經過這少許數據就能必定程度斷定一我的成天在跟什麼玩意兒混。
讓我有點奇怪的是裏面竟然沒有手機,因而去瀏覽了一遍那幾張圖,真的沒有。code
哎,再讓我傷心一下子...orm