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

Good news :mellow:

By the way, FFIsExcluded returns true of false (and not an array). So the way you're using it is probably wrong, or at least strange :

$IsExcluded = FFIsExcluded($MousePosition[0], $MousePosition[1], $hWnd)
    If IsArray($IsExcluded) Then
        $ExclResult = $IsExcluded[0] & "x" & $IsExcluded[1]
    Else
        $ExclResult = $IsExcluded
    EndIf

Should produce the same result as :

$ExclResult = FFIsExcluded($MousePosition[0], $MousePosition[1], $hWnd)
Link to comment
Share on other sites

Great work thank you.

Running the Demo, when pressing F5 I get a debug dialog stating "Snapshot Nº0 not properly initialized". Pressing F5 again then it works as intended.

What can I change to init the snapshot Nº0?

; Demo FastFind (officielle)
#include "FastFind.au3"
#Include <WinAPI.au3>
 
#RequireAdmin
 
global const $DEBUG_DEFAULT = 3
global const $DEBUG_GRAPHIC = $DEBUG_DEFAULT + 4
global const $WINDOW_CLASS = "Notepad" ; CLASS of the target Window
global const $WINDOW_TITLE = "" ; TITRE of the target Window
 
FFSetDebugMode($DEBUG_GRAPHIC) ; Enable advanced (graphical) debug mode, so you will have traces + graphical feedback
FFSetDefaultSnapShot(0)
FFSnapShot(0,0,100,100)

I added a FFSnapshot() after the first FFSetDefaultSnapShot(0) and this seems to work for me. I'm new to this, is this the correct way to do this?

Regards

Edited by 2wice
Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Hi FastFrench,

Firstly, fantastic script! I'm still only testing, but I predict this is going to make my current project run at least 100 times faster. I have a few questions that have come up in my tests, though:

1. Every so often, when I run my script I get a message box saying "Can't start, try again." followed by the "Failed to load FastFind.dll, application probably won't properly work." message box from FastFind.au3. But if I wait a minute or two and try running again, it works fine. Do you have any idea what might be causing this? I thought that maybe the DLL is not being closed properly, but it does this sometimes even on the first execution. I'll continue investigating, because I won't be able to use your DLL if I can't fix it, and I REALLY, REALLY want to use your DLL! :graduated:

2. FFSaveBMP produces some strange BMP files. I think someone mentioned it before, but there's always a black vertical line down the right hand side and when I try opening them in PhotoShop the Pixel Aspect Ratio is all messed up. FFSaveJPG used on the same SnapShot works okay. I can reproduce it with the following:

#include "FastFind.au3"
AutoItSetOption("WinTitleMatchMode", 4)
$FFhWnd = WinGetHandle("[ACTIVE]")
FFSetWnd($FFhWnd)
FFSnapShot(0, 0, 300, 150)
FFSaveBMP(@YEAR & "-" & @MON & "-" & @MDAY & "_" & @HOUR & @MIN & @SEC, false)
FFSaveJPG(@YEAR & "-" & @MON & "-" & @MDAY & "_" & @HOUR & @MIN & @SEC, 100, false)

3. In my speed tests on FFNearestPixel, I noticed that changing the $Left, $Top, $Right and $Bottom parameters doesn't seem to do anything. Using these to restrict the search area does not increase the speed, and it continues to find pixel coordinates outside of the specified area.

4. In the FFSaveBMP and FFSaveJPG there is this line:

local $Suffixe = DllCall($FFDllHandle, "int", "GetLastFileSuffix")

Is this used for anything, or is it left over code?

I'm willing to help with some documentation (in English) if you're still looking for someone. Keep up the good work!

Link to comment
Share on other sites

Update on the DllOpen failure. It's happening on both WinXP and Win7 32bit. I tried registering the DLL through Dependency Walker to get some more information and here's what came back:

DllMain(0x00960000, DLL_PROCESS_ATTACH, 0x00000000) in "FASTFIND.DLL" returned 0 (0x0).

Unloaded "FASTFIND.DLL" at address 0x00960000.

Unloaded "GDIPLUS.DLL" at address 0x4EC50000.

LoadLibraryExW("C:\Documents and Settings\mac\My Documents\Projects\AutoIt\FastFind\FastFind.dll", 0x00000000, LOAD_WITH_ALTERED_SEARCH_PATH) returned NULL. Error: A dynamic link library (DLL) initialization routine failed (1114).

There's nothing in TRACER.TXT for these failed runs, so I don't know what else to look for. Would need some debugging in DllMain to figure it out. It's very odd that it only happens some of the time, though.
Link to comment
Share on other sites

Thank you for the report, I'll try do do some update if/when I find the time. Do other people have this same error message ?

Actually, this summer some nice robbers stole my laptop with USB keys, so I've lost the very last version of the sources. I hopefully have a complete backup between version 1.6 and 1.7, but it's still annoying to recode missing parts :graduated:

