Jump to content

Search image or pixel inside image


Smokie
 Share

Recommended Posts

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!

Link to comment
Share on other sites

  • Developers

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

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

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
Link to comment
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)

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