Jump to content
DuByD

Findbitmaptol across different resolutions

Recommended Posts

Hello all, I am new to Scar and these forums. I am trying to automate something using the findbitmap feature and I have no problems getting it to work for the most part. My problem comes in when the window size is changed and everything in that window is scaled up or down or if being run on a different system with a different resolution setup. I have heard of posts mentioning a way around this and would like to investigate it further before trying to go a colors route instead of the bitmap route. For my test, I captured a bitmap from the active client abd created the img as bmp1. Ran the program and it finds it without issue. I them changed the size of the window (which scales contents) and am no longet able to find the bitmap. My next thought was basing all of my images from a set client width and scaling from there. so I tried using the bitmap resize feature with no results on that either... Here was my testing script. The idea was scaling the images but it could not be precise as the resize function doesn't take a double. I'm sure there is a better way... :) Need to adjust basewith to the width of the client when image was taken. I guess the same test could be accomplished using a picture viewer and zooming the pic in and out...

 

program new;

 

//{.include OpenClose.scar}

var BMP : TSCARBitmap;

var x, y, w, h, a, b : integer;

var basewidth, currentwidth : integer;

Var ratio : double;

 

 

begin

GetClient.Activate;

 

//image taken from client at this width

basewidth := 900;

 

//Current width of client

GetBoxSize(GetClient.ImageArea, w, h);

currentwidth := w;

ratio := currentwidth/basewidth;

writeln(ratio);

 

 

// insert image string here....

BMP := TSCARBitmap.Create('something');

a := BMP.Width;

b := BMP.Height;

a := Trunc(a*ratio);

b := Trunc(b*ratio);

BMP.Resize(a,b);

 

if(FindBitmapTol(x, y, BMP, 0, 0, w - 1, h - 1,100))then

begin

 

writeLn('found bitmap at ' + intToStr(x) + ',' + intToStr(y));

 

end

else

writeLn('missing bitmap');

end.

Edited by DuByD
Link to comment
Share on other sites

First of, FindBitmapTol is really sensitive to object differences (to sensitive if you ask me). Rescaling with the algorithm that SCAR provides will not really work with FindBitmap*. In SCAR images are rescaled with a Nearest neighbor algorithm. When downscaling, it will simply discard much data, when upscaling you literally upscale EACH pixel, or it's neighbor pixel - there is not anti-aliasing filter.

 

So in other words you would need to create a new FindBitmap, or implement a better down-sampling algorithm (supersampling).

Edited by slacky
Link to comment
Share on other sites

Would there be a better way to handle looking for an image that may be one inch in one situation and say a half inch in another? Wanting to get a script to work with a game across multiple computers and window sizes... It works if I do not change the window size or anything but if I open up multiple instances of the game, in order to see them all on my screen, i shrink the window size. This is not a precise method or to a set size. Everything inside the window gets scaled up or down depending on how large or small you make it. I find myself having to recreate the images every time I change the windows borders. Was hoping there was an easy solution out there :)

Link to comment
Share on other sites

You cant measure anything on the monitor in inches as we might (and probably) have different resolution, measure in pixels. As for your question:

DuByD said: "Would there be a better way to handle looking for an image ..."

- I am afraid not.

Edited by slacky
Link to comment
Share on other sites

That is awesome Freddy! :D What algorithm did you go with?

 

You should write it down in http://forums.scar-divi.com/announcements/2278-scar-divi-3-39-beta.html ! =)

 

@DuByD : There you might just have your answer. Download the latest beta, create the bitmap at the maximum size you might use.

 

Actually, now that I think about it, it was added in 3.38, not 3.39. As TSCARBitmap.ResizeEx, where you can set Antialiased to true to activate supersampling.

Link to comment
Share on other sites

This is great news but my logic must be flawed... I am just trying this out with android running in vbox at the moment... I am looking for the lock on the screen to grab and slide. I made my vbox windows client area 1020px wide. I then grabbed a bitmap of the lock picture as seen in the code. Even without resizing this window I cannot find the image. Cant find it if I do resize it... Am i missing something? Here is the code:

 

program new;

 

var BMP1 : TSCARBitmap;

var x, y, w, h, a, b : integer;

var basewidth, currentwidth : integer;

Var ratio : double;

 

begin

 

