Jump to content

Advanced Pixel Search Library


FastFrench
 Share

What do you think of this library ?  

35 members have voted

  1. 1. What do you think about FastFind ?

    • It's really great, I can't imagine doing a script without it
    • It's of some use for me in my current scripts
    • I could use it some day
    • Looks nice, but of no use for me
    • I've tried it, but it doesnt fit my needs
    • Sounds good on the paper, but can't make it work (bug or too difficult to use it)
  2. 2. Have you tried it ?

    • Yes, I'm using it right now
    • Somewhat, I've done some testing, will surely use it later
    • I've downloaded it and just played a little with packaged demo scripts
    • I've downloaded it, but not tried it so far
    • Not downloaded it so far, but I probably will some day
    • It's of no interested for me.
  3. 3. What is missing or should be improved ?

    • It has all the features I may need about Pixels Handling
    • OK it's pretty fast, but couldn't it be faster ?
    • Too hard to use it, could you simplify usage ?
    • Some additional features would be nice to have (please explain in a message)
    • It really lacks some decent documentation (I still hope to find someone to help on that)
    • Some critical features are missing, can't use it (please explain in a message)
    • I found some minor bugs (please explain in a message)
    • I've found some serious bugs (please explain in a message)
    • I've never tried it so far, can't tell
    • It would be nice if you could provide easy access to the associated tool - FFShowPixel
    • I would like to use it other languages. Could you provide wrappers ? (please explain in a message)


Recommended Posts

As I have tons of demands to use the FastFind dll in .NET languages, here is the small wrapper I've written to make the functions available in C#

using System;
using System.Runtime.InteropServices;

namespace XXXX.Tools.FastFind
{
  static public class FastFindWrapper
  {
    const string fastFindDllName = "FastFind64.dll";
    
    // Exclusion areas
    // ===============
    [DllImport(fastFindDllName)]
    public static extern void AddExcludedArea(int x1, int y1, int x2, int y2);

    [DllImport(fastFindDllName)]
    public static extern bool IsExcluded(int x, int y, IntPtr hWnd);

    [DllImport(fastFindDllName)]
    public static extern bool ResetExcludedAreas();

    // Configuration 
    // ==============
    [DllImport(fastFindDllName)]
    public static extern void SetDebugMode();

    [DllImport(fastFindDllName)]
    public static extern void SetHWnd(IntPtr NewWindowHandle, bool bClientArea);

    /// <summary>
    /// Usage : IntPtr ptr = GetLastErrorMsg();
    ///         string s = Marshal.PtrToStringAnsi(ptr);
    /// If extensively used, make sure there is no suspect memory leaks
    /// </summary>
    /// <returns></returns>
    [DllImport(fastFindDllName, CharSet = CharSet.Auto)]    
    public static extern IntPtr GetLastErrorMsg();

    [DllImport(fastFindDllName, CharSet = CharSet.Auto)]
    public static extern IntPtr FFVersion();

    // Basic functions
    [DllImport(fastFindDllName)]
    public static extern int GetPixel(int X, int Y, int NoSnapShot);
    [DllImport(fastFindDllName)]
    public static extern int ColorPixelSearch(ref int XRef, ref int YRef, int ColorToFind, int NoSnapShot);
    [DllImport(fastFindDllName)]
    public static extern int GetPixelFromScreen(int x, int y, int NoSnapShot); // Like GetPixel, but with screen coordinates

    // Snapshots
    [DllImport(fastFindDllName)]
    public static extern int SnapShot(int aLeft, int aTop, int aRight, int aBottom, int NoSnapShot);

    // List of colors management
    [DllImport(fastFindDllName)]
    public static extern int AddColor (UInt32 NewColor);
    [DllImport(fastFindDllName)]
    public static extern int RemoveColor (UInt32 NewColor);
    [DllImport(fastFindDllName)]
    public static extern void ResetColors ();

    // Search function, for multiple colors (color list should be defined first)
    [DllImport(fastFindDllName)]
    public static extern int ColorsPixelSearch(ref int XRef, ref int YRef, int NoSnapShot);
    
