Sign in to follow this  
Followers 0
sunburn

Syntax advice for "find Bmp in Bmp" example script

7 posts in this topic

Appologies in advance as I'm unsure if this is the correct place as I need general help in applying this example script....

http://www.autoitscript.com/forum/index.php?showtopic=66545

So if I need to move it no problem, just let me know where I'd get the best exposure for everyone.

In essence I have a series of bitmaps Im trying to compare to see if any are a match then use them to replicate the code needed for the input later in the script. I've attached several bitmaps to see if anyone can get them to work (one of the character 1 which should be false, one of the character 5, which should be true, and one of the character 3 which should be false).

I have called this function by doing this

$image1 = C:\temp\six control codes.bmp

$image2 = C:\temp\control code 3.bmp ; or "control code 5.bmp" or "control code 1.bmp"

result = findbmp($Image1, $image2, true) ; I have also tried sending "1" and "3" in place of the "true

For ....3.bmp the results I get are " True, 1, 0, -18, 13, 19, 2, 4" and @error =0

For ....1.bmp the results I get are " True, 4, 156, -8, 8, 19, 4, 4" and @error =0

For ....5.bmp the results I get are " True, 1, 0, -18, 13, 19, 5, 4" and @error =0

Again there are many new concepts for me here, but after battling through the script, I thought I would get False for the 1 and 3?

If anyone could give these a try these bitmaps and and tell me the proper syntax used to call the .bmp's (so that I get the expected falses) It would be greatly appreciated. This is such a useful script, a little help and explanation would be greatly appreciated by many.

Control_Code_1.bmp

Control_Code_3.bmp

Control_code_5.bmp

six_control_codes.bmp

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Correct syntax

findBMP($Image1,$Image2,$c24RGBFullMatch)
findBMP($Image1,$Image2,$c24RGBPartialMatch)
findBMP($Image1,$Image2,$c16RGBFullMatch)
findBMP($Image1,$Image2,$c16RGBPartialMatch)

Small attention point is in the code: It doesn't return true or false based on if it has found the picture.

It depends on the other values returned.

If just 1 line of the picture matches it returns true.

I think an enhancement could be to add an if statement in the findBMP.

if $matchedLines=1 then $bMatchPossible=False
(but on the other hand if the picture is 1 line high it also returns a false negative).

The returned values are

$bMatchPossible = Could a match be possible

$matchedLines = The number of matched lines (if its 1 previous returnvalue probably better to set it at False

$foundAtLeft

$foundAtTop

$bmp2width

$BMP2Height

$HighestMatchingLines

$bestMatchLine

Edited by junkew

Share this post


Link to post
Share on other sites

Outstanding! That is exactly where I was getting lost. Additionally, the BMP's I was using were taken by a non auto it program which was messing things up as well. For others with the same problem, use _ScreenCapture to store your images first then you can play with them.

I think that little block might be useful in your "example script" post. I'd repost it, but I'm not sure if it is my place. Thanks for the continued intrest in helping beginners!

For others who might be looking for different solutions:

I played around with some other options and found the _imagesearch function also located in the example scripts as extremely useful and more applicable to what I'm doing.

_imagesearch

Now that I'm getting positive results, here comes the fun part of applying it.

Share this post


Link to post
Share on other sites

I just think its a bug in my function. A bitmap is a bitmap and if you can load it with GDI plus it should be possible to have a non autoit picture compared to a screencapture taken by autoit.

So far I have seen 2 color pictures are a pain due to padding and alignment of bytes. Its safer to have the pictures aligned on a 24 bits boundary.

I will check the bmps used in this post and add them to the original example post and enhance the code further.

Share this post


Link to post
Share on other sites

I don't exactly whats causing the problem but it looks a combination of black characters and stringinstr, stringmid functions.

Black character = 0x00 which is also a string end in C/C++

When I change the black character (with GIMP) to another color (in both pictures) it starts working.

When I debug the function with the black characters the offset calculation starts mis behaving.

Even when changing the 2 pictures to only have number 5 in them it doesn't work

Will further debug and hopefully see the glitch in the code.

six_control_codes2.bmp

Control_code_5_2.bmp

Share this post


Link to post
Share on other sites

change a 0 to 2 (small terrible bug to find took me hours.)

$iPos = StringInStr($BMP1Data, $searchFor,0,1,$iPos)

should become

$iPos = StringInStr($BMP1Data, $searchFor,2,1,$iPos)

Will fix this and cleanup the original thread with the samplescript

http://www.autoitscript.com/forum/index.php?showtopic=66545

Works now correct on black and white pictures also (Especially black 0x00 was hard to fix)

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