Jump to content

Image Search Library


kangkeng
 Share

Recommended Posts

It's working here. Something might be blocking the script from accessing the dll file. Are you running on a restricted user account by any chance?

Just to make sure, this is what I was using:

#include <array.au3>

$left = 0
$top = 0
$right = @desktopwidth
$bottom = @DesktopHeight

$file = "user_green.bmp"
$findimage = "*" & "transblack" & " " & "*" & 30 & " " & $file

$test = _ImageSearchArea($findimage, 0, $left, $top, $right, $bottom, $left, $top, 10)

Func _ImageSearchArea($findImage, $resultPosition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $tolerance, $transparency = 0)
    ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
    If not ($transparency = 0) Then $findImage = "*" & $transparency & " " & $findImage
    If $tolerance > 0 Then $findImage = "*" & $tolerance & " " & $findImage
    MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @LF & 'Before Call') ;### Debug MSGBOX
    Local $result = DllCall("ImageSearchDLL.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage)
    if isarray($result) then _arraydisplay($result)
    Local $err = @error
    MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @LF & 'After Call') ;### Debug MSGBOX
    If $err > 0 Then
        MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @LF & '$err' & @LF & @LF & 'Return:' & @LF & $err) ;### Debug MSGBOX
        Return 0
    EndIf
    ; If error exit
    If $result[0] = "0" Then
        Return 0
    EndIf

    ; Otherwise get the x,y location of the match and the size of the image to
    ; compute the centre of search
    Local $array = StringSplit($result[0], "|")

    $x = Int(Number($array[2]))
    $y = Int(Number($array[3]))
    If $resultPosition = 1 Then
        $x = $x + Int(Number($array[4]) / 2)
        $y = $y + Int(Number($array[5]) / 2)
    EndIf
    Return 1
EndFunc   ;==>_ImageSearchArea

The file "user_green.bmp" is from http://www.autoitscript.com/forum/index.php?app=core&module=attach&section=attach&attach_id=33100

Link to comment
Share on other sites

  • 3 weeks later...

Now I need some help as well.

Here's what I got so far:

#include <constants.au3>
#include <WinAPI.au3>
#include <array.au3>

$HBMP = _WinAPI_LoadImage(0, @ScriptDir & '\temp.bmp', $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE)
MsgBox(0, "hbmp", $HBMP)
$result = DllCall("ImageSearchDLL.dll", "str", "ImageSearch", "int", 0, "int", 0, "int", @DesktopWidth, "int", @DesktopHeight, "str", @ScriptDir & "\templates\example.bmp", "ptr", $HBMP)
If IsArray($result) Then
    _ArrayDisplay($result, "result")
Else
    MsgBox(0, "result", $result)
EndIf

temp.bmp can be accessed and opened, example.bmp can be accessed and opened, yet ImagesearchDLL.dll returns 0. Why's that? ImageSearchDLL.dll is ProgAndy's HBITMAP version from here:

Any assistance is greatly appreciated.

Link to comment
Share on other sites

At the top of your script together with the other #AutoIt3Wrapper statements. If you are unsure Press Tools>Compile (or CTRL+F7) from SciTE, change the radio to "Use X86 version" and then press "Save Only".

Link to comment
Share on other sites

Hey guys,

I like this tool, i am using it for hours now, trying to make a script.

But i figured out this tool only returns 1 or 0.

I know that pixelsearch will return the position of the pixel.

So how can i make this tool to return the X,Y position of the picture?

I think i can try to scan the whole screen bit by bit until it reached the picture, but i dont know if it drains too much cpu, anyway ill try that until someone can tell me a better way.

Thanks in advance!

Link to comment
Share on other sites

Hmmm i looked at the readme a few times and tried some stuff..

and now i came to the conclusion that i dont get it at all..

lol i think it wont work on vista?

ive read some posts about that but no1 really answered

hope some1 can answer coz im too tired to figure it outXD

Link to comment
Share on other sites

Hmmm i looked at the readme a few times and tried some stuff..

and now i came to the conclusion that i dont get it at all..

lol i think it wont work on vista?

I'm getting @error=3 when the DLL is called. According to the API docs, this means "function not found". However, looking at the binary, the function name "ImageSearch" seems to be there.

Maybe the DLL needs to be rebuilt. Does anyone else have it working on a Windows 7 machine? This is an x64 box but it's configured to run with x86 AutoIt. When running 64-bit, @error=1 instead.

Link to comment
Share on other sites

I'm getting @error=3 when the DLL is called. According to the API docs, this means "function not found". However, looking at the binary, the function name "ImageSearch" seems to be there.

Maybe the DLL needs to be rebuilt. Does anyone else have it working on a Windows 7 machine? This is an x64 box but it's configured to run with x86 AutoIt. When running 64-bit, @error=1 instead.

Ooh nevermind. It seems to work with the DLL provided in Maybe the ZIP I downloaded had an old DLL build. Perhaps the ZIP could be reuploaded with the latest builds?
Link to comment
Share on other sites

This app is a real pain when you try to use it.

Does someone have a working imagesearch on Win7 ?

I am not sure which version of the dll i should use and where to put it ?

$result contains nothing neither 0 or 1, but void.

The code I use

ImageSearch demo

#AutoIt3Wrapper_UseX64=n