@2 : does it also happen when the width is multiple of 4 ? using FFSnapShot(0,0,299,150) for instance.

@3 : Quite normal. If you check the code in the Autoit wrapper, you'll see that those are optional and only used when a snapshot is done.

@4 : If the filename is allready used, a number is added as a suffix to avoid overwritting the existing file. This $Suffixe variable can be used to know the exact name of the file that was actually written.

Any help to start some decent documentation in English is still very welcome. You may start with the basic concepts used (goal of FastFind, how to start, use of SnapShots...). For the format, you can can either MSWord or HTML, as you wish.

I would gladly inclose this documentation - even partial - in the next version of FastFind.

Edited by FastFrench
Link to comment
Share on other sites

Sorry to hear about your laptop, :graduated: but it's good you have a recent backup. So many of my projects are not stored anywhere else.

2. You're right, the width of the black line is always equal to snapshot width modulo 4, so it disappears with FFSnapShot(0,0,299,150). However, the Pixel Aspect Ratio distortion remains, and I need to keep adjusting it if I open the image in Photoshop.

3. Ah, I didn't notice that. So to search a particular area of a snapshot I need to add exclusion zones everywhere else, or make a new snapshot of only the area I want?

4. Okay, but $Suffixe doesn't get used, so why bother fetching it? Unless the following code that sets $LastFileNameParam is supposed to be using it?

I'll get started on some documentation this weekend. HTML will be better, so it can be bundled into a single .chm file with search/index/contents.

Link to comment
Share on other sites

Sorry to keep coming back with possible bugs. :graduated: The following script claims that point 5,5 is not in the exclusion zones:

#include "FastFind.au3"
 
AutoItSetOption("WinTitleMatchMode", 4)
 
$handle = WinActivate("[CLASS:Notepad]")
FFSetWnd($handle)
 
FFAddExcludedArea(0, 0, 10, 10)
If FFIsExcluded(5, 5, $handle) Then
    MsgBox(0, "Exclusion", "5,5 is excluded!")
Else
    MsgBox(0, "Exclusion", "5,5 is NOT excluded!")
EndIf
Am I using it incorrectly?
Link to comment
Share on other sites

Hello FastFrench,

Based on your idea quoted below and something I did here is it possible to add a function similar to PixelChecksum which will compute the checksum for pixels of a certain color, ignoring the other colors? Or calculate the checksum of a region only for the pixels which are in an array of colors ? This would be useful when searching for a pattern - let's say text over a background which changes often.

Another idea I had, would be to have the ability to provide some mask to find a precise pattern on the screen.

For exemple, providing the following pattern would mean to take in account only the pixels corresponding to to the "1", ignoring all others. This would probably greatly reduce the "noise" when looking for some precise pattern.

000000000000000

000000111000000

000010000010000

000100000001000

001000000000100

001000000000100

010000000000010

010000000000010

001000000000100

000100000001000

000010000010000

000000111000000

000000000000000

For the double screen: it works fine for me with extended display on two screens. Works as if I had a larger one (width around 2900). Now I've not done extensive testing on different configurations. It's probably very OS-dependant.

Thanks and keep up the great work

Edited by Drin
Link to comment
Share on other sites

I think there's a problem with FFRemoveColor when there's more than one color in the list. The following script dies with a "program has stopped working" message from Windows:

#include "FastFind.au3"
 
FFAddColor(0x00FFFFFF)
FFAddColor(0x00000000)
 
FFRemoveColor(0x00FFFFFF)

OK, thanks. I've found the problem, will be fixed in next coming version.

Sorry to keep coming back with possible bugs. :graduated: The following script claims that point 5,5 is not in the exclusion zones:

#include "FastFind.au3"
 
AutoItSetOption("WinTitleMatchMode", 4)
 
$handle = WinActivate("[CLASS:Notepad]")
FFSetWnd($handle)
 
FFAddExcludedArea(0, 0, 10, 10)
If FFIsExcluded(5, 5, $handle) Then
    MsgBox(0, "Exclusion", "5,5 is excluded!")
Else
    MsgBox(0, "Exclusion", "5,5 is NOT excluded!")
EndIf
Am I using it incorrectly?

In fact, exclusion rectangles are associated with SnapShots (each current snapshot can have its own exclusion rectangles). As you've done no snapshot, I suspect that it's the problem.

Update on the DllOpen failure. It's happening on both WinXP and Win7 32bit. I tried registering the DLL through Dependency Walker to get some more information and here's what came back:

There's nothing in TRACER.TXT for these failed runs, so I don't know what else to look for. Would need some debugging in DllMain to figure it out. It's very odd that it only happens some of the time, though.

Will be fixed in the coming version.

