English|Deutsch
Subscribe Ranorex Announcements Feed Ranorex LinkedIn Ranorex twitter Ranorex Facebook

Image Recognition

Use the Ranorex image processing engine to search for images or image patterns for validation or automation purposes.

Image-Based Automation with Ranorex Recorder

Ranorex Recorder provides an optional way to capture image related mouse actions. To activate image based recording, simply check the 'Image-Based' checkbox in the Recorder's toolbar during a recording session. Read more...

How to do image based automation

If Ranorex is not able to clearly identify some of your GUI elements, it may be helpful to automate them using the implicit image search mechanism of the 'Click' method.

C#

// Create bitmap to search for
// within application form and
// click it
Bitmap bmp = Ranorex.Imaging.Load(
                       @"..\..\Green Sea Turtle Small.bmp");        	
// Performs a right click on the image found
// within the application window based on
// the image location
myRepo.WinFormsApp.Self.Click(MouseButtons.Right,bmp);

// You can also search for images that are slightly different to the
// loaded image by specifying the minimum Similarity for a match (95% = 0.95).
myRepo.WinFormsApp.Self.Click(new Location(bmp, new Imaging.FindOptions(0.95)));
        	
// OR Set the default Similarity value for all following image operations
Imaging.FindOptions.Default.Similarity = 0.95;
myRepo.WinFormsApp.Self.Click(bmp);
        	
Report.Success("Image found and clicked successfully");

VB.NET

' Create bitmap to search for
' within application form and
' click it
Dim bmp As Bitmap = Ranorex.Imaging.Load("..\..\Green Sea Turtle Small.bmp")
' Performs a right click on the image found
' within the application window based 
' on the image location
myRepo.WinFormsApp.Self.Click(MouseButtons.Right, bmp)

' You can also search for images that are slightly different to the
' loaded image by specifying the minimum Similarity for a match (95% = 0.95).
myRepo.WinFormsApp.Self.Click(new Location(bmp, new Imaging.FindOptions(0.95)))
        	
' OR Set the default Similarity value for all following image operations
Imaging.FindOptions.Default.Similarity = 0.95
myRepo.WinFormsApp.Self.Click(bmp)

Report.Success("Image displayed successfully")

Python

# Create bitmap to search for
# within application form and
# click it
bmp = Ranorex.Imaging.Load(@"..\..\Green Sea Turtle Small.bmp")
# Performs a right click on the image found
# within the application window based on
# the image location
myRepo.WinFormsApp.Self.Click(MouseButtons.Right, bmp)
# You can also search for images that are slightly different to the
# loaded image by specifying the minimum Similarity for a match (95% = 0.95).
myRepo.WinFormsApp.Self.Click(Location(bmp, Imaging.FindOptions(0.95)))
# OR Set the default Similarity value for all following image operations
Imaging.FindOptions.Default.Similarity = 0.95
myRepo.WinFormsApp.Self.Click(bmp)
Report.Success("Image found and clicked successfully")

How to find and compare images

To compare an image simply search for it within an existing Ranorex element using the 'Contains' method.

C#

// Create bitmap
Bitmap bmp = Ranorex.Imaging.Load(
                       @"..\..\Green Sea Turtle Small.bmp");        	
        	   	
// Search for it within the application window
if (Ranorex.Imaging.Contains(myRepo.WinFormsApp.Self,bmp) == true)
{
  Report.Success("Image found within WinForms application");
}

VB.NET

' Create bitmap
Dim bmp As Bitmap = Ranorex.Imaging.Load("..\..\Green Sea Turtle Small.bmp")
' Search for it within the application window
If Imaging.Contains(myRepo.WinFormsApp.Self,bmp Then
  Report.Success("Image found within WinForms application")
End If
  

Python


# Create bitmap
bmp = Ranorex.Imaging.Load(@"..\..\Green Sea Turtle Small.bmp")
# Search for it within the application window
if Ranorex.Imaging.Contains(myRepo.WinFormsApp.Self, bmp) == True:
    Report.Success("Image found within WinForms application")

Note: Both examples load an uncompressed file (BMP or PNG format) in order to carry out a one-to-one comparison. Use the FindOptions class to configure similarity, preprocessing and other search settings.