    // ColorsSearch is close to ColorSearch, except it can look for several colors instead of only one. 
    [DllImport(fastFindDllName)]    
    public static extern int ColorsSearch(int SizeSearch, ref int NbMatchMin, ref int XRef, ref int YRef, int NoSnapShot);
    
    // Most generic search function : called in most case. 
    [DllImport(fastFindDllName)]
    public static extern int GenericColorSearch(int SizeSearch, ref int NbMatchMin, ref int XRef, ref int YRef, int ColorToFind, int ShadeVariation, int NoSnapShot);
    
    // New vith verion 1.4 : more powerful search function : looks for 'spots' instead of pixels
    [DllImport(fastFindDllName)]
    public static extern int ProgressiveSearch(int SizeSearch, ref int NbMatchMin, int NbMatchMax, ref int XRef, ref int YRef, int ColorToFind/*-1 if several colors*/, int ShadeVariation, int NoSnapShot);

    // Count pixels with a given color
    [DllImport(fastFindDllName)]
    public static extern int ColorCount(int ColorToFind, int NoSnapShot, int ShadeVariation);

    /// // SnapShot saving into bitmap file
    [DllImport(fastFindDllName)]
    public static extern bool SaveBMP(int NoSnapShot, string szFileName /* With no extension (xxx.bmp added)*/);
    [DllImport(fastFindDllName)]
    public static extern bool SaveJPG(int NoSnapShot, string szFileName /* With no extension*/, UInt64 uQuality) ;
    [DllImport(fastFindDllName)]
    public static extern int GetLastFileSuffix();

    // Raw SnapShot rata retrieval
    [DllImport(fastFindDllName)]
    public static extern IntPtr GetRawData(int NoSnapShot, ref int NbBytes);

    // Detection of changes between two SnapShots
    [DllImport(fastFindDllName)]
    public static extern int KeepChanges(int NoSnapShot, int NoSnapShot2, int ShadeVariation);  // ** Changed in version 2.0 : ShadeVariation added **
    [DllImport(fastFindDllName)]
    public static extern int KeepColor(int NoSnapShot, int ColorToFind, int ShadeVariation);  
    [DllImport(fastFindDllName)]
    public static extern int HasChanged(int NoSnapShot, int NoSnapShot2, int ShadeVariation);  // ** Changed in version 2.0 : ShadeVariation added **
    [DllImport(fastFindDllName)]
    public static extern int LocalizeChanges(int NoSnapShot, int NoSnapShot2, ref int xMin, ref int yMin, ref int xMax, ref int yMax, ref int nbFound, int ShadeVariation);  // ** Changed in version 2.0 : ShadeVariation added **

    // Display of a SnapShot
    [DllImport(fastFindDllName)]
    public static extern bool DrawSnapShot(int NoSnapShot);
    [DllImport(fastFindDllName)]
    public static extern bool DrawSnapShotXY(int NoSnapShot, int X, int Y); // ** New in version 2.0 **

    // Change of the color of a pixel (hyper-omptimized function)
    [DllImport(fastFindDllName)]
    public static extern bool FFSetPixel(int x, int y, int Color, int NoSnapShot);

    // SnapShot duplication
    [DllImport(fastFindDllName)]
    public static extern bool DuplicateSnapShot(int Src, int Dst);

    // Misc functions, new in version 2.0
    [DllImport(fastFindDllName)]
    public static extern int ComputeMeanValues(int NoSnapShot, ref int MeanRed, ref int MeanGreen, ref int MeanBlue);
    [DllImport(fastFindDllName)]
    public static extern int ApplyFilterOnSnapShot(int NoSnapShot, int Red, int Green, int Blue);
  }
}
Link to comment
Share on other sites

oh thanks, my previous question is very old and i find the answer id docs.

My next questions

1)can i load img, NOT take snapshot. U lib is very simply to small processing on img.

2)Take 1 big snapshot and add exclude rects slower than take many small snapshots.... logs 200 mb and for all pixels uses "isexcluded" function.

Link to comment
Share on other sites

1/ nop, not yet. You can save, but not load bitmaps.

