Error

# How To: Using the CorrelationCommand

#1 Posted : Friday, July 28, 2017 10:28:05 AM(UTC)

Posts: 123

Was thanked: 5 time(s) in 5 post(s)

The CorrelationCommand deterines how well two images resemble each other. For example, an image can be searched to see if it contains a smaller image. More information on the command is available in our online documentation.

Note the CorrelationCommand has its limitations: it essentially compares subsections of the image to determine the ratio of resemblance between the two. If the correlation is above the specified threshold, the correlation is marked.

The code snippet below demonstrates how to use the correlation command to determine the suit of a playing card. In this case, we're setting the maximum points to 1 because it only takes the existence of a single suit glyph for a card to be designated as that suit. Note this basic procedure isn't foolproof--only glyphs the same size and design will be detected. For example, the unique Ace of Spades won't be recognized as it's larger and more intricate, there being inconsistent with the template for it.

Code:
``````
public static string DetectCardSuit(string card)
{
RasterCodecs codecs = new RasterCodecs();
codecs.ThrowExceptionsOnInvalidImages = true;

string[] suits = new string[] { "club.png", "diamond.png", "heart.png", "spade.png" };
string suit = null;

CorrelationCommand command = new CorrelationCommand();
command.Threshold = 90;
command.XStep = 1;
command.YStep = 1;

bool found = false;

for (int i = 0; i < suits.Length; i++)
{
suit = suits[i];

AutoBinarizeCommand abc = new AutoBinarizeCommand();
abc.Run(suitImage);
abc.Run(image);

command.CorrelationImage = suitImage;
command.Run(image);

if (command.NumberOfPoints == 1)
{
found = true;
break;
}
}

return found ? Path.GetFileNameWithoutExtension(suit) : null;
}
``````

File Attachment(s):

Edited by user Monday, February 17, 2020 9:18:48 AM(UTC)  | Reason: Updating links to v20

Nick Crook
Developer Support Engineer

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.