优化操作逻辑
This commit is contained in:
@@ -25,7 +25,7 @@ def ShapeDetection(img:cv2.typing.MatLike):
|
||||
percentage=nonzero_num/img_obj.size
|
||||
# print(f"nonzero_num:{nonzero_num},size={img_obj.size}, pos:{percentage}")
|
||||
# 通过计算图像白值的比例来判断实心还是空心
|
||||
if(percentage>0.55):
|
||||
if(percentage>0.63):
|
||||
boll_count+=1
|
||||
return (all_cont,boll_count)
|
||||
|
||||
|
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"index": 3185
|
||||
"index": 8538
|
||||
}
|
73
touch2.py
73
touch2.py
@@ -29,9 +29,11 @@ def flush_wind_pos():
|
||||
not_find=True
|
||||
time.sleep(1)
|
||||
continue
|
||||
_ocr_pos=[pos[0]+0,pos[1]+180,375,296]
|
||||
_ocr_boll=[pos[0]+99,pos[1]+440,172,27]
|
||||
_mouse_touch=[pos[0]+0,pos[1]+603,145,70]
|
||||
w=pos[2]-pos[0]
|
||||
h=pos[3]-pos[1]
|
||||
_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
|
||||
|
||||
# 识别屏幕文字
|
||||
@@ -110,7 +112,7 @@ class ser(object):
|
||||
self.x=x
|
||||
self.y=y
|
||||
def touch(self):
|
||||
self.write(f"Z4\r")
|
||||
self.write(f"Z6\r")
|
||||
time.sleep(0.1)
|
||||
self.write(f"Z0\r")
|
||||
time.sleep(0.05)
|
||||
@@ -137,26 +139,38 @@ class ser(object):
|
||||
def password(self,p:str):
|
||||
index=0
|
||||
p_len=len(p)
|
||||
try_times=0
|
||||
while index<p_len:
|
||||
pos=self.touch_table[p[index]]
|
||||
myprint(f"点击 index={index},{p[index]}")
|
||||
self.togo(pos[0],pos[1])
|
||||
self.touch()
|
||||
self.avoid()
|
||||
if(find_text(identify_text(),"手机已锁定")):
|
||||
if(index==5):
|
||||
myprint(f"手机锁定中,已全部输入")
|
||||
return True
|
||||
myprint(f"密码输入状态异常 index={index},password={p}")
|
||||
return False
|
||||
time.sleep(0.1) # 这里延时防止界面更新延迟导致的识别异常
|
||||
# if(find_text(identify_text(),"手机已锁定")):
|
||||
# if(index==5):
|
||||
# myprint(f"手机锁定中,已全部输入")
|
||||
# return True
|
||||
# myprint(f"密码输入状态异常 index={index},password={p}")
|
||||
# return False
|
||||
num=find_input_count()
|
||||
myprint(f"已输入个数为 {num}")
|
||||
if(num==index+1):
|
||||
try_times=0
|
||||
index+=1
|
||||
elif(num==0 and index==5):
|
||||
return True
|
||||
else:
|
||||
elif(num==index):
|
||||
try_times+=1
|
||||
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):
|
||||
try:
|
||||
text=identify_text()
|
||||
if(find_text(text,"安装系统软件")):
|
||||
if(find_text(text,"安装系统")):
|
||||
unknown_scr=False
|
||||
myprint("进入密码界面")
|
||||
s.enter()
|
||||
time.sleep(0.2)
|
||||
# s.avoid()
|
||||
elif(find_text(text,"请输入解锁密码")):
|
||||
unknown_scr=False
|
||||
@@ -218,20 +233,20 @@ if __name__ == "__main__":
|
||||
|
||||
|
||||
if __name__ == "__main1__":
|
||||
# identify_text()
|
||||
# get_scr(_ocr_pos[0],_ocr_pos[1],_ocr_pos[2],_ocr_pos[3],f"test")
|
||||
# find_input_count()
|
||||
s=ser()
|
||||
s.open("com8")
|
||||
s.avoid()
|
||||
while True:
|
||||
try:
|
||||
s.password_test("1234567890")
|
||||
except Exception as e:
|
||||
myprint(e)
|
||||
break
|
||||
except KeyboardInterrupt as k:
|
||||
myprint(k)
|
||||
break
|
||||
s.reset()
|
||||
s.close()
|
||||
identify_text()
|
||||
get_scr(_ocr_pos[0],_ocr_pos[1],_ocr_pos[2],_ocr_pos[3],f"test")
|
||||
find_input_count()
|
||||
# s=ser()
|
||||
# s.open("com8")
|
||||
# s.avoid()
|
||||
# while True:
|
||||
# try:
|
||||
# s.password_test("1234567890")
|
||||
# except Exception as e:
|
||||
# myprint(e)
|
||||
# break
|
||||
# except KeyboardInterrupt as k:
|
||||
# myprint(k)
|
||||
# break
|
||||
# s.reset()
|
||||
# s.close()
|
||||
|
Reference in New Issue
Block a user