Jump to content

Screen scraping


Nine
 Share

Recommended Posts

Link to comment
Share on other sites

24 minutes ago, Nine said:

Also, corrected a small bug.  New version available.

Note (just a minor detail) : The header still indicates 2021-08-26 as the date of the last modification.

#include-once
#include <ScreenCapture.au3>

; #DESCRIPTION# =================================================================================================================
[...]
; Date ..........: 2021-08-21
; Modified ......: 2021-08-26

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

14 hours ago, Nine said:

@Chimp Yes I removed the source code from the zip file.  It is an AutoIt example, not a FreeBasic example. ;)

ok  :P

Edited by Chimp
removed joke

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

  • 4 months later...

GetWindow does not work on Chrome, you will need to use GetScreen.

The result is a GDI+ handle.  Search the forum for examples how to draw a GUI picture from GDI+.  If you have problem with this, start a new thread in "AutoIt General Help and Support" section.

Link to comment
Share on other sites

Link to comment
Share on other sites

Link to comment
Share on other sites

Really appreciate your work.

How can I take a screenshot of a window (Chromium based), but from pixel 300,80 to 950,940 using this ScreenGet ?

I was using: ScreenCapture_Capture("",$left,$top,$right,$bottom,False)

Another question: the above gives an Hbitmap, and then convert it to bitmap, and set TIFF parameters in order to increase the quality and readability of OCR. Any way I can do it using the image that your screenget file gets ?

Edited by SaeidN
Link to comment
Share on other sites

Link to comment
Share on other sites

  • 2 months later...

Thanks a ton for this! Helped me out a lot :)
Do you think there may be a way to "reverse" _GetScreen_PixelReplaceAll?
I basically want to remove all pixels but exclude a specific one, so that everything but pixels with the corresponding color will be removed. Looked at your udf couldnt get an idea to do this properly 😕

Link to comment
Share on other sites

@Patrik96Here a function that you could try.  If images are not too too big, you should get a decent response time.

Func ClearAll($nColorPreserved, $nColorClear)
  Local $iSize = $iGS_Width * $iGS_Height
  $nColorPreserved = BitOR($nColorPreserved, 0xFF000000)
  $nColorClear = BitOR($nColorClear, 0xFF000000)
  For $i = 1 To $iSize
    If DllStructGetData($tGS_Struct, "color", $i) <> $nColorPreserved Then DllStructSetData($tGS_Struct, "color", $nColorClear, $i)
  Next
EndFunc

 

Edited by Nine
Link to comment
Share on other sites

On 7/4/2022 at 10:26 PM, Nine said:

@Patrik96Here a function that you could try.  If images are not too too big, you should get a decent response time.

Func ClearAll($nColorPreserved, $nColorClear)
  Local $iSize = $iGS_Width * $iGS_Height
  $nColorPreserved = BitOR($nColorPreserved, 0xFF000000)
  $nColorClear = BitOR($nColorClear, 0xFF000000)
  For $i = 1 To $iSize
    If DllStructGetData($tGS_Struct, "color", $i) <> $nColorPreserved Then DllStructSetData($tGS_Struct, "color", $nColorClear, $i)
  Next
EndFunc

 

I'm so sorry for the very late response. Tried it today and it works like intended! Didn't think it would be such as short code^^ Learning a lot from your code. Thank you!

The only last step i need to take is to implement some kind of shade variation, because for some reason, specific GPU's appear to have slighty different pixel colors than my own GPU has. My script will run on different devices(Computer room of my fathers company). I wish there would be way to have the 100% same color on every single device. But guess looking for shade variation is the better choice 😏

Link to comment
Share on other sites

@Patrik96 Make sure you have the same settings between computers.  If one has 16 bits colors and the other one has 32, that might explain the differences.  Look also at other settings (aero, resolution, zoom, etc).  Implementing with AutoIt a shade variation on a large picture will drastically increase the response time.  It is important that you understand why there is color differences. 

Link to comment
Share on other sites

On 7/13/2022 at 3:35 AM, Nine said:

@Patrik96 Make sure you have the same settings between computers.  If one has 16 bits colors and the other one has 32, that might explain the differences.  Look also at other settings (aero, resolution, zoom, etc).  Implementing with AutoIt a shade variation on a large picture will drastically increase the response time.  It is important that you understand why there is color differences. 

