Yesterday do not have to work overtime, idle to have nothing to do, played a few people to pick fault. Unfortunately eyesight is not enough, always can't find out, thought can write a plug-in, help find out where.
Search on the internet, and generally some use Python, computing to find fault with the plug-in.
I am weak python base, especially the image on the one hand, can call a few APIs is good.
First of all, actually finding fault is the core using Python to compare two different pictures. Online a big God using OpenCV to make a plug-in, seemingly very good, but still above a sentence, for me to learn slag, will invoke API is good. OpenCV so difficult things, it is not I can deal with.
The first step, must be to find the handle of the window of the fault.
Here, the relevant introduction of the Internet or more, mainly used to FindWindow to find the handle.
Import Win32gui
Import Win32con
GAME_HWD = 0
While GAME_HWD = 0:
GAME_HWD = Win32gui. FindWindow ("#32770", "everyone to pick fault")
If GAME_HWD:
Break
Time.sleep (2)
This will ensure that the handle to the fault window is obtained.
The second step is to dig up the picture.
Here you can grab pictures on the screen using the Imagegrab. We can search the specific use.
The key here is that two pictures are not easy to locate. No way, with the most frustrated method, first of all the form to the grab down, and then separated along the middle, that is, divided into the left and right two parts, respectively, the IMA and IMB. Ima and IMB are not yet directly comparable. Also must be the edge to remove, how to remove it, I use the most frustrated method, is to use the QQ screenshot, and then roughly look at the edge of the image how many pixels, and then remove the edge.
The image below is two pictures in the game.
The following is the actual run time, the results obtained.
Still need to manually in the original picture on the control, more trouble.
Here is the complete program
#coding =GBK
Import Win32gui
Import time
Import Image
Import imagechops
Import Win32con
from PIL import imagegrab
#s =u "´ó¼òà´õò²ç"
game_hwd = 0
While game_hwd = 0:
G AME_HWD = Win32gui. FindWindow ("#32770", "´")
If game_hwd:
Break
Time.sleep (2)
Win32gui. ShowWindow (Game_hwd,win32con.sw_restore)
Win32gui. SetForegroundWindow (GAME_HWD) #强制将窗口放置最前面
Game_rect = Win32gui. GetWindowRect (GAME_HWD) #获取窗体的矩形坐标
#print game_rect
width = game_rect[2]-game_rect[0]
height = GAME_RECT[3]-game_rect[1]
Rect1 = (game_rect[0]+55,game_rect[1],game_rect[0]+width/2,game_rect[3]-100) # Split along the centerline, +55 because the left edge of the image is removed along the
Rect2 = (game_rect[0]+width/2,game_rect[1],game_rect[2]-55,game_rect[3]-100) #沿中线分开 ,-55 is because the right edge of the image is removed
#具体的这个55, completely according to the actual situation of their own machines, in fact, is the resolution, I was through the QQ screenshot, and then count out this value
Ima = Imagegrab.grab (RECT1)
IMB = Imagegrab.grab (rect2)
#ima. Show ()
#imb. Show ()
#out. Show ()
out = Imagechops.difference (IMA, IMB) #比较两幅图
Out.show ()
You can follow up the difference of this graph, a series of conversion, and then add to the original picture, just to the difference can be obvious in the artwork can be. The
does not update a graph now, you will have to run the script again, and then improve it later.