2/ depends what you have to do. Taking the captures is often the most time consuming task, and isexcluded is quite fast with a reasonnable number of exclusion rects. If you have few captures and lot of searchs to do on each, it should be faster NOT to use those rects.

Link to comment
Share on other sites

  • 2 months later...

Hi!

Great library! I am trying to do some pattern recognition and while your library doesn't provide that part I am using it as a fast first-step filter to find useable sites for the pattern.

For example, I have a cross that looks like this:

00011000

00011000

00011000

11111111

11111111

00011000

00011000

00011000

My program adds the number of positive bits (e.g. "1") and finds that the 8x8 pixel pattern contains 28 white pixels. My routine then do a FFNearestSpot for a 8x8 area with 28 white pixels. Your function finds a match and my routine will compare the found 8x8 area to this pattern and generate a matching value based on the number of bits that match. It will then exclude this 8x8 bit area from the search using FFAddExcludedArea and repeat the search until no more 8x8 areas with 28 white pixels can be found. The area that has the best matching value will then "win" and is reported as the closest match to the pattern recognition.

This works quite well if the searched area is not too big. If it comes over a certain size with too many "matches" to the FFNearestSpot, it stops working. E.g. it does not report the same area over and over again as I exclude them with FFAddExcludedArea, but is simply does not find all the spots with 8x8 areas that have 28 pixels in them.

Is this a problem with FFAddExcludedArea or is there something else that doesn't work?

(see below for update)

Here is the routine I use:

Func FindIconBW($x,$y,$var,$white,$digarr)  ; Searches full screen for BW icon: FindIconBW(xsize,ysize,shadevariation,whitecolor,digital array)
    Local $z=0
    For $a=0 To $x-1
        For $b=0 To $y-1
            $z=$z+$digarr[$a][$b]   ;Sum up number of white pixels to search for
        Next
    Next
    Local $found=0
    Local $siz=$x
    Local $sym=Abs($x-$y)   ;symmetry is 0 if xsize and ysize equal
    Local $iconpos[2]
    If $y>$x Then $siz=$y
    $ResIcon = FFSnapShot() ;Full screen snapshot
    FFResetExcludedAreas()
    FFAddColor(0xFFFFFF)
    FFAddColor($white)
    $w = Hex($white,6);
    $w1 = Dec(StringMid($w,1,2))    ;Red
    $w2 = Dec(StringMid($w,3,2))    ;Green
    $w3 = Dec(StringMid($w,5,2))
    $w=Round(($w1+$w2+$w3)/3,0)
    FFAddExcludedArea(0,0,1920,350) ; Dont search menu lines
    FFAddExcludedArea(0,1020,1920,1080) ; Dont search window border
    FFAddExcludedArea(0,350,20,1020)    ; Dont search window border
    FFAddExcludedArea(1890,350,1920,1020)   ; Dont search browser border
    ;FFAddExcludedArea(20,350,1600,1020)    ; Dont search left side of screen
    Local $match=0
    do
        ; Find a spot that contains $z pixels within $x * $y size
        $ResIcon = FFBestSpot($siz, $z-1, $z, 0, 0, -1 , $var, false, 0, 0, 0, 0)
        ;$ResIcon = FFNearestSpot($siz, $z, 0, 0, -1 , $var, false)
        if (IsArray($ResIcon)) Then
            ; potential match found
            $maxmatch=0
            for $c=0 to $sym*3  ; Has to move pattern test around if it is not symmetric to get "perfect" match
                for $d=0 to $sym*3
                    $match=0
                    For $a=0 To $x-1
                        For $b=0 To $y-1
                            $z = Hex(FFGetPixel($ResIcon[0]+$a-($x/2)+$c,$ResIcon[1]+$b-($y/2)+$d),6);
                            $z1 = Dec(StringMid($z,1,2))    ;Red
                            $z2 = Dec(StringMid($z,3,2))    ;Green
                            $z3 = Dec(StringMid($z,5,2))
                            $z=Round(($z1+$z2+$z3)/3,0)
                            If ($z>=($w-(3*$var))) Then
                                If $digarr[$b][$a]=1 Then $match+=1 ;Sum up number of matching white pixels
                            Else
                                If $digarr[$b][$a]=0 Then $match+=1 ;Sum up number of matching white pixels
                            EndIf
                        Next
                    Next
                    If $match>$maxmatch Or ($c=0 And $d=0) Then
                        $maxmatch=$match
                        $iconpos[0]=$ResIcon[0]-($x/2)+$c
                        $iconpos[1]=$ResIcon[1]-($y/2)+$d
                    EndIf
                next
            next
            IF $maxmatch=($x*$y) Then
                local $sMsg = "Found at x="&$iconpos[0]&",y="&$iconpos[1]&":match="&$maxmatch&",t="&($w-(3*$var))
                FFTrace("   ** "&$sMsg&@lf&"")
                TrayTip("Found", $sMsg, 2000)
                $found=1

            Else
                local $sMsg = "Not at x="&$iconpos[0]&",y="&$iconpos[1]&":match="&$maxmatch&",t="&($w-(3*$var))
                FFTrace("   ** "&$sMsg&@lf&"")
                TrayTip("Potential", $sMsg, 2000)
                FFAddExcludedArea($iconpos[0],$iconpos[1],$iconpos[0]+$x,$iconpos[1]+$y)    ; Remove this pattern from search as it didnt match

            EndIf
        EndIf
    until ((Not IsArray($ResIcon)) OR $found=1)
    If ((Not IsArray($ResIcon)) AND $found<>1) Then
        Sleep(1000)
        local $sMsg = "No match found!"
        FFTrace("   ** "&$sMsg&@lf&"")
        TrayTip("No icon match", $sMsg, 2000)
    EndIf