And for the BMP saving problems, I've switched from GDI to GDI+ (as I did for JPG). I won't have time to test this feature, so please tell me if it's OK now (in version 1.8).

Link to comment
Share on other sites

Thanks FastFrench! I'm not getting that "Can't Start" error anymore, so I can now use FastFind as a standard replacement for PixelGetColor and PixelSearch in all my scripts. Awesome stuff. ;)

The current version and dll names in the FastFind.au3 need to be updated in v1.8.

In fact, exclusion rectangles are associated with SnapShots (each current snapshot can have its own exclusion rectangles). As you've done no snapshot, I suspect that it's the problem.

Then how does it decide which snapshot to add the exclusion zone to? And why pass the window handle? I get the same behaviour when I use a snapshot like this, so I don't think that's the problem:

#include "FastFind.au3"
 
AutoItSetOption("WinTitleMatchMode", 4)
 
$handle = WinActivate("[CLASS:Notepad]")
FFSetWnd($handle)
FFSnapShot(0, 0, 299, 149)
FFAddExcludedArea(0, 0, 10, 10)
 
If FFIsExcluded(5, 5, $handle) Then
    MsgBox(0, "Exclusion", "5,5 is excluded!")
Else
    MsgBox(0, "Exclusion", "5,5 is NOT excluded!")
EndIf

And for the BMP saving problems, I've switched from GDI to GDI+ (as I did for JPG). I won't have time to test this feature, so please tell me if it's OK now (in version 1.8).

This is not working on Win7 32bit. It produces an empty 0KB file. :graduated: I think it works okay on WinXP, because I tried it out on my work computer earlier today, and I didn't notice any problems then.

Oh, and that FFShowPixels link never worked for me either. Apparently I don't have permission to download the file.

Link to comment
Share on other sites

Hello FastFrench,

it does not work for me , the function FFnearestSpot - it finds the color outside my area and is then TRUE, what i no want. i mean the "actions folder" does not correctly work.

#include "FastFind.au3"
#include <Array.au3>
 
HotKeySet ( "{NUMPAD1}" , "start" )
 
While 1
    Sleep(300)
WEnd
Func start()
While 1
 
$Basis_oben_links = DllCall($FFDllHandle, "int", "FFGetPixel", "int", 662, "int", 62, "int",$FFLastSnap)
If $Basis_oben_links[0] = 3061969 Then
  Do
   MouseClick ("left",662,148,1,1)
   $FFLastSnap = DllCall($FFDllHandle, "int", "SnapShot", "int", 0, "int", 0, "int", 0, "int", 0, "int", 0)
   $Schwarzesfeld_p1 = DllCall($FFDllHandle, "int", "FFGetPixel", "int", 395, "int", 15, "int",$FFLastSnap)
  Until $Schwarzesfeld_p1[0]  <> 0
  ExitLoop
Endif
$Basis_unten_rechts = DllCall($FFDllHandle, "int", "FFGetPixel", "int", 749, "int", 149, "int",$FFLastSnap)
If $Basis_unten_rechts[0] = 3061969 Then
  Do
   MouseClick ("left",662,148,1,1)
   $FFLastSnap = DllCall($FFDllHandle, "int", "SnapShot", "int", 0, "int", 0, "int", 0, "int", 0, "int", 0)
   $Schwarzesfeld_p2 = DllCall($FFDllHandle, "int", "FFGetPixel", "int", 793, "int", 83, "int",$FFLastSnap)
  Until $Schwarzesfeld_p2[0]  <> 0
  ExitLoop
Endif
WEnd
 
While 1
 
$Object1 = FFNearestSpot(5, 1, 397, 287, 0x687162 , 1 ,false)
If IsArray($Object21) = True Then
  ;action
  ExitLoop
EndIf
 
$Object2 = FFNearestSpot(3, 2, 359, 309, 0x4E5E63 , 1 ,false)  
If IsArray($Object2) = True Then
 
  ;action
  ExitLoop
  EndIf
 
  $Object3 = FFNearestSpot(1, 1, 389, 263, 0x090C0B , 1 ,false)
  If IsArray($Object3) = True Then
  ;action
  ExitLoop
  EndIf
 
WEnd
 
EndFunc

A. The current version and dll names in the FastFind.au3 need to be updated in v1.8.

B. Oh, and that FFShowPixels link never worked for me either. Apparently I don't have permission to download the file.

same Problem Edited by John81
Link to comment
Share on other sites

Thanks FastFrench! I'm not getting that "Can't Start" error anymore, so I can now use FastFind as a standard replacement for PixelGetColor and PixelSearch in all my scripts. Awesome stuff. ;)

The current version and dll names in the FastFind.au3 need to be updated in v1.8.

You're right, I'll update the 1.8 version right now. Thanks.

