人脸检测——AFLW准备人脸
来源:互联网 发布:淘宝怎么注册天猫 编辑:程序博客网 时间:2024/06/04 23:21
不多说了,直接代码吧:
生成AFLW_ann.txt的代码,其中包含图像名称 和 图像中人脸的位置(x,y,w,h);
** AFLW中含有aflw.aqlite文件。
import sqlite3list_annotation = list()# Format for saving: path x y w hann_format = "{}/{} {} {} {} {}"conn = sqlite3.connect('aflw.sqlite')fidQuery = 'SELECT face_id FROM Faces'faceIDs = conn.execute(fidQuery)for idx in faceIDs: fidQuery = 'SELECT file_id FROM Faces WHERE face_id = {}'.format(idx[0]) imgID = conn.execute(fidQuery) imgID = [id for id in imgID] imgDataQuery = "SELECT db_id,filepath,width,height FROM FaceImages WHERE file_id = '{}'".format(imgID[0][0]) fileID = conn.execute(imgDataQuery) fileID = [id for id in fileID] 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 = [id for id in faceRect] if len(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" % line for line in list_annotation)
AFLW图片都整理到flickr文件下(含0,1,2三个文件),生成人脸的程序(并且对人脸进行了左右镜像):
import osfrom PIL import Imagefrom PIL import ImageFile# ImageFile.LOAD_TRUNCATED_IMAGES = Trueimport cv2import numpy as npwith open('AFLW_ann.txt','r') as f: lines = f.readlines()save_dir1 = 'data_prepare/net_positive'save_dir2 = 'data_prepare/net_positive_flip'if os.path.exists(save_dir1)==False: os.makedirs(save_dir1)if os.path.exists(save_dir2)==False: os.makedirs(save_dir2)for idx, line in enumerate(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) if image is None: continue if x<=0 and y<=0 and w<=0 and h<=0: continue box = (x, y, x+w, y+h) # patch = image.crop(box) patch = image[box[1]:box[3], box[0]:box[2], :] if patch is None: continue patch1 = patch #.resize((51, 51)) # patch2 = patch1.transpose(Image.FLIP_LEFT_RIGHT) h = patch.shape[0] w = patch.shape[1] iLR = patch.copy() for i in range(h): for j in range(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)
如果帮到你了,请赞赏支持:
阅读全文
0 0
- 人脸检测——AFLW准备人脸
- 合并人脸特征点的sql语句aflw
- 人脸检测——准备非人脸
- 人脸检测源码解析——3、准备数据
- 人脸检测及识别python实现系列(3)——为模型训练准备人脸数据
- 人脸检测——DDFD
- 人脸检测——CascadeCNN
- 人脸检测——xiaomi
- 人脸检测——UnitBox
- 人脸检测——HyperFace
- 人脸检测——MTCNN
- 人脸检测——Compact CascadeCNN
- 人脸检测——MTCNN
- 人脸检测——STN
- 人脸检测——MTCNN
- 人脸检测——fcn
- 人脸检测——DDFD
- 人脸检测的harr检测函数
- 让Apache Shiro保护你的应用
- 欢迎使用CSDN-markdown编辑器
- LeetCode 36 Valid Sudoku (O(1)空间 位运算)
- Spring boot和Mybatis整合+Mysql+jsp页面跳转问题(借助FreeMarker)
- Binder.clearCallingIdentity && Binder.restoreCallingIdentity作用
- 人脸检测——AFLW准备人脸
- google翻译的用法 使用translate.google.com翻译整个网页内容
- ipython notebook实用教程
- Could not find a storyboard named 'Main' in bundle NSBundle?
- 【好久不见】捡起mysql的存储过程
- 根据域名动态获取IP地址(iOS)
- 打造云上代码交付链_CodePipeline实践分享
- 使用WebView在Android中嵌套html网页
- Error:Failed to complete Gradle execution.