对数据集进行扰动

import cv2
import numpy as np
import os

def randLighting(img):
    saturation = 1.5
    exposure = 1.5
    
    
    hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)

    r0 = np.random.rand()
    r1 = np.random.rand()
    r2 = np.random.rand()
    r3 = np.random.rand()

    saturation = r0 * (saturation - 1) + 1
    exposure = r1 * (exposure - 1) + 1
    if (r2 > 0.5):
        exposure = 1 / exposure
    if (r3 > 0.5):
        saturation = 1 / saturation
    
#    for i in range(row):
#        for j in range(col):
#            hsv[i,j,2] *= exposure
    hsv[:,:,2]=cv2.multiply(hsv[:,:,2],exposure)
    return cv2.cvtColor(hsv, cv2.COLOR_HSV2RGB)

imgDir = "/home/disk/lyw/AuoPose/Data/carbody1/"
outDir = "/home/disk/lyw/AuoPose/Data/images/train/carbody/"
imgs = os.listdir(imgDir)
for i in range(len(imgs)):
    imgName = imgDir + imgs[i]
    img = cv2.imread(imgName)
    dst = randLighting(img)
    l = len(imgs[i])
    cv2.imwrite(imgDir + imgs[i][:l-4] + '_' + '1' + '.jpg', dst)

你可能感兴趣的:(计算机视觉,深度学习)