We really tried everything to get the 100% exact same Pixel colors on every device. But it seems to be not possible, unless every device uses the same gpu. Tried to install fresh Windows 10 to 3 devices. 2 of them got the same graphics card, where Pixel colors were exact the same. But the third one had a different graphics card and different Pixel colors as well.
All of them used the same monitor, so i think there is no way around handling pixel variations...

The pictures it uses are about 539 x 329, which luckily isn't too big.
Do you think it would be possible to add some kind of pixel variation "detection" to _GetScreen_SearchArea without loosing too much performance?



As for _GetScreen_GetPixel($iX, $iY), i simply use the returned color with the following function:
 

;Returns 1 if pixel is within the set shade variance, 0 if it is not.
;$RBG = the color you are looking for
;$pixel = the actual color of the pixel
;$shade the ammount of variance allowed. I think its 0-255.
Func CheckColorVariation($RBG, $pixel, $shade = 0)
    $difference = 0
    $mask = BitAND($RBG, 0xff0000)
    $mask = BitShift($mask, 16)
    $pix = BitAND($pixel, 0xff0000)
    $pix = BitShift($pix, 16)
    $difference = abs($mask-$pix)
    If $difference > $shade Then
        Return 0
    EndIf

    $mask = BitAND($RBG, 0x00ff00)
    $mask = BitShift($mask, 8)
    $pix = BitAND($pixel, 0x00ff00)
    $pix = BitShift($pix, 8)
    $difference = abs($mask-$pix)
    If $difference > $shade Then
        Return 0
    EndIf


    $mask = BitAND($RBG, 0x0000ff)
    $pix = BitAND($pixel, 0x0000ff)
    $difference = abs($mask-$pix)
    If $difference > $shade Then
        Return 0
    EndIf

    Return 1
EndFunc


It works great, however i have no idea how to properly implement this function into _GetScreen_SearchArea since it returnes coordinates instead of colors.

Any idea? 😕
 

Edited by Patrik96
Link to comment
Share on other sites

  • Developers
2 hours ago, Patrik96 said:

Any idea? 😕

Maybe the annoying black background you have even when posting? (Maybe next time Past without formatting! ;)  )

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

48 minutes ago, Jos said:

Maybe the annoying black background you have even when posting? (Maybe next time Past without formatting! ;)  )

Oh lol it took me a few minutes to realize what you are talking about :D I am using the "AutoIt Dark" theme of the forums, where this is coming from i guess. Can't see the annoying black background on this theme as well. Hopefully this post doesn't include it 😏

Edit: Alright removed it, thanks for telling. It really looked weird
Edit 2: Hands up it was because of c&p from Discord where i prepared text on mobile before posting it here. So this points it pretty good:
(Maybe next time Past without formatting!  )

Edited by Patrik96
Link to comment
Share on other sites

4 hours ago, Patrik96 said:

Do you think it would be possible to add some kind of pixel variation "detection" to _GetScreen_SearchArea without loosing too much performance?

I believe that it will do impact the performance.  Since I am using my UDF and I need top performance, I am afraid I will not implement this.  Beside, if I was to implement shade variation to this particular function, I would also need to do the same for the other functions. 

Why dont you pass a parameter to your script and search for the corresponding color accordingly.  It would be very easy to implement it :

Global Const $COLOR_A = $CmdLine[1] = 1 ? 0x101010 : 0x121212

 

Edited by Nine
Link to comment
Share on other sites

  • 3 months later...

Great job Nine !

Just a note concerning "Example2", which throws a fatal error in my case :

error at line 24 ==> Subscript used on non-accessible variable.:
Local $aArea = _GetScreen_SearchArea($aPos[0]-50, $aPos[1]-50, $aPos[0]+60, $aPos[1]+60, $iColor)
Local $aArea = _GetScreen_SearchArea($aPos^ ERROR

The reason is simple : there is no bright red ($iColor = 0xFF0000) in my Scite screen, where the example is opened and run, because of this line in my SciTEUser.properties file :

#string (darker red, not the original bright one)
style.au3.7=fore:#C80000,back:#F0F4F9

As soon as I comment the string style line (#) and close/reopen Scite, then Example2 works fine because strings retrieve their bright red color 0xFF0000

Anyway, no big deal, if one day you got a major update, then you'll advise. Don't know why but it just reminded me of someone who often writes "check @error as much as you can !" . No Melba23, that's not you :D

This was pixelsearch's note concerning pixelsearch, end of transmission. :bye:

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