Jump to content

Shade Variations in Pixel Search


Recommended Posts

Greetings,

First I will make the disclaimer for those who do not like to assist in these matters, yes my script is used for

a game. The script is a combination of learn by example, help from the forums and my own trial and error.

However I have some questions, primarily about pixel search. I have an exsisting script, that works but it does

not always function as well as I would like it to.

I use pixel search to determine a color change in a certain area to trigger an event, or skip a whole bunch of

steps really. The colors are not solid they are mildly transparent or layered and change ever so slightly over time.

so I cannot use checksum.

Pixel search works but not 100% of the time due to variations in the shade, it basicly looks for the presence of

text that when present is greyish white and when not is a dim black. However the color changes ever so slightly

so it cannot rely on one hex color code, meaning I must use shade variation. I have been toying with the shade

variation settings to try and increase the accuracy while minimising false positives.

1) So getting on with my question, I would like some assitance in better understanding how the shade variation

of pixel search works. To improve accuracy

2) My next second question, has to do with reducing false positives, instead of something like this:

=======

;This pixel search looks for the presence of the greyish white pixel, if it is found it skips a bunch of code, if it

is not found it continues.

PixelSearch(1392, 213, 1392, 213, 0XCFCFCF, 150)

If @error Then

(bunch of code)

EndIf

========

3) Is it possible to set it up to check two different locations for example 1392, 213 and 1392, 215 and if @error on one or both

then continue with the bunch of code that follows, or if positive or not @error on both points then it would skip the

code and go down to the line containing end if. (Did this question make sense?)

I appreciate any help you are willing to provide.

Thank you

Link to comment
Share on other sites

On the "Variation" of color, it depends on the actual changes, maybe you could use two different pixel searches at the same location with the two (three, etc) different known colors.

this is the test you want

$Pixel1 = PixelSearch(1392, 213, 1392, 213, 0XCFCFCF, 150)
$Pixel2 = PixelSearch(1392, 213, 1392, 215, 0XCFCFCF, 150)

; error checking
If Not IsArray($Pixel1) Or Not IsArray($Pixel2) Then ; Or is either one at error

    ; (bunch of code)

Else
    ; Both of them are NOT an Error
    ; (bunch of code)
EndIf

8)

NEWHeader1.png

Link to comment
Share on other sites

while; 1

(preceding code)

$Pixel1 = PixelSearch(1392, 213, 1392, 213, 0XCFCFCF, 150)
$Pixel2 = PixelSearch(1392, 213, 1392, 215, 0XCFCFCF, 150)

; error checking
If Not IsArray($Pixel1) Or Not IsArray($Pixel2) Then ; If either one is at error white text was not present.

(bunch of code)

Else ; Code was skipped because both Pixel 1 and 2 are NOT an Error white text was present."
EndIf

wend

Is this correct?

If so I can try that.

Thanks

Edited by nyxx24
Link to comment
Share on other sites

So like this then?

while; 1

(preceding code)

$Pixel1 = PixelSearch(1392, 213, 1392, 213, 0XCFCFCF, 150)
$Pixel2 = PixelSearch(1392, 213, 1392, 215, 0XCFCFCF, 150)

; error checking
If Not IsArray($Pixel1) Or Not IsArray($Pixel2) Then ; If either one is at error white text was not present continue

(bunch of code)

EndIf  ; Code was skipped because both Pixel 1 and 2 are NOT an Error white text was present."
wend

Thanks

Link to comment
Share on other sites

On the "Variation" of color, it depends on the actual changes, maybe you could use two different pixel searches

at the same location with the two (three, etc) different known colors.

I was just re-reading this because I was about to ask how I would expand this for three colors, but to rewind a bit,

you said it could search the same location for two or three known colors..

So in short if I replace this:

PixelSearch(1392, 213, 1392, 213, 0XCFCFCF, 150)
If @error Then

(code)

EndifoÝ÷ Ùµ¢¶aÏÛjëh×6$Pixel1 = PixelSearch(1392, 213, 1392, 213, 0XCFCFCF, 150)
$Pixel2 = PixelSearch(1392, 213, 1392, 213, 0XDEDEDE, 150)
If Not IsArray($Pixel1) Or Not IsArray($Pixel2) Then

(code)

Endif

I am confused, when you have 2 variables wouldn't you have 4 possible outcomes

y/y n/n y/n n/y so to be sure I understand:

If either check fails then it continues

If either check succeeds it continues

