zhenxun_bot/plugins/image_management/send_image/anti.py
2023-07-29 09:53:44 +08:00

27 lines
623 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import cv2
import random
import warnings
import numpy as np
from PIL import Image
def pixRandomChange(img):
# Image转cv2
img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
img[0, 0, 0] = random.randint(0, 0xfffffff)
# cv2转Image
img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
return img
def pixRandomChangeFile(path):
# 注意cv2.imread()不支持路径中文
warnings.filterwarnings("ignore", category=Warning)
img = cv2.imread(path)
img[0, 0, 0] = random.randint(0, 0xfffffff)
cv2.imwrite(path, img)
print('finish')
pixRandomChangeFile('./0.jpg')