EndFunc


Local $homeicon[16][16]=[[0,0,0,1,1,0,0,0],[0,0,0,1,1,0,0,0],[0,0,0,1,1,0,0,0],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[0,0,0,1,1,0,0,0],[0,0,0,1,1,0,0,0],[0,0,0,1,1,0,0,0]]
FindIconBW(8,8,46,0xD0E0F0,$homeicon)

If I include the "don't search left side of screen" line in this code, it finds the icon every time. If I don't include it, it fails.

Using FFNearestSpot also seems to give slightly more positives, but still the same result: After a number of negative matches it fails to find the spot with the icon.

Any idea what is wrong?

Typical! I ask a question and I find the solution myself :P

If you want to use this routine, change the name of the $z parameter that contains the number of white pixels to $pz or something as $z was reused in the routine.

If you also want to exclude any non-perfect match you can speed it up considerably by quitting on a negative:

If ($z>=($w-(3*$var))) Then
                                If $digarr[$b][$a]=1 Then
                                    $match+=1   ;Sum up number of matching white pixels
                                Else    ; Fail, so quit (only perfect match allowed)
                                    $a=$x-1
                                    $b=$y-1
                                EndIf
                            Else
                                If $digarr[$b][$a]=0 Then
                                    $match+=1   ;Sum up number of matching white pixels
                                Else    ; Fail, so quit (only perfect match allowed)
                                    $a=$x-1
                                    $b=$y-1
                                EndIf
                            EndIf

Update:

I also found that the FFNearestSpot is better if you have an idea on were on the screen to start the search. Another problem seems to be that the search time increases with the number of Excluded areas, so a better way may be to simply color the false positives with black color:

For $a=0 To $x-1
                    For $b=0 To $y-1
                        FFSetPixel($iconpos[0]+$a,$iconpos[1]+$b, 0)    ; Instead of excluding, draw black across false spot; speeds up consecutive searches
                    Next
                Next
                ;FFAddExcludedArea($iconpos[0]+1,$iconpos[1]+1,$iconpos[0]+$x,$iconpos[1]+$y)   ; Remove this pattern from search as it didnt match

For color search you could change the routine to search for the three color components instead of combining them to a grayscale. I will try to see if I can get that to work.

Edited by kakemoms
Link to comment
Share on other sites

Ok. I made a color version for the icon search. I also added a icon reader and a function to dump it to the screen. It works quite well compared to the Black&White one:

Func FindIconCol($x,$y,$wcol1,$wcol2,$digarr)   ; Searches full screen for Color icon: FindIconCol(xsize,ysize,mincolor,maxcolor,digital array)
    Local $pz=0
    For $a=0 To $x-1
        For $b=0 To $y-1
            $pz=$pz+$digarr[$a][$b] ;Sum up number of white pixels to search for
        Next
    Next
    Local $v1
    Local $v2
    Local $v3
    Local $vam
    Local $vax
    Local $van
    Local $found=0
    Local $siz=$x
    Local $sym=Abs($x-$y)   ;symmetry is 0 if xsize and ysize equal
    Local $iconpos[2]
    If $y>$x Then $siz=$y
    $ResIcon = FFSnapShot() ;Full screen snapshot
    FFResetExcludedAreas()
    FFResetColors()
    $w = Hex($wcol1,6);
    $w1 = Dec(StringMid($w,1,2))    ;Red
    $w2 = Dec(StringMid($w,3,2))    ;Green
    $w3 = Dec(StringMid($w,5,2))
    $u = Hex($wcol2,6);
    $u1 = Dec(StringMid($u,1,2))    ;Red
    $u2 = Dec(StringMid($u,3,2))    ;Green
    $u3 = Dec(StringMid($u,5,2))
    $t1=Abs($w1-$u1)
    $t2=Abs($w2-$u2)
    $t3=Abs($w3-$u3)
    ; Find max variation:
    If $t1>=$t2 And $t1>=$t3 Then
        $vax=$t1/2
        $vam=$t2/2
        If $t2>$t3 Then $vam=$t3/2
    ElseIf $t2>=$t3 Then
        $vax=$t2/2
        $vam=$t1/2
    Else
        $vax=$t3/2
        $vam=$t1/2
    EndIf
    ; So we have a vam value that is the minumum variation if the threshold is put at $w+$vam
    ; and a vax value that is the maximum variation if the threshold is put at $w+$vax
    ; "worst" case is that vam is 0 (one of the colors is $ff) and vax is 128 (one color is $00)
    ; The number of colors to be added to the filter is vax*2/16 which can be up to 16:
    ; Each step is minimum 16 with 8 variation (+/-8)
    $van=Ceiling(($vax*2/16))   ; Number of steps
    For $a=0 To ($van-1)
        ;Round($a*$vax/$van,0)  ; Step Threshold based on $van
        $v1=Ceiling(($a+0.5)*$t1/$van)  ; Step Threshold based on $van steps. Since variation will be +/-0.5 around a certain color step
        ;$w1=0 -> $vax=127 -> $van=16
        ;$v1=0.5*255/16=8, $v1=1.5*255/16=24, ..., $v1=15.5*255/16=247
        ;$v1+w1=8,24,...,247
        $v2=Ceiling(($a+0.5)*$t2/$van)
        ;$w2=127
        ;$v2=0.5*128/16=4, $v2=1.5*255/16=12, ...
        $v3=Ceiling(($a+0.5)*$t3/$van)
        ;$w2=254
        ;$v2=0.5*1/16=0, $v1=1.5*1/16=0, ..., $v1=15.5*1/16=1
        Local $string=(Hex(($v1+$w1),2)&Hex(($v2+$w2),2)&Hex(($v3+$w3),2))  ; Assumes that w1,w2,w3 are the lowest values (check for this later)
        ;ConsoleWrite($string & @CRLF) ;
        FFAddColor(Dec($string))
    Next
    $var=Ceiling($vax/$van)*3       ;Variation for all the colors (3 colors)
    ;ConsoleWrite($var & @CRLF) ;
    ;FFAddColor(0xFFFFFF)
    ;FFAddColor($white)
    ;$w=Round(($w1+$w2+$w3)/3,0)
    FFAddExcludedArea(0,0,1920,200) ; Dont search menu lines
    FFAddExcludedArea(0,1020,1920,1080) ; Dont search window border
    FFAddExcludedArea(0,200,20,1020)    ; Dont search window border
    FFAddExcludedArea(1895,200,1920,1020)   ; Dont search browser border
    ;FFAddExcludedArea(20,350,900,1020) ; Dont search left side of screen
    Local $match=0
    do
        ; Find a spot that contains $z pixels within $x * $y size
        $ResIcon = FFBestSpot($siz, $pz-5, $pz, 00, 400, -1 , $var, false)
        ;$ResIcon = FFNearestSpot($siz, $pz, 1920, 400, -1 , $var, false)
        if (IsArray($ResIcon)) Then
            ; potential match found
            $maxmatch=0
            for $c=0 to ($x/2)  ; Has to move pattern test around if it is not symmetric to get "perfect" match
                for $d=0 to ($y/2)
                    $match=0
                    For $a=0 To $x-1
                        For $b=0 To $y-1
                            $z = Hex(FFGetPixel($ResIcon[0]+$a-($x/2)+$c,$ResIcon[1]+$b-($y/2)+$d),6);
                            $z1 = Dec(StringMid($z,1,2))    ;Red
                            $z2 = Dec(StringMid($z,3,2))    ;Green
                            $z3 = Dec(StringMid($z,5,2))
                            ;$z=Round(($z1+$z2+$z3)/3,0)
                            If ($z1>=($w1)) And ($z2>=($w2)) And ($z3>=($w3)) Then
                                If $digarr[$b][$a]=1 Then
                                    $match+=1   ;Sum up number of matching white pixels
                                Else    ; Fail, so quit (only perfect match allowed)
                                    ;$a=$x-1
                                    ;$b=$y-1
                                EndIf
                            Else
                                If $digarr[$b][$a]=0 Then
                                    $match+=1   ;Sum up number of matching white pixels
                                Else    ; Fail, so quit (only perfect match allowed)
                                    ;$a=$x-1
                                    ;$b=$y-1
                                EndIf
                            EndIf
                        Next
                    Next
                    If $match>$maxmatch Or ($c=0 And $d=0) Then
                        $maxmatch=$match
                        $iconpos[0]=$ResIcon[0]-($x/2)+$c
                        $iconpos[1]=$ResIcon[1]-($y/2)+$d
                    EndIf
                next
            next

            ;drawCircle($iconpos[0]*1920/1280,$iconpos[1]*1080/720)
            IF $maxmatch=($x*$y) Then
                local $sMsg = "Found at x="&$iconpos[0]&",y="&$iconpos[1]&":match="&$maxmatch&",t="&($w-(3*$var))
                FFTrace("   ** "&$sMsg&@lf&"")
                TrayTip("Found", $sMsg, 2000)
                $found=1
                drawCircle($iconpos[0]*1920/1280,$iconpos[1]*1080/720)
                sleep(1000)
            Else
                ;local $sMsg = "Not at x="&$iconpos[0]&",y="&$iconpos[1]&":match="&$maxmatch&",t="&($w-(3*$var))
                ;FFTrace("   ** "&$sMsg&@lf&"")
                ;TrayTip("Potential", $sMsg, 2000)
                ;drawCircle($iconpos[0]*1920/1280,$iconpos[1]*1080/720)
                ;FFSetPixel($x, $y, $Color, $NoSnapShot=$FFLastSnap)
                For $a=0 To $x-1
                    For $b=0 To $y-1
                        FFSetPixel($iconpos[0]+$a,$iconpos[1]+$b, 0)    ; Instead of excluding, draw black across false spot; speeds up consecutive searches
                    Next
                Next
                ;FFAddExcludedArea($iconpos[0]+1,$iconpos[1]+1,$iconpos[0]+$x,$iconpos[1]+$y)   ; Remove this pattern from search as it didnt match
                ;sleep(1000)
            EndIf
        EndIf
    until ((Not IsArray($ResIcon)) OR $found=1)
    If ((Not IsArray($ResIcon)) AND $found<>1) Then
        ;Sleep(1000)
        local $sMsg = "No match found!"
        FFTrace("   ** "&$sMsg&@lf&"")
        TrayTip("No icon match", $sMsg, 2000)
    EndIf