#include <Array.au3>
#include <ImageSearch.au3>

;
; Demo on the functions of ImageSearch
;

MsgBox(0, "MSG", "You need to have an image visible on your screen")

$x1 = 0
$y1 = 0
Global $result


MsgBox(0, "MSG", "Search for image the top left corner in a 750x750 box")

; find image if it is in the top left corner of screen
$result = _ImageSearchArea(@ScriptDir &"\Poubelle.bmp", 1,0,0,750,750, $x1, $y1, 0)

If $result = 1 Then
    MouseMove($x1, $y1, 3)
    MsgBox(0, "Found", "Found the image in top left corner")
Else
    MsgBox(0, "Néant", "Je n'ai pas trouvé l'image")
EndIf

ImagesearchArea (part of Imagesearch.au3)

Func _ImageSearchArea($findImage, $resultPosition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $tolerance)
    MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
    If $tolerance > 0 Then $findImage = "*" & $tolerance & " " & $findImage

    $result = DllCall(@ScriptDir &"\ImageSearchDLL.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage)


    ; If error exit
    If $result = "0" Then
    Return 0
    EndIf

    MsgBox(0,"Result","" & $result)

    ; Otherwise get the x,y location of the match and the size of the image to
    ; compute the centre of search
    $array = StringSplit($result, "|")

    $x = Int(Number($array[2]))
    $y = Int(Number($array[3]))
    If $resultPosition = 1 Then
        $x = $x + Int(Number($array[4]) / 2)
        $y = $y + Int(Number($array[5]) / 2)
    EndIf
    Return 1
Edited by armenfrast
Link to comment
Share on other sites

This app is a real pain when you try to use it.

Does someone have a working imagesearch on Win7 ?

I am not sure which version of the dll i should use and where to put it ?

Yes. Did you read the last post before yours and try the DLL at that link? It works fine for me on Win 7.
Link to comment
Share on other sites

  • 3 weeks later...

Hi all, i am experimenting with the above version since i want to use the hbitmap version.

I am on Win7 64 and already have the 'conventional' imagesearch working fine.

But when i try to use this i am out of luck.

Anyone has a 'compatible' package of ImageSearch.au3 and corresponding 32bit Dlls that can use hbitmaps ?

That would be great since i cannot compile my own version of proper dlls. too much C for me.

I tried picking up all the scatered bits of .au3 files and Dlls here all over the place but thats realy a bit 'unsortet'.

Link to comment
Share on other sites

  • 4 months later...

I finally managed to compile the dll on VS 2005 Express.

I used the source from ProgAndy with his hbitmap mod.

  • Fixed the memory leak (@ProgAndy line 1121 DeleteDC(xdc) not sdc :) )
  • modified the behaviour of the search so that the bitmap is searched from start to end and all the match coordinates found in the bitmap are returned in the outputstring.
The string looks like this: "123|65#543|67#874|98#...."

Also i changed the ImageSearch.au3 to parse the string into a 2dimensional array and this array is returned from ImageSearchArea.

Its all in the zip file. Its works for me on win7 64bit with running x86 autoit.exe

Im quite a newb in C++ so i didnt know how to implement a proper error checking on the return string, so i simply defined

char answer[500000] = "" ;

I think 500k byte for the string are enough for the most purposes :mellow:

Maybe if you use a small pixel bitmap for searching and get lots of results (>50000), the dll may crash, so try to search for more unique patterns.

Transparency works with pngs, black pixel and option: *TransBlack

I didnt test the toleance option with the new mods but they *should* work.

The autoit UDF was wildly changed and is a bit messy, but its working for my purposes.

ImageSearchDLL_2dimArray_leak_fixed.rar

Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite
Link to comment
Share on other sites

  • 2 months later...

I finally managed to compile the dll on VS 2005 Express.

I used the source from ProgAndy with his hbitmap mod.

  • Fixed the memory leak (@ProgAndy line 1121 DeleteDC(xdc) not sdc :D )
  • modified the behaviour of the search so that the bitmap is searched from start to end and all the match coordinates found in the bitmap are returned in the outputstring.
The string looks like this: "123|65#543|67#874|98#...."

Also i changed the ImageSearch.au3 to parse the string into a 2dimensional array and this array is returned from ImageSearchArea.

Qsek, any info how to use it?

i tried whole desktop :

$res = _imagesearcharea(@ScriptDir & '/img/img1.png',0, 0, @DesktopWidth, @DesktopHeight)
    MsgBox('','asd',$res,1)
    _ArrayDisplay($res)

$res return always 0

I have got working version with another DLL and au3 include(without transparency), but i dont know where im wrong.

But your version looks promising, with array and transparency.

Any hints?

Link to comment
Share on other sites

  • 4 weeks later...

First i dont know what png you are using and if there is a match on your desktop.

But i suggest that you look in the imagesearch.au3 and uncomment line 43 because $result is the DLL return Array and will give you more information about whats going on.

And you could put in some tolerance:

$res = _imagesearcharea(@ScriptDir &'/img/img1.png',0, 0, @DesktopWidth, @DesktopHeight, 40)

Also read http://www.autohotkey.com/docs/commands/ImageSearch.htm for the right usage of the options.

Like i said, my udf was changed only to made it work for my application.

Edited by qsek
Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite
Link to comment
Share on other sites

  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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