refactor🎨: 优化图库

This commit is contained in:
HibiKier
2023-08-18 00:42:10 +08:00
parent 48b720b00a
commit 38abb74c4c
6 changed files with 38 additions and 25 deletions
+10 -7
View File
@@ -1,6 +1,8 @@
import cv2
import random
import warnings
from pathlib import Path
import cv2
import numpy as np
from PIL import Image
@@ -8,16 +10,17 @@ from PIL import Image
def pix_random_change(img):
# Image转cv2
img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
img[0, 0, 0] = random.randint(0, 0xfffffff)
img[0, 0, 0] = random.randint(0, 0xFFFFFFF)
# cv2转Image
img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
return img
def pix_random_change_file(path: str):
def pix_random_change_file(path: Path):
# 注意:cv2.imread()不支持路径中文
str_path = str(path.absolute())
warnings.filterwarnings("ignore", category=Warning)
img = cv2.imread(path)
img[0, 0, 0] = random.randint(0, 0xfffffff)
cv2.imwrite(path, img)
img = cv2.imread(str_path)
img[0, 0, 0] = random.randint(0, 0xFFFFFFF)
cv2.imwrite(str_path, img)
return str_path