EndFunc

For reading an icon & printing it to the console (as AutoIT code):

Func ReadIconCol($x,$y,$white)  ; Read a 16x16 area with "white" as threshold and put it into $digarr.
    $ResIcon = FFSnapShot() ;Full screen snapshot
    FFResetExcludedAreas()
    FFResetColors()
    $w = Hex($white,6);
    $w1 = Dec(StringMid($w,1,2))    ;Red
    $w2 = Dec(StringMid($w,3,2))    ;Green
    $w3 = Dec(StringMid($w,5,2))
    $w=Round(($w1+$w2+$w3)/3,0)
    Local $pz=0
    Local $mean=0
    Local $varmax=0
    Local $var=0
    For $a=0 To 15
        For $b=0 To 15
            $z = Hex(FFGetPixel($x+$b,$y+$a),6);
            $z1 = Dec(StringMid($z,1,2))    ;Red
            $z2 = Dec(StringMid($z,3,2))    ;Green
            $z3 = Dec(StringMid($z,5,2))    ;Blue
            $z=Round(($z1+$z2+$z3)/3,0)
            If ($z1>=$w1) And ($z2>=$w2) And ($z3>=$w3) Then
                $digarr[$b][$a]=1
                $pz+=1
                $var=$var+$z
                If $z1>$varmax Then $varmax=$z1
                If $z2>$varmax Then $varmax=$z2
                If $z3>$varmax Then $varmax=$z3
            Else
                $digarr[$b][$a]=0
            EndIf
        Next
    Next
    $mean=$var/$pz  ; mean "white" color
    if ($mean-$w)>($varmax-$mean) Then
        $var=$mean-$w
    Else
        $var=$varmax-$mean
    EndIf
    Return $digarr
