抖音代运营成功案例,搜索引擎seo如何优化,全球影响力最大的人,asp网站建设专家设计并实现了一个图片增强的组件#xff0c;具体功能如下#xff1a; 图片数据增强#xff0c;包括且不限于#xff1a;图片旋转、比例增强、高斯噪声、饱和度变换等若图片包含对应标注boundingbox#xff0c;也支持对应变换#xff0c;保证圈选内容的不变性实现多种方式… 设计并实现了一个图片增强的组件具体功能如下 图片数据增强包括且不限于图片旋转、比例增强、高斯噪声、饱和度变换等若图片包含对应标注boundingbox也支持对应变换保证圈选内容的不变性实现多种方式random组合增加增强效果 具体依赖
import cv2
import numpy as np
import copy
import random
from PIL import Image
import os数据增强方法
classmethod
def resize_image(cls, image, mode: str img, notes: [[dict]] None, scale_percent: int None):if scale_percent is None:scale_percent random.randrange(30, 80)width int(image.shape[1] * scale_percent / 100)height int(image.shape[0] * scale_percent / 100)resized_image cv2.resize(image, (width, height))if mode notes and notes is None:raise ValueError(When mode is set to notes, you must provide notes data.)elif mode notes:points [i.get(points) for i in notes]resized_points []for box in points:resized_box []for point in box:x int(point[0] * scale_percent / 100)y int(point[1] * scale_percent / 100)resized_box.append([x, y])resized_points.append(resized_box)resized_notes copy.deepcopy(notes)for i in range(len(resized_notes)):resized_notes[i][points] resized_points[i]return resized_image, resized_noteselif mode img:return resized_imageclassmethod
def add_gaussian_noise(cls, image, mode: str img, notes: [[dict]] None, mean70, std20):noise np.random.normal(mean, std, image.shape).astype(np.uint8)noisy_image cv2.add(image, noise)if mode notes and notes is None:raise ValueError(When mode is set to notes, you must provide notes data.)elif mode notes:gaussian_notes copy.deepcopy(notes)return noisy_image, gaussian_noteselif mode img:return noisy_image完整代码
source