Imaging Capabilities and the API

Ask general questions here.
User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Imaging Capabilities and the API

Post by Aracknid » Tue Feb 28, 2012 4:06 pm

I was watching the screencast in your support section called "How and When to Use the Imaging Capabilities", and I'd like to do something like this in my own scripts. The problem is I'm doing all my coding in VS2010 using the Ranorex API. I'm also not using any Ranorex repository, and assume this is required for storing the images? And finally, I've only got a license for the developer version, so I don't have the ability to use the Ranorex Recorder.

- Can I still do these sorts of tests? If so can you point me in the right direction?

- Do I need to use a repository for storing the images? If so, how do you do that in a multi-developer environment so that the repository is accessable to everyone? Is it good practice to store the repo in TFS?

- If I need a repository, how can I view what's in it?

Thanks,

Aracknid

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: Imaging Capabilities and the API

Post by artur_gadomski » Wed Feb 29, 2012 9:24 am

As far as the repository is concerned we store it Subversion just like all the other files. We have it added to Solution and set VS to open it using Spy. And here I think is another answer. Spy works in 2 modes, live and repository, you can create and edit repositories in Spy.

No idea about images, we do have one image comparison but we just grab 2 images from report rather than comparing screenshot to prepared image.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Imaging Capabilities and the API

Post by Support Team » Wed Feb 29, 2012 11:54 am

Hi,

following chapter of our user guide will show you how to perform code based "image based automation":
How to do image based automation

You can use Ranorex Spy to create screen shot files holding the controls you want to use within image base automation.

Regards,
Tobias
Ranorex Support Team

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: Imaging Capabilities and the API

Post by Aracknid » Tue Mar 06, 2012 3:38 pm

OK, Thanks. I've been able to write code to click on something based on an image, and also to comapre a known element to an image.

I noticed that the Imaging class had many methods and properties, and I saw Find and Findsingle, etc...

Does this mean I can find an element based on an image and not an Xpath? If so, can you provide some sample code (VB please) on how to do this. I tried but was unsuccessful.

For example, normally I might find a button like this:
Dim oButton as Ranorex.Button
oButton = oForm.Find(XPath)
But if I have no Xpath because the control is not supported and not exposing anything helpful to find it, can I do something like this?
Dim oButton as Ranorex.Button
Dim oImage as Bitmap

oImage = Ranorex.Imaging.Load(sPath)
oButton = Ranorex.Imaging.Find(oForm, oImage)
Looks like the type returned from a Find is Ranorex.Imaging.Match.... And I couldn't figure out how to use that...

Thanks,

Aracknid

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Imaging Capabilities and the API

Post by Support Team » Wed Mar 07, 2012 4:41 pm

Hi,
Aracknid wrote:But if I have no Xpath because the control is not supported and not exposing anything helpful to find it, can I do something like this?
If you search for a specific image on your form, you get the location of the found image but you don't get an element as you want. If you want to click an element on your GUI through imaged based searching, you have just to use the code which is in the link above posted by Tobias.

Regards,
Peter
Ranorex Team

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: Imaging Capabilities and the API

Post by Aracknid » Thu Mar 08, 2012 11:02 pm

Can you clarify how the Imaging.FindOptions.Similarity property works?

My issue is that I have a stored image which is small (about 11x14 pixels and as a BMP). For a reason I don't get (because nothing changed... same app version), when I compare it to a runtime grab of the element that contains this image, 1 of the pixels is shifted by 1 in all RGB colors. So the pixel was 174,194,226 RGB when I grabbed it and saved it and now it's 175,195,227 RGB. All the rest of the pixels are exact. When I try to do a Imaging.Contains it fails. So I changed the Imaging.FindOptions.Default.Similarity to 0.99 and it passed. Great.

Now the problem is when I use this same function with a different BMP file it finds the wrong image. Yes, what is found is similar, but not that similar 99% in my opinion. I was surprised it found the wrong image with a default of .99. When I changed it to 1.0 it didn't find it at all.

FYI: Im looking for an icon and a few pixels around it. The icon itself should not change, but the area around it might based on if the cell in the grid is selected, has focus, is hovered over, etc..

I read what it said in the API help file, but that didn't help me. I assumed that 99% would mean 99% of the pixels need to match for it to be considered a match. But based on the fact that it found the wrong image, I'd say that's not how it works at all. So what is it actually doing?

So, here is an example of what I'm look for and in what...

This is what I'm looking for:
task icon.JPG
And I'm looking in this Silverlight grid object:
pw.JPG
Notice that what I'm looking for is the icon and the surrounding area, which is slightly "sky blue".

What it will find with a similarity of .99 is the icon in the second row which is on a white background.


Thanks,

Aracknid.
You do not have the required permissions to view the files attached to this post.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Imaging Capabilities and the API

Post by Support Team » Mon Mar 12, 2012 2:02 pm

Aracknid wrote:I assumed that 99% would mean 99% of the pixels need to match for it to be considered a match
No, not 99% of the pixels need to match, but 99% of the color information in the image need to match. See following post for an in-depth explanation:
http://www.ranorex.com/forum/issue-with ... tml#p11032

The shift of a single pixel you described is a very small difference, since it is only a difference of 3 for a possible maximum difference of 765 (= 255+255+255) per pixel (similarity ~ 0.004 for that single pixel). And if only a single pixel is different, you further need to divide this similarity by the area of your image (width * height in pixels).

Consequently, try to use a higher similarity like 0.999999.

Regards,
Alex
Ranorex Team