Post by AnkuLua on Jan 11, 2016 9:01:11 GMT
You write the first script on your device. You are exciting that it works perfectly on your device.
You share the script with your friend. Hope to earn their admiration.
But...
Why does the script run slowly or even crashes on your friend's low-end phone? But it runs smoothly on your high-end phone.
The problem must be from your friend's phone.
Do your friend have to buy a new phone just because your script?
Of course not. Through scripts optimization, you can take back their admiration.
AnkuLua operation principle:
AnkuLua's operations could be divided into three stages:
The operations of image recognition could be divided into three steps.
The image resizing is one of the key factors for memory usage.
For example, your phone's width resolution is 2560, but friends' are 640.
And your script's CompareDimension is set to 2560. Then every screenshot will be resized to 2560 for image recognition even on 640 phones.
It will be a miracle that the script can run smoothly on your friend's phone.
Image recognition in step three takes most time.
But we can reduce it by doing something in steps one and two.
Optimizing image recognition:
Setting proper CompareDimension
The most straightforward way for script optimization is setting proper CompareDimension.
Suggest multiple of 320 or 640.
It's because that the width resolutions of most devices are multiple of 320 or 640.
Setting CompareDimension to these numbers can make the resized images still clear. It's good for the success of image recognition.
We normally set the value to 640 or 1280. 320 may be too small.
But...
Do we need a low-resolution phone or setting BS to low resolution for script development? It's hard to operate...
Of course not, we can use software to resize the images cropped from high-resolution devices.
For PC, we recommend conver from imagemagick .
We take out the required execution file and write a batch file. You can download resize.zip directly.
Please upzip the resize.zip to the folder with your scripts.
Then open a command prompt windows and execute resize.bat command,resize.bat takes three parameters
The first one is the resizing percentage.
The second one is the folder with original images.
The third one is the folder for destination images.
For example, the following command will halve (50%) all the images in folder image.2560 to folder image.1280.
We can also use following scripts to switch the resolutions and check if the result consistent.
Note: Only need to change CompareDimension. We don't need to change ScriptDimension.
Use region
If regions are not used, AnkuLua will take the whole screen image for recognition.
Therefore, smaller region takes less time for image recognition.
Note: Region value is according to ScriptDimension. In following example, region lowerRight is the lower right quarter of the screen.
With scripts optimization, your scripts will run smoothly even on low-end devices.
[Next]: To be continued...
[Previous]: Compile and Encrypt Scripts
[Home]: AnkuLua Introduction
You share the script with your friend. Hope to earn their admiration.
But...
Why does the script run slowly or even crashes on your friend's low-end phone? But it runs smoothly on your high-end phone.
The problem must be from your friend's phone.
Do your friend have to buy a new phone just because your script?
Of course not. Through scripts optimization, you can take back their admiration.
AnkuLua operation principle:
AnkuLua's operations could be divided into three stages:
- take the screenshot
- image recognition
- touch actions
The operations of image recognition could be divided into three steps.
- resize the captured image according to the value of Settings:setCompareDimension()
- Crop the image according to the region by setROI or region objects. Otherwise, the whole image is used.
- Do recognition on the image from step two.
The image resizing is one of the key factors for memory usage.
For example, your phone's width resolution is 2560, but friends' are 640.
And your script's CompareDimension is set to 2560. Then every screenshot will be resized to 2560 for image recognition even on 640 phones.
It will be a miracle that the script can run smoothly on your friend's phone.
Image recognition in step three takes most time.
But we can reduce it by doing something in steps one and two.
Optimizing image recognition:
Setting proper CompareDimension
The most straightforward way for script optimization is setting proper CompareDimension.
Suggest multiple of 320 or 640.
It's because that the width resolutions of most devices are multiple of 320 or 640.
Setting CompareDimension to these numbers can make the resized images still clear. It's good for the success of image recognition.
We normally set the value to 640 or 1280. 320 may be too small.
But...
Do we need a low-resolution phone or setting BS to low resolution for script development? It's hard to operate...
Of course not, we can use software to resize the images cropped from high-resolution devices.
For PC, we recommend conver from imagemagick .
We take out the required execution file and write a batch file. You can download resize.zip directly.
Please upzip the resize.zip to the folder with your scripts.
Then open a command prompt windows and execute resize.bat command,resize.bat takes three parameters
The first one is the resizing percentage.
The second one is the folder with original images.
The third one is the folder for destination images.
For example, the following command will halve (50%) all the images in folder image.2560 to folder image.1280.
resize.bat 50 image.2560 image.1280
We can also use following scripts to switch the resolutions and check if the result consistent.
resolution = 1280 -- Here is the only place to be changed
Settings:setCompareDimension(true, resolution)
localPath = scriptPath()
setImagePath(localPath.."image."..resolution.."/")
Note: Only need to change CompareDimension. We don't need to change ScriptDimension.
Use region
If regions are not used, AnkuLua will take the whole screen image for recognition.
Therefore, smaller region takes less time for image recognition.
Note: Region value is according to ScriptDimension. In following example, region lowerRight is the lower right quarter of the screen.
Settings:setCompareDimension(true, 1280)
Settings:setScriptDimension(true, 2560)
lowerRight = Region(1280, 800, 1280, 800) -- It's ok if (x+w) or (y+h) bigger than the screen resolution. AnkuLua always take the maximum values of the devices.
With scripts optimization, your scripts will run smoothly even on low-end devices.
[Next]: To be continued...
[Previous]: Compile and Encrypt Scripts
[Home]: AnkuLua Introduction