(python版本)数据增强:
数据图片可用于填充数据集;
一张图片可以通过随机裁剪,旋转,缩放,水平反转等操作来生成多张相似的图片;
https://blog.csdn.net/y459541195/article/details/100140203
https://github.com/aleju/imgaug
github上也有专门的库可以调用; (这个更全,包括一些添加噪声等更高级的增强)
还有如果想获取自己人脸的数据集可以用过视频或这摄像头来过去图片
import cv2
import dlib
import os
import sys
import random
output_dir = ‘./img’
size = 128
if not os.path.exists(output_dir):
os.makedirs(output_dir)
改变图片的亮度与对比度
def relight(img, light=1, bias=0):
w = img.shape[1]
h = img.shape[0]
# image = []
for i in range(0, w):
for j in range(0, h):
for c in range(3):
tmp = int(img[j, i, c] * light + bias)
if tmp > 255:
tmp = 255
elif tmp < 0:
tmp = 0
img[j, i, c] = tmp
return img