#1
Posted
:
Friday, July 28, 2017 10:28:05 AM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 163
Was thanked: 9 time(s) in 9 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.
https://www.leadtools.com/help/leadtools/v20/dh/po/correlationcommand.htmlNote 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;
RasterImage image = codecs.Load(card);
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;
command.Points = new LeadPoint[1];
bool found = false;
for (int i = 0; i < suits.Length; i++)
{
suit = suits[i];
RasterImage suitImage = codecs.Load(suit);
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;
}
Edited by user Monday, February 17, 2020 9:18:48 AM(UTC)
| Reason: Updating links to v20
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
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.