Kaynağa Gözat

!2 show more color video

pcacc 5 ay önce
ebeveyn
işleme
85ffc5e00a
3 değiştirilmiş dosya ile 17 ekleme ve 5 silme
  1. 2 2
      app_dongri.py
  2. 12 0
      scriptBase/comon.py
  3. 3 3
      templates/index_dongri.html

+ 2 - 2
app_dongri.py

@@ -85,8 +85,8 @@ def monitor_begin():
     last_time = current_time
     regionRet, regionPos = game_region()
     screenshot = pyautogui.screenshot(region=regionPos)
-    binary_img = binarize_image(screenshot)
-    compressed_data = compress_image(binary_img)
+    #binary_img = binarize_image(screenshot)
+    compressed_data = compress_image(screenshot)
     
     image_data_base64 = base64.b64encode(compressed_data).decode('utf-8')
     socketio.emit('image_data', image_data_base64)

+ 12 - 0
scriptBase/comon.py

@@ -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):

+ 3 - 3
templates/index_dongri.html

@@ -24,12 +24,12 @@
         <h3>请选择时间间隔:</h3>
         <select id="timeInterval">
             <option value="500">0.5 秒</option>
-            <option value="1000">1 秒</option>
+            <option value="1000" selected>1 秒</option>
             <option value="2000">2 秒</option>
             <option value="5000">5 秒</option>
             <option value="0">停止</option>
         </select>
-        <canvas id="canvas" width="520" height="292"></canvas>
+        <canvas id="canvas" width="300" height="400"></canvas>
     </div>
 
     <div class="status-container ">
@@ -170,7 +170,7 @@
             get_title();
             read_cfg();
             executeTask();
-            setTimeout(stopPageAndCloseSocket, 120000); // 2分钟 = 120000毫秒
+            setTimeout(stopPageAndCloseSocket, 60000); // 1分钟 = 60000毫秒
         };
         
     </script>