Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Friday, July 28, 2017 10:28:05 AM(UTC)

Nick  
Nick

Groups: Registered, Tech Support, Administrators
Posts: 161

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.html

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;
         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;
      }

File Attachment(s):
glyphs.zip (5kb) downloaded 144 time(s).

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.
LEAD Logo
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

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.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.066 seconds.