RichardAR Posted August 13, 2009 Posted August 13, 2009 Hello. I am working on a script that constantly needs to check pixel color within a tolerance. This is because the program I am scripting for has text and other window elements that constantly change within a tolerance depending on the view of the camera in the 3d environment, or if the background is dark or bright. I haven't figured out what the tolerance range is, however I have wrote this function to do a color comparison and I need advice on how to do it properly. Func IsColorMatch($color1, $color2, $threshMax, $threshMin = 0) $r1 = _ColorGetRed($color1) $g1 = _ColorGetGreen($color1) $b1 = _ColorGetBlue($color1) $r2 = _ColorGetRed($color2) $g2 = _ColorGetGreen($color2) $b2 = _ColorGetBlue($color2) $dr = Abs($r1 - $r2) $dg = Abs($g1 - $g2) $db = Abs($b1 - $b2) $tr = (($dr >= $threshMin) And ($dr <= $threshMax)) $tg = (($dg >= $threshMin) And ($dg <= $threshMax)) $tb = (($db >= $threshMin) And ($db <= $threshMax)) Return $tr And $tg And $tb EndFunc
jvanegmond Posted August 13, 2009 Posted August 13, 2009 Snippet from my code library: Func _ColorInBounds($pMColor, $pTColor, $pVariation) $lMCBlue = _ColorGetBlue($pMColor) $lMCGreen = _ColorGetGreen($pMColor) $lMCRed = _ColorGetRed($pMColor) $lTCBlue = _ColorGetBlue($pTColor) $lTCGreen = _ColorGetGreen($pTColor) $lTCRed = _ColorGetRed($pTColor) $a = Abs($lMCBlue - $lTCBlue) $b = Abs($lMCGreen - $lTCGreen) $c = Abs($lMCRed - $lTCRed) If ( ( $a < $pVariation ) AND ( $b < $pVariation ) AND ( $c < $pVariation ) ) Then Return 1 Else Return 0 EndIf EndFunc github.com/jvanegmond
martin Posted August 13, 2009 Posted August 13, 2009 Hello. I am working on a script that constantly needs to check pixel color within a tolerance. This is because the program I am scripting for has text and other window elements that constantly change within a tolerance depending on the view of the camera in the 3d environment, or if the background is dark or bright. I haven't figured out what the tolerance range is, however I have wrote this function to do a color comparison and I need advice on how to do it properly. Func IsColorMatch($color1, $color2, $threshMax, $threshMin = 0) $r1 = _ColorGetRed($color1) $g1 = _ColorGetGreen($color1) $b1 = _ColorGetBlue($color1) $r2 = _ColorGetRed($color2) $g2 = _ColorGetGreen($color2) $b2 = _ColorGetBlue($color2) $dr = Abs($r1 - $r2) $dg = Abs($g1 - $g2) $db = Abs($b1 - $b2) $tr = (($dr >= $threshMin) And ($dr <= $threshMax)) $tg = (($dg >= $threshMin) And ($dg <= $threshMax)) $tb = (($db >= $threshMin) And ($db <= $threshMax)) Return $tr And $tg And $tb EndFunc It doesn't look quite right to me. For example $tr = (($dr >= $threshMin) And ($dr <= $threshMax)) is to decide if the red component is out of tolerance, but it will only be true if both conditions are met which is when the difference is exactly equal to the allowed tolerance. I think it should be $tr = $dr > $threshMin Then the return should not be the Anded result but the Ored result Return $tr Or $tb Or $tg Func IsColorMatch($color1, $color2, $threshMax, $threshMin = 0) If $threshMin = 0 And color1 <> $color2 Then Return False $threshMin = Abs($threshMin) $r1 = _ColorGetRed($color1) $g1 = _ColorGetGreen($color1) $b1 = _ColorGetBlue($color1) $r2 = _ColorGetRed($color2) $g2 = _ColorGetGreen($color2) $b2 = _ColorGetBlue($color2) $dr = Abs($r1 - $r2) $dg = Abs($g1 - $g2) $db = Abs($b1 - $b2) $tr = $dr > $threshMin $tg = $dg > $threshMin $tb = $db > $threshMin Return $tr Or $tg Or $tb EndFunc ;==>IsColorMatch Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now