人脸检测——生成矫正人脸——cascade cnn的思想, 但是mtcnn的效果貌似更赞
来源:互联网 发布:淘宝仓管工作职责 编辑:程序博客网 时间:2024/05/19 21:14
简单粗暴,不多说,直接代码吧:(这个代码实在上篇博客的基础上:人脸检测——AFLW准备人脸)
先要生成AFLW_ann.txt。
import osfrom PIL import Imagefrom PIL import ImageFileImageFile.LOAD_TRUNCATED_IMAGES = Trueimport cv2import numpy as npdef crop_for_cal(sn, xn, yn, n): with open('AFLW_ann.txt','r') as f: lines = f.readlines() save_dir1 = 'data_prepare/cal_positive_'+str(n)+'_12' save_dir2 = 'data_prepare/cal_positive_'+str(n)+'_24' save_dir3 = 'data_prepare/cal_positive_'+str(n)+'_48' if os.path.exists(save_dir1)==False: os.makedirs(save_dir1) if os.path.exists(save_dir2)==False: os.makedirs(save_dir2) if os.path.exists(save_dir3)==False: os.makedirs(save_dir3) for idx, line in enumerate(lines): spl1 = line.strip().split(' ') image_path = spl1[0] x = int(spl1[1]) y = int(spl1[2]) w = int(spl1[3]) h = int(spl1[4]) x = int(x-xn*w/sn) y = int(y-yn*h/sn) w = int(w/sn) h = int(h/sn) # 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 if patch.shape[0]<10 and patch.shape[1]<10: continue #patch1 = patch.resize((12, 12)) #patch2 = patch.resize((24, 24)) #patch3 = patch.resize((48, 48)) patch1 = cv2.resize(patch, (12, 12)) patch2 = cv2.resize(patch, (24, 24)) patch3 = cv2.resize(patch, (48, 48)) spl2 = image_path.split('/') image_name = spl2[-1] save_path1 = save_dir1+'/'+str(idx)+image_name + '.jpg' save_path2 = save_dir2+'/'+str(idx)+image_name + '.jpg' save_path3 = save_dir3+'/'+str(idx)+image_name + '.jpg' #patch1.save(save_path1, 'jpeg') #patch2.save(save_path2, 'jpeg') #patch3.save(save_path3, 'jpeg') cv2.imwrite(save_path1, np.array(patch1)) cv2.imwrite(save_path2, np.array(patch2)) cv2.imwrite(save_path3, np.array(patch3))if __name__ == '__main__': s_set = (0.83, 0.91, 1.0, 1.10, 1.21) x_set = (-0.17, 0, 0.17) y_set = (-0.17, 0, 0.17) n = 0 for x in x_set: for y in y_set: for s in s_set: n = n + 1 crop_for_cal(s, x, y, n)
如果帮到你了,请赞赏支持:
阅读全文
1 0
- 人脸检测——生成矫正人脸——cascade cnn的思想, 但是mtcnn的效果貌似更赞
- 人脸检测——mtcnn思想,生成negative、positive、part样本。
- 人脸检测(三)——Multi-task CNN(MTCNN)
- 人脸检测——MTCNN
- 人脸检测——MTCNN
- 人脸检测——MTCNN
- 人脸检测——矫正人脸生成标签
- 人脸检测——MTCNN学习笔记
- 人脸检测算法MTCNN
- 人脸检测之MTCNN训练自己的数据
- 基于NCNN的人脸检测MTCNN实现过程
- 基于 MTCNN/TensorFlow 实现人脸检测
- 基于 MTCNN/TensorFlow 实现人脸检测
- 基于Opencv/TensorFlow/mtcnn/Facenet的实时人脸检测/人脸识别
- Win端搭建基于ncnn框架的MTCNN人脸检测
- 走近人脸检测(4)——传统人脸检测技术和 CNN 的结合
- 人脸检测——Faster R-CNN
- 人脸检测——Faster R-CNN
- Linux 设备驱动之 UIO 用户态驱动优缺点分析
- javascript插件的几种写法
- ViewPager+Fragment 多层嵌套问题,第二次进入显示空白
- JAVA中service实现类中的@Service(demoService)是什么意思?
- Hive中java对数据库、表的操作
- 人脸检测——生成矫正人脸——cascade cnn的思想, 但是mtcnn的效果貌似更赞
- docker 远程连接
- JPA入门
- 116. Populating Next Right Pointers in Each Node
- 点滴学习Linux---- mail命令发送邮件
- 51nod 1444 破坏道路
- 什么是8K视频技术!8K视频测试解决方案
- java错误mark_1
- Vivado HLS 学习笔记(一)