人臉檢測——AFLW準(zhǔn)備人臉

不多說了,直接代碼吧:

生成AFLW_ann.txt的代碼,其中包含圖像名稱 和 圖像中人臉的位置(x,y,w,h);

** AFLW中含有aflw.aqlite文件。


importsqlite3

list_annotation = list()

# Format for saving: path x y w h

ann_format ="{}/{} {} {} {} {}"

conn = sqlite3.connect('aflw.sqlite')

fidQuery ='SELECT face_id FROM Faces'

faceIDs = conn.execute(fidQuery)

foridxinfaceIDs:

fidQuery ='SELECT file_id FROM Faces WHERE face_id = {}'.format(idx[0])

imgID = conn.execute(fidQuery)

imgID = [idforidinimgID]

imgDataQuery ="SELECT db_id,filepath,width,height FROM FaceImages WHERE file_id = '{}'".format(imgID[0][0])

fileID = conn.execute(imgDataQuery)

fileID = [idforidinfileID]

db_id = fileID[0][0]

filepath = fileID[0][1]

faceRectQuery ='SELECT x,y,w,h FROM FaceRect WHERE face_id = {}'.format(idx[0])

faceRect = conn.execute(faceRectQuery)

faceRect = [idforidinfaceRect]

iflen(faceRect)==0:

continue

x,y,w,h =  faceRect[0]

list_annotation.append(ann_format.format(db_id,filepath,x,y,w,h))

with open("AFLW_ann.txt",'w') as f:

f.writelines("%s\n"% lineforlineinlist_annotation)

AFLW圖片都整理到flickr文件下(含0,1,2三個文件),生成人臉的程序(并且對人臉進(jìn)行了左右鏡像):


importos

fromPILimportImage

fromPILimportImageFile

# ImageFile.LOAD_TRUNCATED_IMAGES = True

importcv2

importnumpy as np

with open('AFLW_ann.txt','r') as f:

lines = f.readlines()

save_dir1 ='data_prepare/net_positive'

save_dir2 ='data_prepare/net_positive_flip'

ifos.path.exists(save_dir1)==False:

os.makedirs(save_dir1)

ifos.path.exists(save_dir2)==False:

os.makedirs(save_dir2)

foridx, lineinenumerate(lines):

s1 = line.strip().split(' ')

image_path = s1[0]

x = int(s1[1])

y = int(s1[2])

w = int(s1[3])

h = int(s1[4])

print(image_path)

# image = Image.open(image_path)

image = cv2.imread(image_path)

ifimageisNone:

continue

ifx<=0andy<=0andw<=0andh<=0:

continue

box = (x, y, x+w, y+h)

# patch = image.crop(box)

patch = image[box[1]:box[3], box[0]:box[2], :]

ifpatchisNone:

continue

patch1 = patch#.resize((51, 51))

# patch2 = patch1.transpose(Image.FLIP_LEFT_RIGHT)

h = patch.shape[0]

w = patch.shape[1]

iLR = patch.copy()

foriinrange(h):

forjinrange(w):

iLR[i,w-1-j] = patch[i,j]

patch2 = iLR

s2 = image_path.split('/')

image_name = s2[-1]

save_path1 = save_dir1+'/'+str(idx)+image_name +'.jpg'

save_path2 = save_dir2+'/'+'l'+str(idx)+image_name +'.jpg'

#patch1.save(save_path1, 'jpeg')

#patch2.save(save_path2, 'jpeg')

cv2.imwrite(save_path1, np.array(patch1))

cv2.imwrite(save_path2, np.array(patch2))

print(idx)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 人臉識別,基于人臉部特征信息識別身份的生物識別技術(shù)。攝像機(jī)、攝像頭采集人臉圖像或視頻流,自動檢測、跟蹤圖像中人臉,...
    利炳根閱讀 1,952評論 0 1
  • 《裕語言》速成開發(fā)手冊3.0 官方用戶交流:iApp開發(fā)交流(1) 239547050iApp開發(fā)交流(2) 10...
    葉染柒丶閱讀 28,776評論 5 20
  • 《ilua》速成開發(fā)手冊3.0 官方用戶交流:iApp開發(fā)交流(1) 239547050iApp開發(fā)交流(2) 1...
    葉染柒丶閱讀 11,521評論 0 11
  • 1、個性化推薦的算法不準(zhǔn)確,推薦的內(nèi)容和標(biāo)簽不符合,例如偏好中選擇“人文”,推薦的top10條結(jié)果中有8條不屬于人...
    小皮皮高高閱讀 1,281評論 0 2
  • 昨天晚上站在天臺給媽媽打電話,秋天的晚風(fēng)吹出許多清晰的涼意,被秋風(fēng)包裹的涼意仿佛帶了一種天地廣闊而蒼茫的孤單與寂寥...
    三更笙閱讀 578評論 0 4

友情鏈接更多精彩內(nèi)容