Пример #1
0
        private async Task HashCardAsync(SfCard card)
        {
            if (card.promo == true)
            {
                if (card.promo_types != null && card.promo_types.Contains("datestamped"))
                {
                    return;
                }
            }
            var reference = referenceCards.SingleOrDefault(c => c.sf_id == card.id);

            if (reference == null)
            {
                var image = Path.Combine("Images", card.id + ".jpg");
                if (!File.Exists(image))
                {
                    var client = new HttpClientDownloadWithProgress(card.image_uris.large, image);
                    client.ProgressChanged += (long?totalFileSize, long totalBytesDownloaded, double?progressPercentage) =>
                    {
                        status($"Downloading {card.id}: {card.name} ({card.set}) ... {totalBytesDownloaded}...");
                    };
                    await client.StartDownload();
                }

                ulong hash = 0;
                Phash.ph_dct_imagehash(image, ref hash);
                var row = sql.InsertCard(card.name, hash.ToString(), card.set, card.type_line, card.mana_cost, card.rarity, card.id);
                using (DataTable Reader = sql.dbResult($"SELECT * FROM cards WHERE id = {row}"))
                    referenceCards.Add(new ReferenceCard(Reader.Rows[0]));
            }
        }
Пример #2
0
        public void UpdateCard(ReferenceCard card)
        {
            var directory = Path.Combine(refCardDir, (string)card.dataRow["Set"]);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            var image = Path.Combine(directory, card.CollectorNumber + ".jpg");

            if (!File.Exists(image))
            {
            }

            Phash.ph_dct_imagehash(image, ref card.pHash);
            sql.dbNone("UPDATE cards SET pHash=" + card.pHash.ToString() + " WHERE id=" + card.Id);
        }
Пример #3
0
        private void matchCard()
        {
            var 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);

                var           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;
                    card.hammingValue  = lowestHamming;
                    //Debug.WriteLine("Highest Similarity: " + bestMatch.name + " ID: " + bestMatch.cardId.ToString());

                    Graphics g    = Graphics.FromImage(cameraBitmap);
                    var      font = new Font("Tahoma", 25);
                    g.DrawString(bestMatch.Name, font, Brushes.Black, new PointF(card.corners[0].X - 29, card.corners[0].Y - 39));
                    g.DrawString(bestMatch.Name, font, Brushes.Yellow, new PointF(card.corners[0].X - 30, card.corners[0].Y - 40));
                    g.Dispose();
                }
            }
        }