|
@@ -6,6 +6,7 @@ import random
|
|
|
import pygetwindow as gw
|
|
|
import re
|
|
|
from PIL import Image
|
|
|
+from PIL import ImageFilter
|
|
|
import io
|
|
|
|
|
|
def compress_image(image, target_size = 100 * 1024):
|
|
@@ -23,6 +24,7 @@ def compress_image(image, target_size = 100 * 1024):
|
|
|
|
|
|
return compressed_image.getvalue()
|
|
|
|
|
|
+'''
|
|
|
def binarize_image(image):
|
|
|
# 将图片转换为黑白格式(二值化)
|
|
|
# 这里使用Pillow库来进行图片二值化
|
|
@@ -30,7 +32,17 @@ def binarize_image(image):
|
|
|
threshold = 128 # 设定二值化阈值,0~255之间,通常取128
|
|
|
image = image.point(lambda x: 0 if x < threshold else 255, '1') # 进行二值化处理
|
|
|
return image
|
|
|
+'''
|
|
|
|
|
|
+def binarize_image(image):
|
|
|
+ # 将图片转换为灰度图像
|
|
|
+ image = image.convert("L")
|
|
|
+ # 降噪处理(中值滤波)
|
|
|
+ image = image.filter(ImageFilter.MedianFilter(size=3))
|
|
|
+ # 自适应阈值二值化
|
|
|
+ threshold = image.point(lambda x: 0 if x < 128 else 255, '1')
|
|
|
+
|
|
|
+ return threshold
|
|
|
|
|
|
|
|
|
def waitFindImg(imgPath, waitTime, preWaitTime):
|