EndFunc

Func PrintIcon($digarr)
    Local $sString = "["
    For $a=0 To 15
        $sString = $sString &"["
        For $b=0 To 15
            If $digarr[$b][$a]=1 Then
                $sString = $sString & "1"
            Else
                $sString = $sString & "0"
            EndIf
            If $b<>15 Then
                $sString = $sString & ","
            Else
                $sString = $sString & "]"
            EndIf
        Next
        If $a=15 Then
            $sString = $sString & "]"
        Else
            $sString = $sString & ", _"
        EndIf
        ConsoleWrite($sString & @CRLF) ;
        $sString = ""
    Next
EndFunc

Enjoy!

Link to comment
Share on other sites

  • 1 month later...

massive thanks to FastFrench, great tool and works perfect with AutoIt! :)

could someone help with integrating these functions in Visual Studio C++, though? I've tried simply #include "FastFind.h" and using SnapShot() function, but I get "Error    1    error LNK2019: unresolved external symbol "int __stdcall SnapShot(int,int,int,int,int)" (?SnapShot@@YGHHHHHH@Z)".

I also tried adding FastFind.dll's directory in "Project->Properties->Configuration Properties->C/C++->General->Additional include directories" and the FastFind.dll in "Project->Properties->Configuration Properties->Linker->Input->Additional Dependencies" but then I get "Error    1    error LNK1107: invalid or corrupt file: cannot read at 0x2B0".

I will really appreciate any help on using FastFind in C++

 

Link to comment
Share on other sites

  • 3 months later...
  • Developers

Sweet .. thanks for sharing that info or did you try to ask a question here without providing any more info than an invalid statement containing "<mycolor>"?

Jos 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Guess I wasn't direct enough with my previous post: Seriously, what the hell are you assuming we can do for you when you do not provide all needed information on what you are doing and what is going wrong?  

Jos 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Is it possible to add functionality for a Flood-fill algorithm (magic wand)?

There used to be a script here of a magic wand on the forums, but all links on that thread do not work, and nobody posted the code.

 

I'm specifically looking to be able to perform Flood-fills to a certain pixel, or a group of specified pixels. With or without Tolerance.

 

Also, I'm looking to emulate the following Photoshop functions in code: Expand selection, contract selection, smooth selection, Intersect selection (selection A intersect with selection B.)

Edit: Nvm about that. I found a Floodfill example for Autoit, however it is a bit slow.

