python :获取百度中国艺人一般人物的脸部图像制作数据集,分析百度搜索中国艺人,打开检测页面找到api。 找到了图像和api的url
将url复制到postman分析
经过简单的分析,发现了GET请求寻呼的机制。 rn表示页数,pn表示开始标签。 ps :经过简单的测试,rn最多只能设置100。 但是足够了。 RESPONSE的人物名为ename,并且图像地址为pic_4n_78
编程是无稽之谈,直接编码
#! /usr/hldhmgsjx/envpython# coding=utf-8 importrequestsimportjsonimportosdownload _ dir=' Chinese _ celeb _ imgs '=false : OS.mkdir (downimpon ) 100url=' https://sp0 resource _ id=28266 from _ mid=500 format=JSON ie=utf-8oe=utf-8 query=中国艺人sort _ key=sort S.text ) figs=JSON _ str [ ' data ' ] [0] [ ' result ' ] foriinfigs 330 img _ RES=requests.get (img _ URL ) if img _ RES.status _ code==2003 360 ext _ str _ splits=img _ its
数据集制作是为了进行深度学习论文实验,打算制作3000个左右的公众人物的脸部数据集,通过上面的脚本下载了4000个左右的原始图像,用dlib进行了脸部的定位。
代码如下所示
importdlibimportcv2importnumpyasnpimporttimeimportosprint ('当前时间: ', time.strftime ) (' % y.% m.% d % h 3360 % m 3360 % time.local time (time.time ) ) ) predictor _ model=' . /。 landmark ) ) ) ) 652 shape _ predictor _ 68 _ face _ landmarks.dat ' detector=dlib.get _ frontal _ face _ face ) arget _ dir=' aligned _ faces ' def cut _ faceimg (path=' images/1 cv2.im read _ color (try : img=cv2.im decodecode dtype=np.uint8)、-1) im _ shape=img.shape im _ h=im _ shape [0] im _ w=im _ shape [1] #灰度img _ gray cv2.imshow('img ', img ) # cv2.waitKey ) #面部数量rectsfaces=dects 0) forIinrange(len(Faces ) ) : sf=faces[i] left=sf.left ) ) right=sf.right ) ) top=sf.top ) ) bottom h=bottom-topw=right-left left=max (0,left-int ) rightint ) w/Expand ) ) top-int(h/Expand ) (bottom=min ) im_h,Bottomint ) h/Expand ) ) #print ) left,rint left 3360 right (dst=cv2.resize (dst,) 224,224 )、interpolation=cv2.inter _ cubic (cv2.im show ) ', dst ) # cv2.waitKey () ct=time.time ) ) local_time=time.localtime ) CT ) data_head=time.strftime ) % y local _ y d,DATA_secs(stamp=(''.join ) time_stamp.split ) [0].split('-' ) ).join ) time_stamp.split ') name=stamp '.jpg ' cv2.im write (OS.path.join ) target_path,name, dst ) def main ) : ifos.path.exists (source _ dir )==false : returnifos.path.exists target _ dir )==ffists
对准附录脸https://download.csdn.net/download/espwyc/12127496
原始数据https://download.csdn.net/download/espwyc/12127497