下载地址:https://www.pan38.com/share.php?code=pvvmX 提取码:8888
订单自动检测和抢单功能。主程序包含图像预处理、OCR识别、订单解析和条件判断等模块。使用时需要安装Tesseract OCR引擎并配置路径。系统会持续监控指定屏幕区域。
import cv2
import pytesseract
import numpy as np
import time
import pyautogui
from geopy.distance import geodesic
配置参数
MIN_PRICE = 30 # 最低可接受价格
MAX_DISTANCE = 5 # 最大可接受距离(公里)
SCREENSHOT_AREA = (100, 200, 800, 600) # 订单区域坐标
REFRESH_INTERVAL = 0.5 # 检测间隔(秒)
def preprocess_image(image):
gray = cv2.cvtColor(image, cv2.COLORBGR2GRAY) , threshold = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY)
return threshold
def extract_text(image):
custom_config = r'--oem 3 --psm 6'
text = pytesseract.image_to_string(image, config=custom_config)
return text.strip()
def parse_order_info(text):
lines = [line for line in text.split('\n') if line.strip()]
orders = []
for line in lines:
if '¥' in line:
try:
price = float(line.split('¥')[1].split()[0])
address = line.split('地址:')[1].split('距离')[0].strip()
distance = float(line.split('距离:')[1].split('km')[0].strip())
orders.append({'price': price, 'address': address, 'distance': distance})
except Exception as e:
print(f"解析错误: {e}")
return orders
def check_order_condition(order):
return order['price'] >= MIN_PRICE and order['distance'] <= MAX_DISTANCE
def click_order(position):
pyautogui.click(position)
print(f"已点击订单位置: {position}")
def main():
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
while True:
screenshot = pyautogui.screenshot(region=SCREENSHOT_AREA)
img = np.array(screenshot)
processed_img = preprocess_image(img)
text = extract_text(processed_img)
orders = parse_order_info(text)
for i, order in enumerate(orders):
if check_order_condition(order):
y_position = SCREENSHOT_AREA[1] + 50 + (i * 80)
click_position = (SCREENSHOT_AREA[0] + 100, y_position)
click_order(click_position)
time.sleep(0.2)
time.sleep(REFRESH_INTERVAL)
if name == "main":
main()
ytesseract==0.3.10
opencv-python==4.9.0.80
numpy==1.26.4
pyautogui==0.9.54
geopy==2.4.1
Pillow==10.2.0
[Settings]
min_price = 30
max_distance = 5
refresh_interval = 0.5
[Screen]
x1 = 100
y1 = 200
x2 = 800
y2 = 600
[OCR]
tesseract_path = C:\Program Files\Tesseract-OCR\tesseract.exe
import cv2
import numpy as np
from PIL import ImageGrab
import pytesseract
import re
class OrderDetector:
def init(self, config):
self.config = config
self.template = cv2.imread('order_template.png', 0)
def screen_capture(self):
img = ImageGrab.grab(bbox=self.config['monitor_area'])
return cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
def match_template(self, img):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
res = cv2.matchTemplate(gray, self.template, cv2.TM_CCOEFF_NORMED)
return np.where(res >= 0.8)