|
Post by baduser on Apr 15, 2018 16:41:47 GMT
Hi, I have a problem with the speed of the script. The script takes too long to handle the condition. It is possible that it runs even faster?
This is the script:
-- ========== Settings ================ Settings:setCompareDimension(true, 1280) Settings:setScriptDimension(true, 1280) Settings:setScanInterval(0.001) nTime2= os.clock() ---Regions---- reg1 = Region(370,70,590,60) reg2 = Region(0, 610, 290,110) reg3 = Region(120,60,140,400) reg4 = Region(700,80,250,600) reg6 = Region(595,0,90,85) reg10 = Region(480,215,180,100)
--images image1=Pattern("image1.png"):similar(0.7) image2=Pattern("image2.png"):similar(0.6) image3=Pattern("image3.png"):similar(0.6) image4=Pattern("image4.png"):similar(0.7) image5=Pattern("image5.png"):similar(0.6) image6=Pattern("image6.png"):similar(0.6) image7=Pattern("image7.png"):similar(0.6) image8=Pattern("image8.png"):similar(0.7) image9=Pattern("image9.png"):similar(0.6) image10=Pattern("image10.png"):similar(0.7)
--Tabels Regionen={ [image1]=reg1, [image2]=reg1, [image3]=reg1, [image4]=reg1, [image5]=reg6, [image6]=reg10, [image7]=reg10, [image8]=reg10, [image9]=reg1, [image10]=reg12 }
for ImageX,regX in pairs(Regionen) do if regX:exists(ImageX,0.01) then print("do function") end
end
nTime2=os.clock()-nTime2 print( nTime2,"sec") --how long the script work
The images are grey.
|
|
|
Post by Acera Dryd on Apr 15, 2018 17:40:42 GMT
Your script would be faster if you use the function usePreviousSnap(true) and every time you ne a screen refresh you have to call snapshot().
Furthermore you have to replace
...:exists(..., 0.01) with
...:exists(...) Caution: If you need to wait for a pattern, you have to change your code to something like this:
usePreviousSnap(false) ...:exists(..., 2) usePreviousSnap(true)
|
|
|
Post by baduser on Apr 15, 2018 18:09:20 GMT
Your script would be faster if you use the function usePreviousSnap(true) and every time you ne a screen refresh you have to call snapshot(). Furthermore you have to replace ...:exists(..., 0.01) with ...:exists(...) Caution: If you need to wait for a pattern, you have to change your code to something like this: usePreviousSnap(false) ...:exists(..., 2) usePreviousSnap(true)
Thx ,my first test is work now faster, but the hit rate will be worse. But that way work better. I will do some more test with diffrent option.
|
|
|
Post by baduser on Apr 25, 2018 11:25:28 GMT
Hi again:) my tests with usePreviousSnap(), some images could be found. The other images that have not been found, no matter with which setting if I have given the script more time to find or more runs per Interval(ScanInterval), it will not be found. If I set the similar low or too low, it gets a match although the image is not there. (im not sure, maybe i do something wrong) ahhh, I am desperate^^ another idea that comes to my mind if something like that would be possible: is there a way to check pictures in the background? like parallel to the script or like multitasking? or have anyone another any ideas?
|
|
|
Post by Acera Dryd on Apr 25, 2018 22:07:10 GMT
Could you provide the concerning code, where the image won't be found?
Ankulua and Lua provide no functions for Multithreading except coroutines, but this won't help your problem.
|
|
|
Post by baduser on Apr 26, 2018 21:07:51 GMT
Could you provide the concerning code, where the image won't be found? ? it is in the first thread, just now with usePreviousSnap(): . . . usePreviousSnap(true) for ImageX,regX in pairs(Regionen) do if regX:exists(ImageX,0.01) then print("do function") end
end usePreviousSnap(false)
its maybe the image to small? 24x25 Pixel
|
|
|
Post by Acera Dryd on Apr 27, 2018 6:43:33 GMT
First you have to replace
if regX:exists(ImageX,0.01) then with
if regX:exists(ImageX) then It make no sense, if you search a pattern on a cached snapshot for seconds. The code number 1 will provide the same result as the code number 2.
1: regX:exists(ImageX) 2: regX:exists(ImageX, 407983259)
This happens because code number 2 looks the whole time at the cached snapshot. If you want to wait for a pattern, then you have to disable "usePreviousSnap" temporally. For example:
usePreviosSnap(false) local match = regX:exists(ImageX, 407983259) usePreviosSnap(false)
Second: It would be a good idea if you call the method "snapshot" after the first call of "usePreviosSnap". This prevent, that Ankulua use a non cached picture.
Third: You should call "snapshot" every time you want, that Ankulua refresh his cached snap. If the Pattern appears after your last "snapshot", Ankulua wont find it.
|
|
|
Post by Mercobots on Apr 27, 2018 14:03:25 GMT
hi there also try this ankulua lib ankulua.boards.net/thread/169/common-library-autoresize regionWaitMulti(target, seconds, debug, skipLocation)
local reg1 = Region(370, 70, 590, 60) local reg2 = Region(0, 610, 290, 110) local reg3 = Region(120, 60, 140, 400) local reg4 = Region(700, 80, 250, 600) local reg6 = Region(595, 0, 90, 85) local reg10 = Region(480, 215, 180, 100)
local targets = { { id = 'img1', region = reg1, target = Pattern("image1.png"):similar(0.7), }, { id = 'img2', region = reg1, target = Pattern("image2.png"):similar(0.6), }, { id = 'img3', region = reg1, target = Pattern("image3.png"):similar(0.6), }, { id = 'img4', region = reg1, target = Pattern("image4.png"):similar(0.7), }, { id = 'img5', region = reg6, target = Pattern("image5.png"):similar(0.6), }, { id = 'img6', region = reg10, target = Pattern("image6.png"):similar(0.6), }, { id = 'img7', region = reg10, target = Pattern("image7.png"):similar(0.6), }, { id = 'img8', region = reg10, target = Pattern("image8.png"):similar(0.7), }, { id = 'img9', region = reg1, target = Pattern("image9.png"):similar(0.6), }, { id = 'img10', region = reg12, target = Pattern("image10.png"):similar(0.7), }, }
--regionWaitMulti(target, seconds, debug, skipLocation) regionWaitMulti(targets, 20)
if is not what you are looking for you can use it as before local timer_script = Timer() local timer = Timer()
for i, v in ipairs(targets) do if v.region:exists(v.target) then print('img found - ' .. timer:check()) end timer:set() end
print('script time - ' .. timer_script:check())
|
|
|
Post by baduser on Apr 27, 2018 21:03:23 GMT
if is not what you are looking for you can use it as before local timer_script = Timer() local timer = Timer()
for i, v in ipairs(targets) do if v.region:exists(v.target) then print('img found - ' .. timer:check()) end timer:set() end
print('script time - ' .. timer_script:check())
Nope, im sure that its not what i search;) but thx regionWaitMulti(target, seconds, debug, skipLocation) Thats look intresting:) Second: It would be a good idea if you call the method "snapshot" after the first call of "usePreviosSnap". This prevent, that Ankulua use a non cached picture. I think that's the solution. Thx guys, I'll test it for the days and then give feedback:)
|
|
|
Post by baduser on May 8, 2018 20:45:33 GMT
Hey guys, my current solution is: only to set "snapshot()" before to start to search the imgae in the table. "usePreviosSnap" this make really faster but have no impact of the time with "snapshot()". Only "usePreviosSnap" is fasterst but the image hitrate is bad.
Thx guys:)
|
|