本文整理了常见的通过opencv实现数据处理的函数:包括、添加噪声(高斯、椒盐、随机噪声)、灰暗化处理、光照处理。目的在于往数据集里增加噪声,略微增加数据集的挑战性。并通过函数批量实现数据的处理。
import os
import cv2
import numpy as np
import random
####变亮
def imgBrightness(img1, c, b):
h, w, ch = img1.shape
blank = np.zeros([h, w, ch], img1.dtype)
rst = cv2.addWeighted(img1, c, blank, 1-c, b)
return rst
### 变暗
def darker(image, percetage=0.9):
image_copy = image.copy()
w = image.shape[1]
h = image.shape[0]
# get darker
for xi in range(0, w):
for xj in range(0, h):
image_copy[xj, xi, 0] = int(image[xj, xi, 0] * percetage)
image_copy[xj, xi, 1] = int(image[xj, xi, 1] * percetage)
image_copy[xj, xi, 2] = int(image[xj, xi, 2

最低0.47元/天 解锁文章
2183

被折叠的 条评论
为什么被折叠?



