Next to the post , today we talk about how to implement automatic team brush path
Introduced:
Automatic team Brush Path process is the first click on the Brush Channel button, then click to the button, and then click the convenient team ...
These operations on the previous blog has told us how to do, using picpick measurement coordinates, and then using Autopy simulation mouse click
But how do you automatically create teams and match teammates after clicking on a quick team?
We're going to use word recognition here.
Have played asked all know, no teammates or the number of teammates to 4, the team will exist guardian, as follows
And the position of the guardian is fixed, the priority of the guardian is from left to right, for example, match to a teammate, the bucket Chang old will disappear (will not fight); Match a teammate, the skeleton elders will disappear (will not go to war)
My idea is that, after a period of time on the night God Simulator, and then to this text recognition, to determine whether "Dou Chang old" and "Bones elders" exist in the identified string. Of course, you can also judge whether the number of elders is equal to 2
Because played the turn system know, the team reached three people can start, do the task of the system will automatically match teammates, until the match is full until
Pre-Preparation: using PiL's Imagegrab
Installing PIL
Pip Install Pillow
(The pillow package contains the Pil,pil is now discontinued)
I'm here to install a dependency package directly with Pycharm
Copy code, run directly
#coding =utf-8import timeimport win32apiimport win32con from PIL import Imagegrab time.sleep (3= (3911561582853= Imagegrab.grab (bbox) # parameter save path to file Im.save ('as.png')
Run directly, you will find a as.png file in the current directory
Official document explanation of the Grab method
Here Bbox = (x1,y1,x2,y2), which means a section from screen coordinates (X1,Y1) to (X2,y2)
inch 1.1. 3 return an "RGB" image. The bounding box argument can is used to copy only a part of the screen.
Using BAIDU-AIP for word recognition
I have tried pytesseract and pytesser word recognition, often appear to recognize the failure of Chinese support is not friendly
So I'm using BAIDU-AIP for word recognition here.
Pycharm Open file->settings-> Plus
Search for BAIDU-AIP, then click on the lower left corner of the install package
We need appp_id, Api_key, Secret_key, we go to Baidu Cloud application
Login Baidu Cloud , Baidu Cloud disk and Baidu Stick account can be used directly, do not apply for a Baidu account
Find word recognition
Click Create App
Complete creation, the individual user can identify 600 times a day for free
Images that require text recognition
Copy code, run
#coding =utf-8 fromAIP Import Aipocrimport re# Baidu character recognition appp_id='app_id'Api_key='App_key'Secret_key='Secret_key'Client=AIPOCR (appp_id,api_key,secret_key) I= Open (R'E:\python_project\test\imageIdentification\helpedName1.png','RB') img=i.read () message=client.basicgeneral (IMG); forIinchMessage.Get('Words_result'): Print (I.Get('words'))
can see the results
Start making plug-ins:
As in the previous blog, the first measurement of coordinates, coordinates according to different resolutions, I here is 1920*1080
The coordinates of the Brush path button are (809,222)
The coordinates of the Go button are (1101,646)
Convenient team coordinates are (1449,730)
Create a Team button (998,799)
Start Matching (1232,794)
After measuring coordinates, call word recognition to determine whether "Dou Chang old" and "skeleton elders" exist in the identified string.
If two elders do not exist, there are already three people in the team. At this point, close the Brush Path window, click on the land pressure real, dialogue, start the Brush road
Set the 10-wheel brush path time, and start a new round of brush paths after the 10-wheel brush-run task ends
The detailed code is as follows:
imagegrabutil.py (tool)
#coding =utf-8 from PIL import imagegrab# parameter Description # The x-coordinate at the start of the first argument # the y-coordinate at the start of the second argument # The x-coordinate at the end of the third argument # the y-coordinate of the end of the fourth argument Def screenshot (x1,y1,x2,y2,filename): = (x1, y1, x2, y2) = imagegrab.grab (bbox) # parameters Save file path im.save ('e:\\python_project\\asktao_automation\\resource\\'+ filename+'. png')
baiduaiputil.py (Word recognition tool)
I here Baidu Cloud appp_id, Api_key, Secret_key saved in Config.ini
#coding =utf-8 fromAIP Import Aipocrimport re# Baidu word recognition #!/usr/bin/Env python#-*-coding:utf-8-*-Import Configparserimport Osos.chdir ("E:\python_project\Asktao_Automation\util") CF=Configparser.configparser ()Cf.read ("Config.ini")secs=cf.sections () appp_id= cf.Get("Baiduaip","appp_id") Api_key= cf.Get("Baiduaip","Api_key") Secret_key= cf.Get("Baiduaip","Secret_key")Client=AIPOCR (Appp_id,api_key,secret_key) def characterrecognition (FilePath): I= Open (FilePath,'RB') img=i.read () message=client.basicgeneral (IMG); #print (message.Get('Words_result')) string=''; forIinchMessage.Get('Words_result'): Print (I.Get('words')) string+ = i.Get('words') return string
Config.ini
=
shuadao.py
#coding =utf-8import autopyimport timeimport win32apiimport Win32con fromImagegrabutil Import screenshot frombaiduaiputil Import Characterrecognitionimport sysdefaultencoding='Utf-8'ifSys.getdefaultencoding ()! =defaultencoding:reload (SYS) sys.setdefaultencoding (defaultencoding) #刷道 (Captain Mode) #time. Sleep (5) win32api.keybd_event ( -,0,0,0) #alt键位码是18win32api. keybd_event (9,0,0,0) #tab键位码是9time. Sleep (0.5) win32api.keybd_event ( -,0,0,0) #enter键位码是13win32api. keybd_event ( -,0, Win32con. Keyeventf_keyup,0) #释放按键win32api. keybd_event (9,0, Win32con. Keyeventf_keyup,0) win32api.keybd_event ( -,0, Win32con. Keyeventf_keyup,0) Time.sleep (2) def mousemove_click (x, y): Autopy.mouse.smooth_move (Autopy.mouse.click) Mousemove_click (809,222) #移动到刷道按钮mousemove_click (1101,646) #点击前往time. Sleep (Ten) #从其他地图走到轩辕庙陆压真人处花费10smousemove_click (1449,730) #点击便捷组队mousemove_click (998,799) #点击创建队伍mousemove_click (1121,781) #点击开始匹配 forIinchRange1,Ten,1): Teamfilename='Judgeteamcount'Time.sleep (3) screenshot (391,156,1582,853, Teamfilename) # Judgeteamstr= Characterrecognition ('e:\\python_project\\asktao_automation\\resource\\'+teamfilename+'. PNG') #文字识别 #每个人守护顺序不一样, modify as neededif 'Dou Chang Old'NotinchJudgeteamstr and'Skeleton Elders'Notinchjudgeteamstr: #这两个守护不在, indicating that the team has three people, began to brush the road Mousemove_click (1524,234) #点击关闭按钮 Mousemove_click (809,222) # move to the Brush Channel button Mousemove_click (1101,646) # Click to go to Mousemove_click (1446,661#点击 "Voldemort" I'm on my way. BreakTime.sleep ( -) #休息十分钟后再次查看是否组到人 # operation after 10 rounds of brush path forJinchRange1,Ten,1): Time.sleep (780#平民伏魔一般780s之内, local tyrants has 300s, modify taskfilename as needed='Judgetaskaccomplish'Time.sleep (3) screenshot ( -,164,1701,866, Taskfilename) judgetaskstr= Characterrecognition ('e:\\python_project\\asktao_automation\\resource\\'+taskfilename+'. PNG') if '"Lord Voldemort," I'm going.' inchJudgetaskstr:mousemove_click (1446,661) # Click on "Voldemort" I'm on it.Else: Time.sleep ( -#防止780s内还没有完成伏魔操作, wait 60s, just in case Mousemove_click (1446,661) # Click on "Voldemort" I'm on it.
The effect is as follows:
Since the blog park can only upload 10MB gif below, so I did not upload the full
Pro-Test available, about 10 minutes or so can be matched to three people, began to brush the road
10 Wheel Brush path for a group, the number of groups can be set to a larger number of cycles, I set the 10
Sometimes the match is not people, such as the day is more difficult to match to people. Can judge whether the elders exist in that part, multiple loops several times
Again, my Code may not be able to run on your computer, my computer resolution is 1920*1080, the location of the simulator is the default in the center, the simulator to move the measurement of the coordinates are not the same
The most important thing in making a plug-in is thinking