BMP1 := TSCARBitmap.Create('deNqtmflzFNe1x/Mn9d49m2afHq0eaXofLSOwC' +

'X7xS2wcPwzOK+LY5cQWMdgYRBIZEIsrbAV2khfHC3jHa+yHl0rZzyaEYAmEhVg' +

'kBM4P73tuL5rRYkE5Vd+a6h519/3MOd97zr0t7gfpH8heinM0CAeSl8SB4GiKk' +

'9LcjOK14JTHn5yE7GQ4O8MZGcnKaG5Orem8k+WcAueUOUfn6DgvOCXZKUM8vrS' +

'KvJlXbV3zypDqlWWPvhfZBTI7Fdwyu71JEQ9gIIyuOprmpVQvLdspzgabpjnJg' +

'MckHtXNKbXSAp4MkBqfjNFVp6wxyc4iQy8qn0d2NJFR8U5MrbVot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S3PaYSwexGtuU1eh2zYNaicRmclp9JMqU2apZHardJVGOiEcxclI1Ax6xCp6' +

'CRipqhk7GMyiqkoENZpFtjctBgw5DrbLPxv2v4LdL9urSzws9x15wTEgddAD/G' +

'K0KUsZ4BELKgo03srJRVI0c+z6LQKmIlaHLhs5VSxwCWM3TAQMQjLnZqoQA80Q' +

'86FZBUhiGFUyuEInJbPV/lM/DVJToBQhbfNJEQ8Si4wIgOUSvwtSdW+y9xOJiQ' +

'9Cnv8bQGmU18NidktXBG60yC47KZrpkZGnQ7gxfpXLUwJMP4wPlSP5wPQWukue' +

'6y1wVx0zL8UgsjD6PZATv7uhdokM8dH21hetOit1psUrzXSQLZUDFB0WyoFJwS' +

'sLcEKW59zbdea6SI4yFPP5plQoLJIQ8IsuyzxPlly1f2wSzLeRJCN1poSEmPJv' +

'4oplXmZ8ZT5G9RJrzcxAfaNFMAaY74JHMwOFL8QhmMDtof8pGZ/linqlScORqR' +

'jMLQVUnFTD7eOJBsgoUjaUNM+9Fk9+YGhkaj/2LVVau/Rnqm0e1S9RMfZ5KRu4' +

'paqYeVAm6WEegVJrvOtet0w9fGkYJisPSPGbZ/6WqNfdiCjwq3dgK8wjdyE5O6' +

'EkJPUm+muYqcb4nLRk5hV4S4rMUlKBqmQdJpUAKPDw/X3wIw0f5ihYSUb5Q+uz' +

'OaIqpbCEtsMtwL0b3Dcz1pEiwU0UDm8j8zOYX4lYKeGiUIqnChqPjPCFV9cDAP' +

'WWxyvJVDfwshHNKCsumbKAUt1MBNNsglbV1+Fk22xWjneuOBySBkuARGQ9rZ6j' +

'VMHlerupIIt9T5Hp8HkgPkFCRethxhSlyV4gUTHBzQfEhqvbg1OzUzIpi3IbRF' +

'xEFClUoq1Z1tZoVjTxhVDINynKVEgMosmM9gJnHw04lH8ZegNQkZBA8Xf8PVHe' +

'EJA==');

 

GetClient.Activate;

basewidth := 1020;

GetBoxSize(GetClient.ImageArea, w, h);

currentwidth := w;

ratio := currentwidth/basewidth;

writeln(ratio);

a := BMP1.Width;

b := BMP1.Height;

a := Trunc(a*ratio);

b := Trunc(b*ratio);

BMP1.ResizeEx(a,b,True);

BMP1.Resize(a,b);

 

if(FindBitmapTol(x, y, BMP1, 0, 0, w - 1, h - 1,100))then

begin

writeLn('found bitmap at ' + intToStr(x) + ',' + intToStr(y));

end

else

writeLn('missing bitmap');DebugBitMap(BMP1);

Debugbitmap(BMP1);

end.

Link to comment
Share on other sites

Put your code in the

-containers. 

 

Your math is fine, but:

 

[font=Courier New]>>> BMP1.ResizeEx(a,b,True);[/font]

[font=Courier New]>>> BMP1.Resize(a,b);[/font]

You only need:

[font=Courier New]>>> BMP1.ResizeEx(a,b,True);[/font]'

 

But, that is not the problem. After some rough testing with scaling and searching, I see that SCARs "FindBitmapTol" is just way to sensitive. You might be more lucky if you crop the image down a little (less to work with when resizing, and searching often results in better result). I tested with your image, loaded the original in to an imageviewer. I then loaded it in to scar, croped it down (to image shown below), and searched: I found it some times when resizing, while other times, not that lucky. Also: You might have better luck with [color=#800000][font=Courier New]Round()[/font][/color] then with [color=#800000][font=Courier New]Trunc()[/font][/color] in this case. You could try to check trough both possibilities [color=#800000][font=Courier New]Ceil()[/font][/color] (round up) and [color=#800000][font=Courier New]Floor()[/font][/color]/[color=#800000][font=Courier New]Trunc()[/font][/color] (round down), that might just be what you need - But as I said: Bitmap-searching in SCAR is SUPER-sensitive.

 

delete_me.png

 

And when images get that big.. Load am from your computer..

[font=Courier New]>>> Bmp1 := TSCARBitmap.Create('');

>>> BMP1.LoadFromPng('some_img.png')[/font]

Edited by slacky
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...