Beispiel #1
0
        private void loadSourceCards()
        {
            using (DataTable Reader = sql.dbResult("SELECT * FROM cards"))
            {
                foreach (DataRow r in Reader.Rows)
                {
                    ReferenceCard card = new ReferenceCard();
                    card.cardId  = (String)r["id"];
                    card.name    = (String)r["Name"];
                    card.pHash   = (UInt64)r["pHash"];
                    card.dataRow = r;

                    referenceCards.Add(card);
                }
            }
        }
Beispiel #2
0
        private void matchCard()
        {
            int cardTempId = 0;

            foreach (MagicCard card in magicCards)
            {
                cardTempId++;
                // Write the image to disk to be read by the pHash library.. should really find
                // a way to pass a pointer to image data directly
                card.cardArtBitmap.Save("tempCard" + cardTempId + ".jpg", ImageFormat.Jpeg);


                // Calculate art bitmap hash
                UInt64 cardHash = 0;
                Phash.ph_dct_imagehash("tempCard" + cardTempId + ".jpg", ref cardHash);

                int           lowestHamming = int.MaxValue;
                ReferenceCard bestMatch     = null;

                foreach (ReferenceCard referenceCard in referenceCards)
                {
                    int hamming = Phash.HammingDistance(referenceCard.pHash, cardHash);
                    if (hamming < lowestHamming)
                    {
                        lowestHamming = hamming;
                        bestMatch     = referenceCard;
                    }
                }

                if (bestMatch != null)
                {
                    card.referenceCard = bestMatch;
                    //Debug.WriteLine("Highest Similarity: " + bestMatch.name + " ID: " + bestMatch.cardId.ToString());

                    Graphics g = Graphics.FromImage(cameraBitmap);
                    g.DrawString(bestMatch.name, new Font("Tahoma", 25), Brushes.Black, new PointF(card.corners[0].X - 29, card.corners[0].Y - 39));
                    g.DrawString(bestMatch.name, new Font("Tahoma", 25), Brushes.Yellow, new PointF(card.corners[0].X - 30, card.corners[0].Y - 40));
                    g.Dispose();
                }
            }
        }
Beispiel #3
0
        private void loadSourceCards()
        {
            using (DataTable Reader = sql.dbResult("SELECT * FROM cards"))
            {
                foreach (DataRow r in Reader.Rows)
                {
                    ReferenceCard card = new ReferenceCard();
                    card.cardId = (String)r["id"];
                    card.name = (String)r["Name"];
                    card.pHash = (UInt64)r["pHash"];
                    card.dataRow = r;

                    referenceCards.Add(card);
                }
            }
        }