Sign in to follow this  
Followers 0
DNnlee

Need help shrinking my script

8 posts in this topic

#1 ·  Posted (edited)

I have a large amount of BMP images, and i use the "IMAGESEARCH" library recommended to me the other day.

i want to scan an area for the image i want, and there are multiple image that i want, but they appear one at a time.

if image is found, i want to assign a value to $VALUE, and i have to assign 9 different values to about 120 images.

below is an example of what i want to do, any recommendation on how to "shrink" or compact the script so it's not so long and more efficient.

$result = _ImageSearch("ONE.bmp",1,$x1,$y1,0)
if $result=1 Then
    $Value = 10
EndIf

$result = _ImageSearch("Two.bmp",1,$x1,$y1,0)
if $result=1 Then
    $Value = 20
EndIf

$result = _ImageSearch("THREE.bmp",1,$x1,$y1,0)
if $result=1 Then
    $Value = 30
EndIf

$result = _ImageSearch("FOUR.bmp",1,$x1,$y1,0)
if $result=1 Then
    $Value = 40
EndIf

something like scanning the area for all of the images at once instead of doing it 120 times would be helpful too, only one desired image would appear at a time.

Edited by DNnlee

Share this post


Link to post
Share on other sites



Subscripted variables (indexes) that reference tables (arrays) is what you're after!

Load the array from a file, or hard-code it in your script.

Then process the whole mess with a simple loop and a couple lines of code.

What determines the value assigned to the image?

Do you have a fixed number of images, or is the quantity variable (unknown)?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Subscripted variables (indexes) that reference tables (arrays) is what you're after!

Load the array from a file, or hard-code it in your script.

Then process the whole mess with a simple loop and a couple lines of code.

What determines the value assigned to the image?

Do you have a fixed number of images, or is the quantity variable (unknown)?

i have only 9 values , and i have a set amount of possible images, and i have screenshoted all 120+ of them... lol

i've just thought of this, wondering if it'll work

dim $imagelocation[200][2]
$ImageLocation[0][0] = "One.bmp"
$ImageLocation[0][1] = 10
$ImageLocation[1][0] = "Two.bmp"
$ImageLocation[1][1] = 10
$ImageLocation[2][0] = "Three.bmp"
$ImageLocation[2][1] = 10
$ImageLocation[3][0] = "Four.bmp"
$ImageLocation[4][1] = 10
for $s = 0 to 200   
    $result = _ImageSearch($ImageLocation[$s][0],1,$x1,$y1,101) 
    if $result = 1 Then
        $value = $ImageLocation[$s][1]
        ExitLoop
    EndIf
    
Next
Edited by DNnlee

Share this post


Link to post
Share on other sites

Exactly the idea.

Were you to be changing, or adding to, your list often you might just make a text file looking something like:

10ONE.BMP

20TWO.BMP

Then a simple loop could read each line of the file, split it, and load your array.

Or, your example is fine, or, to save some space you could go this route and put maybe 10 "pairs" on each line:

dim $imagelocation[200][2] = [ _
    [10, "ONE.BMP"], [20, "TWO.BMP],...   ...[50, "TEN.BMP], _
    [60, "11.BMP"],  [90, "12.BMP],...  ...[40, "20.BMP], _
    ...
    ...
    [70, "111.BMP"], [30, "112.BMP],...   ...[80, "120.BMP]]

Share this post


Link to post
Share on other sites

You can also use an Ini file to store your images information. This way if you add or remove an image you don't have to recompile your script.

$ImageLocation = IniReadSection(@ScriptDir & '\Image.ini', 'Images')

For $s = 1 to $ImageLocation[0][0]    
    $result = _ImageSearch($ImageLocation[$s][0],1,$x1,$y1,101)
    if $result = 1 Then
        $value = $ImageLocation[$s][1]
        ExitLoop
    EndIf  
Next

Ini file called Image.ini

[Images]
One.bmp = 10
Two.bmp = 10
Three.bmp = 10
Four.bmp = 10

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

ahh nevermind, it's a small trivial thing to not be able to comment on the ini file, i'll live iwth it

thank you all for all the help ! XD

Edited by DNnlee

Share this post


Link to post
Share on other sites

ahh nevermind, it's a small trivial thing to not be able to comment on the ini file, i'll live iwth it

thank you all for all the help ! XD

it works very nicely now, but then when i look at the CPU usage, it pops up to 90+% when it does the ImageSearch function,

i was scared it'll damage the CPU so i added a Sleep(30) and now it takes about 15+ seconds for the script to go through all 100 images and find a match.

anyone know if 90+ cpu usage is normal when it does imagesearch? and any way to make it search any faster without hurting the CPU

i'm using T9300 @ 2.5 ghz, loading this script on a VMware.

tyvm

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

CPU's are made to be maxed. Nothing wrong with running at 100% assuming your fan is running properly, you have an adequate heatsink, thermal grease (heatsink compound), your case is ventilated, etc. My home CPU (Athlon 64 3000/939) is overclocked from 10*200 to 10*270 with a stock heatsink and the DDR400 memory is running at 448Mhz @ CL2.5-3-2-5-1T. It's been that way for 2 years and I often run the thing for 10 hours straight at 100% CPU usage when decoding videos. I'm not sure I've every seen it go beyond about 52 celsius. Consider that I'm overclicking it, I'm running it at more like 135% for hours at a time. The CPUs are rated for temperatures far beyond what I'm seeing. Yes, the hotter you run it, the shorter it's lifespan may be. So, run it at full speed and you'll have to replace it in 10 years, or be easy on it and it'll last 12 years. The trouble is, any current chip will be considered a dinosaur long before it dies of old age. Just my 2 cents.

(EDIT: Was running better memory timings than I'd thought)

Edited by Spiff59

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0