Sign in to follow this  
Followers 0
Smokie

Search image or pixel inside image

10 posts in this topic

Hi. I saw some UDFs about image search inside another image and also pixel search, but the problem is that i also need toolerance for imagesearch or shade variation for pixel, because otherwise they can't find it. Any ideas, please please please I am desperate!

Share this post


Link to post
Share on other sites



I don't quite understand, the Imagesearch function and PixelSearch do exactly what you're asking.

What are you trying to automate?

1 person likes this

Share this post


Link to post
Share on other sites

Any ideas, please please please I am desperate!

What's on fire? ;)

Do you seriously think people can help you when you are this vague?
So, when you want us to see whether we can help, you better start giving all details of what you want to do and, more importantly, what you already have tried.

Jos

Jos

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Sorry, i got caught in my own ideas :). I want to do an ImageSearch Or PixelSearch inside another image file or hBitmap with tolerance/shade-variation. I already found theese libraries to search for bitmaps inside another memory bitmaps, but they won't work all the time:

And->

But i also need the tolerance parameter for ImageSearch or the shade-variation for PixelSearch. When I use the normal ImageSearch UDF for the screen it only finds the image if I set the tolerance >=32.

While 1
   $x=0
   $y=0

   $pos = ImageSearch("test.bmp", 0, $x, $y, 32)
   If Not @error Then
      MouseClick("left", $pos[0], $pos[1])
      sleep(2000)
   EndIf
WEnd

This is what I have tried with BmpSearch on an hBitmap ->

; Initialize GDI+ library
_GDIPlus_Startup()

;Get the hBitmap of the image i want to search for
$Bitmap = _GDIPlus_BitmapCreateFromFile("test.bmp")
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($Bitmap) 

;Doing the actual window capture and saving it inside $hBMP
$iWidth = _WinAPI_GetWindowWidth($browser) ; $browser = the handle of the window which I am capturing
$iHeight = _WinAPI_GetWindowHeight($browser)
$hDDC = _WinAPI_GetDC($browser)
$hCDC = _WinAPI_CreateCompatibleDC($hDDC)
$hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iWidth, $iHeight)
_WinAPI_SelectObject($hCDC, $hBMP)

DllCall("User32.dll", "int", "PrintWindow", "hwnd", $browser, "hwnd", $hCDC, "int", 0)

;Searching for the image
$pos = _BmpSearch($hBMP, $hBitmap)
_ArrayDisplay($pos)

;delete resources
 _WinAPI_ReleaseDC($browser, $hDDC)
_WinAPI_DeleteDC($hCDC)
_WinAPI_DeleteObject($hBMP)
_GDIPlus_Shutdown()

Any idea how to add tolerance to these functions?

Edited by Smokie

Share this post


Link to post
Share on other sites

You can use GDIPlus _GDIPlus_BitmapGetPixel to get the pixel color in a memory object. I think ImageSearchDLL.dll has a function that lets you search in hBitmap (Like ImageSearchEx instead of just ImageSearch. I can't confirm this, I just think I saw something about this)

Look at the _GDIPlus_BitmapGetPixel in the help file, and you could do your own shade variation by subtracting/adding your tolerance to the color to find

It would look something like

$pixel_color = Hex(_GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY), 8)
        If ($pixel_color < Hex($color_to_find + $color_tolerance, 8) and $pixel_color > Hex($color_to_find - $color_tolerance, 8)) Then

(I think my math is right on that, you might want to double check that)

1 person likes this

Share this post


Link to post
Share on other sites

Thanks! I will give it a shot:D

Share this post


Link to post
Share on other sites

Just a heads up, _GDIPlus_BitmapGetPixel returns the alpha channel too (the transparency) so it would be formatted 0xFF000000 and 0x00000000

1 person likes this

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Ok so what i have in mind for the pixel search is : capture  the hBMP, iterate through its pixels and see if any of them is in that tolerance range. What about the transparency?

Edited by Smokie

Share this post


Link to post
Share on other sites

If the color you're looking for is red

$color_to_find = 0xFFFF0000

0xFF = no transparency, FF0000 = Red

1 person likes this

Share this post


Link to post
Share on other sites

I love you man! :drool:

Share this post


Link to post
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
Sign in to follow this  
Followers 0