优化操作逻辑

This commit is contained in:
2025-03-03 12:28:44 +08:00
parent 6767b5dcff
commit 207dc8a06a
3 changed files with 46 additions and 31 deletions

View File

@@ -25,7 +25,7 @@ def ShapeDetection(img:cv2.typing.MatLike):
percentage=nonzero_num/img_obj.size percentage=nonzero_num/img_obj.size
# print(f"nonzero_num:{nonzero_num},size={img_obj.size}, pos:{percentage}") # print(f"nonzero_num:{nonzero_num},size={img_obj.size}, pos:{percentage}")
# 通过计算图像白值的比例来判断实心还是空心 # 通过计算图像白值的比例来判断实心还是空心
if(percentage>0.55): if(percentage>0.63):
boll_count+=1 boll_count+=1
return (all_cont,boll_count) return (all_cont,boll_count)

View File

@@ -1,3 +1,3 @@
{ {
"index": 3185 "index": 8538
} }

View File

@@ -29,9 +29,11 @@ def flush_wind_pos():
not_find=True not_find=True
time.sleep(1) time.sleep(1)
continue continue
_ocr_pos=[pos[0]+0,pos[1]+180,375,296] w=pos[2]-pos[0]
_ocr_boll=[pos[0]+99,pos[1]+440,172,27] h=pos[3]-pos[1]
_mouse_touch=[pos[0]+0,pos[1]+603,145,70] _ocr_pos=[pos[0]+0,pos[1]+int(180/877*h),w,int(296/877*h)]
_ocr_boll=[pos[0]+int(99/376*w),pos[1]+int(440/877*h),int(172/376*w),int(27/877*h)]
_mouse_touch=[pos[0]+0,pos[1]+int(603/877*h),int(145/376*w),int(70/877*h)]
return return
# 识别屏幕文字 # 识别屏幕文字
@@ -110,7 +112,7 @@ class ser(object):
self.x=x self.x=x
self.y=y self.y=y
def touch(self): def touch(self):
self.write(f"Z4\r") self.write(f"Z6\r")
time.sleep(0.1) time.sleep(0.1)
self.write(f"Z0\r") self.write(f"Z0\r")
time.sleep(0.05) time.sleep(0.05)
@@ -137,26 +139,38 @@ class ser(object):
def password(self,p:str): def password(self,p:str):
index=0 index=0
p_len=len(p) p_len=len(p)
try_times=0
while index<p_len: while index<p_len:
pos=self.touch_table[p[index]] pos=self.touch_table[p[index]]
myprint(f"点击 index={index},{p[index]}") myprint(f"点击 index={index},{p[index]}")
self.togo(pos[0],pos[1]) self.togo(pos[0],pos[1])
self.touch() self.touch()
self.avoid() self.avoid()
if(find_text(identify_text(),"手机已锁定")): time.sleep(0.1) # 这里延时防止界面更新延迟导致的识别异常
if(index==5): # if(find_text(identify_text(),"手机已锁定")):
myprint(f"手机锁定中,已全部输入") # if(index==5):
return True # myprint(f"手机锁定中,已全部输入")
myprint(f"密码输入状态异常 index={index},password={p}") # return True
return False # myprint(f"密码输入状态异常 index={index},password={p}")
# return False
num=find_input_count() num=find_input_count()
myprint(f"已输入个数为 {num}") myprint(f"已输入个数为 {num}")
if(num==index+1): if(num==index+1):
try_times=0
index+=1 index+=1
elif(num==0 and index==5): elif(num==0 and index==5):
return True return True
else: elif(num==index):
try_times+=1
myprint(f"点击未识别,重试 index={index}") myprint(f"点击未识别,重试 index={index}")
if(try_times>20):
myprint(f"尝试次数过多 times={try_times},退出")
s.back()
return False
else:
myprint(f"密码输入状态异常 index={index},num={num},password={p}")
s.back()
return False
@@ -179,10 +193,11 @@ if __name__ == "__main__":
while(True): while(True):
try: try:
text=identify_text() text=identify_text()
if(find_text(text,"安装系统软件")): if(find_text(text,"安装系统")):
unknown_scr=False unknown_scr=False
myprint("进入密码界面") myprint("进入密码界面")
s.enter() s.enter()
time.sleep(0.2)
# s.avoid() # s.avoid()
elif(find_text(text,"请输入解锁密码")): elif(find_text(text,"请输入解锁密码")):
unknown_scr=False unknown_scr=False
@@ -218,20 +233,20 @@ if __name__ == "__main__":
if __name__ == "__main1__": if __name__ == "__main1__":
# identify_text() identify_text()
# get_scr(_ocr_pos[0],_ocr_pos[1],_ocr_pos[2],_ocr_pos[3],f"test") get_scr(_ocr_pos[0],_ocr_pos[1],_ocr_pos[2],_ocr_pos[3],f"test")
# find_input_count() find_input_count()
s=ser() # s=ser()
s.open("com8") # s.open("com8")
s.avoid() # s.avoid()
while True: # while True:
try: # try:
s.password_test("1234567890") # s.password_test("1234567890")
except Exception as e: # except Exception as e:
myprint(e) # myprint(e)
break # break
except KeyboardInterrupt as k: # except KeyboardInterrupt as k:
myprint(k) # myprint(k)
break # break
s.reset() # s.reset()
s.close() # s.close()