突然感覺自己要“食鹽”趕緊快點把這個月的部落格補上,分享一個小工具
先參考技術文檔,然後跟着步驟一步步來做就行。技術文檔 https://ai.baidu.com/docs#/Face-Detect-V3/top
1、先是要擷取一個Access token
我打碼的地方是需要用百度賬戶去擷取的,具體如何擷取,可以到這裡擷取 https://ai.baidu.com/docs#/
AppID和API Key分别複制到下面的代碼的【你的ID】和【你的密碼】
2、輸入圖檔,得到結果
然後就很簡單了,給你個你要檢測的人臉的url,然後根據文檔輸入可以獲得的一些參數。就可以了,全部代碼如下在文末,結果如下(我用的是webread函數,urlread也可以可能代碼要有所修改):
clear;clc
Host = webread('https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=【你的ID】&client_secret=【你的密碼】');
Access_Token = Host.access_token;
request_url = 'https://aip.baidubce.com/rest/2.0/face/v3/detect';
request_url = [ request_url, '?access_token=', Access_Token ];
%% URL read
PATH = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1559491417857&di=d183d6a220b231a80db8e6c2d1b53378&imgtype=0&src=http%3A%2F%2Fwww.taiwan.cn%2Flocal%2Fxinwentupian%2F201501%2FW020150123610242240067.jpg';
P = webread( request_url,'image',PATH,...
'image_type','URL',...
'face_field',{'age','beauty','expression','face_shape','gender','glasses',...
'race','quality','eye_status','emotion','face_type','landmark','landmark150' });
IM = imread( PATH );
imshow(IM)
hold on
left = P.result.face_list.location.left;
top = P.result.face_list.location.top;
width = P.result.face_list.location.width;
height = P.result.face_list.location.height;
plot( left, top, 'r+' )
plot( left+width, top, 'r+' )
plot( left, top+height, 'r+' )
plot( left+width, top+height, 'r+' )
最後就是想說,百度這個做的還是很棒的,有什麼問題大家積極交流。