If both checks fail it continues

If both checks succeed it skips

Or am I looking at this wrong and confusing myself worse?

Link to comment
Share on other sites

I do understand you... But lets start with this

PixelSearch is looking inside a "boxed" area defined by your x and y locations

when you use like this PixelSearch(1392, 213, 1392, 213,... It is only looking at one little dot (pixel)

Is there any "white" in the area?

can you change it to search a larger "block" ?

-----------------------------------------------------

y/y n/n y/n n/y so to be sure I understand: ... True

If either check fails then it continues ; it does the (code)

If either check succeeds it continues ; this is saying the same as above.. it does the (code)

If both checks fail it continues ; it does the (code)

If both checks succeed it skips ; yes, it skips the (code)

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

Yes, I could do a larger area.

The area will either be an empty somewhat black shade area or it will have two words of white text in it. But they are not

very large white letters, surrounded by antialiasing. With a transparent layer that changes hue\shade sort of speak based

on the background hense the hue\shade issue.

The best I could do is the legs of three letters that would be at most 2 pixels wide and 5 pixels high

Without the actual images in front of me, lets say as an example:

Upper left 1392, 210 Lower Right 1394, 215

Upper left 1492, 210 Lower Right 1494, 215

Upper left 1592, 210 Lower Right 1594, 215

So I could check all 3 areas for the color white 0xFFFFFF which could also be a bit gray 0XCFCFCF or 0XDEDEDE for example.

But instead I choose to look for one single pixel centered in a larger 3x3 area of the letters because the text I am looking

for also floats/moves/shifts 1 pixel in either direction, so if my pixel area is to large then it increases the failure rate. The

one pixel centered in the larger area has a greater chance of always having the white/gray pixel there when the text is

there.

Yes primarily white text in a black box that moves, and changes hue/shade based on the scenerey behind it.. probably not

impossible, but definetly a challenge.

The point is if the text is not present then there is something there to do, if the text is present there is not anything there to

do and performing the actions that follow is a waste of time.

I apologise if I am making something complicated out of what seemed a simple question, but I do appreciate your help and

patience very much.

Thanks

Nyxx

Link to comment
Share on other sites

I have a similar but more complex problem so i cast here my idea as i'm not able to realize it because i don't how how the hex value changes compared to the color search.

As the OP i have this problem, two layers, the background one wich can virtually be ANY color and the foreground layer wich is fixed but semi transparent(i'd say 90% opacity).

Considering the opacity is very high the background color, whatever that might be at any given time, will blend just slightly with the foreground color potentially creating a final color always a little off from the original one i got as a checksum.

Now how to accomplish a succesfull pixelcheck with virtually 0% false positives?

I tought this, let's say the foreground color is white and we know it has a color "distance" equal to 0.

Now the background color changes periodically and randomly BUT due to the fact the opacity of the foreground color is 90% whatever the background color is, it will only blend that much with the foreground creating small variations.

If we were to introduce a "tollerance threshold" we could eliminate that small color variation letting us really understand when that pixel really changes color(drastically, wich is what we all want).

To introduce the tollerance we need to calculate the "distance" of the blended color, let's say the background is black and blending with the foreground white creates a small shade of gray(wich is suposedly the maximum variation possible) and the distance would be say 10.

At this point we know what the treshold is and we can effectively detect drastic changes in the pixel without false positives.

The problem is that i have no clue how hex color value change and thus can't even begin to calculate this "distance".

I hope i've been of insight to someone more skilled than me who can help us solve this problem.

Cheers.

Link to comment
Share on other sites

It was way easier than i tought, actually PixelGetColor returns a value wich can be used to the purpose.

I added a simple variation of 10%, the code is pretty basic, hope it helps.

#include <Misc.au3>
Sleep(3000)
While 1 
    ToolTip("Waiting for click...")
    If _IsPressed("01") Then        
        $MousePos = MouseGetPos()
        ToolTip("")
        ExitLoop
    EndIf
WEnd
Sleep(3000)
$PixelColor = PixelGetColor($MousePos[0],$MousePos[1])

while 1 
    $ComparisonColor = PixelGetColor($MousePos[0],$MousePos[1])
    If $ComparisonColor > $PixelColor+($PixelColor*0.1) Or $ComparisonColor < $PixelColor-($PixelColor*0.1) Then
        ToolTip("Pixel changed!")
    Else
        ToolTip($ComparisonColor)
    EndIf 
WEnd
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...