public VoyImageResult SearchUrl(string imageUrl)
        {
            DownloadResult downloadResult = ImgDownload.Download(imageUrl);

            if (downloadResult.image != null)
            {
                return(SearchMat(downloadResult.image));
            }

            return(VoyImageResult.Invalid());
        }
Beispiel #2
0
        private VoyImageResult SearchMat(Mat query)
        {
            try
            {
                VoyImageResult result = new VoyImageResult();

                // First, take the top of the image and look for the antimatter
                Mat top = query.SubMat(0, Math.Max(query.Rows / 5, 80), query.Cols / 3, query.Cols * 2 / 3);
                Cv2.Threshold(top, top, 100, 1.0, ThresholdTypes.Tozero);
                result.antimatter = MatchTop(top);
                if (result.antimatter == 0)
                {
                    // Not found
                    return(VoyImageResult.Invalid());
                }

                if (result.antimatter > 8000)
                {
                    result.antimatter = result.antimatter / 10;
                }

                double standardScale    = (double)query.Cols / query.Rows;
                double scaledPercentage = query.Rows * (standardScale * 1.2) / 9;

                Mat bottom = query.SubMat((int)(query.Rows - scaledPercentage), query.Rows, query.Cols / 6, query.Cols * 5 / 6);
                Cv2.Threshold(bottom, bottom, 100, 1.0, ThresholdTypes.Tozero);

                if (!MatchBottom(bottom, ref result))
                {
                    // Not found
                    return(VoyImageResult.Invalid());
                }

                result.valid = true;
                return(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception during VoyImage: {ex.Message}");
                return(VoyImageResult.Invalid());
            }
        }
Beispiel #3
0
 public VoyImageResult SearchUrl(string imageUrl)
 {
     try
     {
         using (var client = new WebClient())
         {
             lock (this)
             {
                 using (BinaryReader reader = new BinaryReader(client.OpenRead(imageUrl)))
                 {
                     return(SearchMat(Cv2.ImDecode(ReadAllBytes(reader), ImreadModes.Color)));
                 }
             }
         }
     }
     catch
     {
         return(VoyImageResult.Invalid());
     }
 }