人脸检测——准备非人脸
来源:互联网 发布:用homebrew安装mysql 编辑:程序博客网 时间:2024/05/16 07:53
简单粗暴,不多说,直接代码吧:
import osimport randomfrom PIL import Imagefrom PIL import ImageFileImageFile.LOAD_TRUNCATED_IMAGES = Trueimport cv2import numpy as npdef random_crop(imagepath): # image = Image.open(imagepath) # len_rand = random.randint(0, min(image.size[0], image.size[1])-1) # x_rand = random.randint(0, image.size[0]-len_rand-1) # y_rand = random.randint(0, image.size[1]-len_rand-1) image = cv2.imread(imagepath) len_rand = random.randint(0, min(image.shape[1], image.shape[0])-1) x_rand = random.randint(0, image.shape[1]-len_rand-1) y_rand = random.randint(0, image.shape[0]-len_rand-1) box = (x_rand, y_rand, x_rand+len_rand, y_rand+len_rand) # return image.crop(box) return image[box[1]:box[3], box[0]:box[2], :]save_dir = 'data_prepare/net_negative'if os.path.exists(save_dir)==False: os.makedirs(save_dir)neg_img_dir = 'imagenet_selected'for file in os.walk(neg_img_dir): filenames = file[2]for idx, filename in enumerate(filenames): filepath = neg_img_dir + '/' + filename for i in range(33): image_crop = random_crop(filepath) savepath = save_dir + '/' + str(i) + filename # image_crop_12 = image_crop.resize((15,15)) if image_crop is None: continue if image_crop.shape[0]<10 and image_crop.shape[1]<10: continue image_crop = cv2.resize(image_crop, (12, 12)) # image_crop_12.save(savepath, 'jpeg') cv2.imwrite(savepath, np.array(image_crop)) print (idx)
如果帮到你了,请赞赏支持:
阅读全文
0 1
- 人脸检测——准备非人脸
- 人脸检测——AFLW准备人脸
- 人脸检测源码解析——3、准备数据
- 人非人,花非花
- 人脸检测及识别python实现系列(3)——为模型训练准备人脸数据
- 所托非人勿怪人,忠人之事需灵变
- 再谈“所托非人勿怪人,忠人之事需灵变”
- 非人生物
- 人脸检测——DDFD
- 人脸检测——CascadeCNN
- 人脸检测——xiaomi
- 人脸检测——UnitBox
- 人脸检测——HyperFace
- 人脸检测——MTCNN
- 人脸检测——Compact CascadeCNN
- 人脸检测——MTCNN
- 人脸检测——STN
- 人脸检测——MTCNN
- 基于imcrop,裁剪人脸视频
- Android坐标系和视图坐标系
- Web安全之SQL注入攻击技巧与防范
- PHP mktime() 创建日期
- 详解Nginx与Apache共用80端口的配置方法
- 人脸检测——准备非人脸
- Glide如何加载https图片(简明操作)
- 使用js获取到css3的兼容前缀
- Can not perform this action after onSaveInstanceState异常源码分析
- Amazon Athena 性能调整
- BZOJ 1663: [Usaco2006 Open]赶集 floyd(划掉+dp
- Spring MVC数据转换、格式化、校验、文件上传和下载
- 测试
- Java & Pascal & C++——容斥原理例题——切蛋糕