Then how does it decide which snapshot to add the exclusion zone to? And why pass the window handle? I get the same behaviour when I use a snapshot like this, so I don't think that's the problem:

#include "FastFind.au3"
 
AutoItSetOption("WinTitleMatchMode", 4)
 
$handle = WinActivate("[CLASS:Notepad]")
FFSetWnd($handle)
FFSnapShot(0, 0, 299, 149)
FFAddExcludedArea(0, 0, 10, 10)
 
If FFIsExcluded(5, 5, $handle) Then
    MsgBox(0, "Exclusion", "5,5 is excluded!")
Else
    MsgBox(0, "Exclusion", "5,5 is NOT excluded!")
EndIf

Oops... looks like there is a mistake in the FastFind.au3 :

Func FFAddExcludedArea(const $x1, const $y1, const $x2, const $y2)
local $Res = DllCall($FFDllHandle, "int", "FFAddExcludedArea", "int", $x1, "int", $y1, "int", $x2, "int", $y2)
if IsArray($res) Then return $res[0]
return $res
EndFunc

You should change "FFAddExcludedArea" into "AddExcludedArea". Actually FFAddExcludedArea do not exist in the dll.

This is not working on Win7 32bit. It produces an empty 0KB file. :graduated: I think it works okay on WinXP, because I tried it out on my work computer earlier today, and I didn't notice any problems then.

Odd. Will have to find some time to experiment that then. Can you tell if it works for JPG on the same computer where it fails for BMP ? As BMP is a very old and basic format, it would be surprising that this format is not supported on new OS...

Any additionnal hint is welcome.

Oh, and that FFShowPixels link never worked for me either. Apparently I don't have permission to download the file.

A shame. Looks like we have to bug Autoit' staff to "validate" this download. Despite several months delay, it seems like they didn't have a look...

Hello FastFrench,

it does not work for me , the function FFnearestSpot - it finds the color outside my area and is then TRUE, what i no want. i mean the "actions folder" does not correctly work.

#include "FastFind.au3"
#include <Array.au3>
 
HotKeySet ( "{NUMPAD1}" , "start" )
 
While 1
    Sleep(300)
WEnd
Func start()
While 1
 
$Basis_oben_links = DllCall($FFDllHandle, "int", "FFGetPixel", "int", 662, "int", 62, "int",$FFLastSnap)
If $Basis_oben_links[0] = 3061969 Then
  Do
   MouseClick ("left",662,148,1,1)
   $FFLastSnap = DllCall($FFDllHandle, "int", "SnapShot", "int", 0, "int", 0, "int", 0, "int", 0, "int", 0)
   $Schwarzesfeld_p1 = DllCall($FFDllHandle, "int", "FFGetPixel", "int", 395, "int", 15, "int",$FFLastSnap)
  Until $Schwarzesfeld_p1[0]  <> 0
  ExitLoop
Endif
$Basis_unten_rechts = DllCall($FFDllHandle, "int", "FFGetPixel", "int", 749, "int", 149, "int",$FFLastSnap)
If $Basis_unten_rechts[0] = 3061969 Then
  Do
   MouseClick ("left",662,148,1,1)
   $FFLastSnap = DllCall($FFDllHandle, "int", "SnapShot", "int", 0, "int", 0, "int", 0, "int", 0, "int", 0)
   $Schwarzesfeld_p2 = DllCall($FFDllHandle, "int", "FFGetPixel", "int", 793, "int", 83, "int",$FFLastSnap)
  Until $Schwarzesfeld_p2[0]  <> 0
  ExitLoop
Endif
WEnd
 
While 1
 
$Object1 = FFNearestSpot(5, 1, 397, 287, 0x687162 , 1 ,false)
If IsArray($Object21) = True Then
  ;action
  ExitLoop
EndIf
 
$Object2 = FFNearestSpot(3, 2, 359, 309, 0x4E5E63 , 1 ,false)  
If IsArray($Object2) = True Then
 
  ;action
  ExitLoop
  EndIf
 
  $Object3 = FFNearestSpot(1, 1, 389, 263, 0x090C0B , 1 ,false)
  If IsArray($Object3) = True Then
  ;action
  ExitLoop
  EndIf
 
WEnd
 
EndFunc

same Problem

Could you give more informations please ? As you're giving 0,0,0,0 rectangle for the snapshot, it's full window. And as you never give any Window handle, you're presumaly working full screen. So I don't understand what you mean with "outside my area", where your area is the full screen...

By the way, why do you use direct dllcall ? I suggest you experiment first with autoit wrapper functions, it would avoid some common errors and simplify the code.

For instance, your first call to :

$Basis_oben_links = DllCall($FFDllHandle, "int", "FFGetPixel", "int", 662, "int", 62, "int",$FFLastSnap)

will fail, as you have no SnapShot done at that step.

I've uploaded an fixed version 1.8

Edited by FastFrench
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...