diff --git a/.gitignore b/.gitignore index e3b6db5..15260a6 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ AnimalParty.spec Ui/__pycache__/ imgs/nums imgs/num -PaddleOCR-json_v.1.3.0 \ No newline at end of file +PaddleOCR-json_v.1.3.0 +testrecources \ No newline at end of file diff --git a/PickExpnumber.py b/PickExpnumber.py new file mode 100644 index 0000000..4012888 --- /dev/null +++ b/PickExpnumber.py @@ -0,0 +1,38 @@ +import cv2 +import numpy as np +tolerancex,tolerancey = 20,20 +explocation = { + "room": (1500, 400, 300, 200), + "quickgame": (1500, 200, 300, 200), +} +def getAllExp(bounding_rects): + sorted_arr = bounding_rects[bounding_rects[:, 1].argsort()] + return sorted_arr[0] +# 加载图像 +def getExpimg(path,model): + image_path = cv2.imread(path) + if model == 'room': + region_x, region_y, region_w, region_h = explocation["room"] + else: + region_x, region_y, region_w, region_h = explocation["quickgame"] + image = image_path[region_y:region_y+region_h, region_x:region_x+region_w] + lower_color = np.array([42,180,140]) + upper_color = np.array([45, 200, 150]) + mask = cv2.inRange(image, lower_color, upper_color) + # 形态学操作 + kernel = np.ones((10, 10), np.uint8) + erosion = cv2.erode(mask, kernel, iterations=1) + mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel) + # 查找轮廓 + contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE,) + # 处理每个轮廓 + bounding_rects = [] + for contour in contours: + x, y, w, h = cv2.boundingRect(contour) + bounding_rects.append([x+region_x,y+region_y,w,h]) + bounding_rects = np.array(bounding_rects) + result = getAllExp(bounding_rects) + rectangle_x,rectangle_y,rectangle_w,rectangle_h = result[0]-tolerancex,result[1]-tolerancey,result[2]+tolerancex+10,result[3]+tolerancey+10 + exp_pic = image_path[rectangle_y:rectangle_y+rectangle_h,rectangle_x:rectangle_x+rectangle_w] + cv2.imwrite('./imgs/exp.png',exp_pic) +getExpimg('./testrecources/expjs.png','room') diff --git a/README.md b/README.md index a3717ff..7170c9a 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,10 @@ - [x] 无用的功能 ----- +## v1.82 + +- 使用新算法检测经验数字坐标,移除固定坐标 + ## v1.81 - fix bugs diff --git a/Ui/setup.py b/Ui/setup.py index f3e348b..ab59c22 100644 --- a/Ui/setup.py +++ b/Ui/setup.py @@ -52,6 +52,7 @@ def setupUi(self, setup): self.horizontalLayout.addItem(spacerItem) self.HyperlinkLabel = HyperlinkLabel(self.layoutWidget) self.HyperlinkLabel.setObjectName("HyperlinkLabel") + self.HyperlinkLabel.setUrl('https://ocr.space/') self.horizontalLayout.addWidget(self.HyperlinkLabel) self.OK = PrimaryPushButton(setup) self.OK.setGeometry(QtCore.QRect(270, 210, 153, 32)) diff --git a/__pycache__/PickExpnumber.cpython-311.pyc b/__pycache__/PickExpnumber.cpython-311.pyc new file mode 100644 index 0000000..db78f72 Binary files /dev/null and b/__pycache__/PickExpnumber.cpython-311.pyc differ diff --git a/__pycache__/controWin_inter.cpython-311.pyc b/__pycache__/controWin_inter.cpython-311.pyc index 2375951..5b7967a 100644 Binary files a/__pycache__/controWin_inter.cpython-311.pyc and b/__pycache__/controWin_inter.cpython-311.pyc differ diff --git a/controWin_inter.py b/controWin_inter.py index 8a54e79..e650728 100644 --- a/controWin_inter.py +++ b/controWin_inter.py @@ -13,6 +13,7 @@ from qfluentwidgets import FluentIcon as FIF from circle_detection import isthereCircle +from PickExpnumber import getExpimg THRESHOLD=0.02 @@ -167,7 +168,8 @@ def quickgame(self, limit_number, shutdown, game_number): if self.execute_condition(current_time, 'endgame.png', 5): avg=self.ifthereimg('./imgs/end.png', '结束游戏')[1] if avg is not None: - self.get_screenshot(region=(1641,266,70,40)) + self.get_screenshot()#获取截图捕获经验 + getExpimg('./imgs/screenshot.png','quickgame') time.sleep(0.3) pyautogui.leftClick(avg[0],avg[1]) self.action_ready = False @@ -231,7 +233,9 @@ def roomgame(self): self.routine_click('./imgs/expup.png', '升级') self.routine_click('./imgs/expup2.png', '升级2') if self.ifthereimg('./imgs/xiangce.png', '结算')[0]: - self.get_screenshot(region=(1645,448,70,40)) + self.get_screenshot() # 获取截图捕获经验 + getExpimg('./imgs/screenshot.png', 'room') + time.sleep(0.3) getexp=self.Ocr("./imgs/exp.png") if getexp == 'error': continue diff --git a/imgs/exp.png b/imgs/exp.png index 6b0bc25..0257565 100644 Binary files a/imgs/exp.png and b/imgs/exp.png differ diff --git a/mainGui.py b/mainGui.py index 335e90c..d5773c2 100644 --- a/mainGui.py +++ b/mainGui.py @@ -11,7 +11,7 @@ from Ui.myIcon import myIcon from setup_inter import setupWin -current_version = 1.81 +current_version = 1.82 class mainwindow(SplitFluentWindow): def __init__(self): super().__init__() diff --git "a/imgs/QQ\346\210\252\345\233\27620231004171510.png" b/testrecources/expjs.png similarity index 100% rename from "imgs/QQ\346\210\252\345\233\27620231004171510.png" rename to testrecources/expjs.png