Edit2: Ok so I got FFKeepcolor to work despite my sample code displaying false.

 

Is there a way to save files as png? I specifically need this for transparency.

Also, how can I exclude an area that is an Ellipse shape? For example if I specify the center (x,y), and radius R.

Edited by KrinnyAit
Help with FFKeepColor
Link to comment
Share on other sites

  • 1 month later...
$hWndzz = WinGetHandle("[CLASS:Notepad]")
FFSnapShot(0, 0, 0, 0, $hWndzz)
FFSaveBMP("snapshot", false, 0,0,0,0, 1)

Errors:

1- SnapShot (0,0,0,0,0x000F064C,FFFFFFFF) failed

2- IsArray($Res):1 - Ubound($Res):6 , $Res[0]:0

3- Line 283 (File "C:\...."); $FFLastSnapStatur[$NoSnapShot] = -1 ..... Error: Array variable has incorrect number of subscripts orsubscript dimension range exceeded.

Windows 7 32bit

Link to comment
Share on other sites

  • 4 weeks later...

Hello. 

I am very new to autoit and i just download fastfind 2.2. So i just wondering is it posible to use fastfind to search pixel or picture on the program that minimize? If yes please teach me how to do.

Sorry i am not good in english.

Link to comment
Share on other sites

  • 2 weeks later...

I'm getting "Failed to load":

fferror.png

First it pops up a dialog "Can't start, try again." Then the above, "Failed to load FastFind.dll, application probably won't work. Check if the file FastFind.dllis installed near this script".

This has been working fine for ages, but now when I try in the same folder as it always was, with FastFind.dll in the same folder as both my script and the FastFind.au3, it won't load. Probably Windows is refusing to load the DLL for some security reason. I've tried the file properties, and on another machine when I first copied it across there was a thing at the bottom of the properties that said "This is from another computer" with a click to allow it, which I clicked, but it still won't load on that computer either. Both are Windows 7.

Link to comment
Share on other sites

  • 2 months later...
  • 3 weeks later...

Hello, i have implemented for C# autoit PixelSearch compatibility with FastFind couse i needed the search direction.

What is missing from autoit PixelSearch is only hwnd witch can be passed easly to snapshot function but i needed full screen size so i didnt implemented.

 

public Point PixelSearch(int left, int top, int right, int bottom, int color, int shade) {

            Point Pixel_Coords = new Point(-1, -1);
            Color a = Color.FromArgb(color);
            if (left < right & top < bottom) { SnapShot(left, top ,right ,bottom, 0); }
            if (left > right & top < bottom) { SnapShot(right, top, left, bottom, 0); }
            if (left > right & top > bottom) { SnapShot(right, bottom, left, top, 0); }
            if (left < right & top > bottom) { SnapShot(left, bottom, right, top, 0); }

            int j = left;     // from left to right
            int l = right;
            if (left > right) 
            {
                j = -(left); // from right to left
                l = right;
            }
                for (; j <= l; j++) // x search loop
                {
                    int k = top; // from top to bottom
                    int m = bottom;
                    if (top > bottom)
                    { 
                        k = -(top); //from bottom to top
                        m = bottom;
                    }

                    for (; k <= m; k++) // y search loop
                    {
                        Color c = Color.FromArgb(FFGetPixel(Math.Abs(j), Math.Abs(k), 0));
                        if (c.R >= a.R - shade & c.R <= a.R + shade)
                        {
                            if (c.G >= a.G - shade & c.G <= a.G + shade)
                            {
                                if (c.B >= a.B - shade & c.B <= a.B + shade)
                                {
                                    Pixel_Coords = new Point(Math.Abs(j), Math.Abs(k));
                                    LogWrite("PixelSearch : Found at (" + Math.Abs(j) + ":" + Math.Abs(k) + ")");
                                    return Pixel_Coords;  // return pixel location
                                }
                            }
                        }
                    }
                }
            
            return Pixel_Coords; //if no pixel found return (-1,-1);
        }

Also if someone can respond to Coderxy01 question, i have the same error too when i try to compare two snapshot. it happens in a loop, the first  compare works then error starts to pop. 

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...