public static VoyImageResult Invalid() { VoyImageResult r = new VoyImageResult(); r.valid = false; return(r); }
private bool MatchBottom(Mat bottom, ref VoyImageResult result) { int minHeight = bottom.Rows * 3 / 15; int maxHeight = bottom.Rows * 5 / 15; int stepHeight = bottom.Rows / 30; Point maxlocCmd = new Point(); Point maxlocSci = new Point(); int scaledWidth = 0; int height = minHeight; for (; height <= maxHeight; height += stepHeight) { Mat scaledCmd = _skill_cmd.Resize(new Size(_skill_cmd.Cols * height / _skill_cmd.Rows, height)); Mat scaledSci = _skill_sci.Resize(new Size(_skill_sci.Cols * height / _skill_sci.Rows, height)); double maxvalCmd = ScaleInvariantTemplateMatch(bottom, scaledCmd, out maxlocCmd); //Console.WriteLine($"For CMD height {height} we got {maxvalCmd} at location {maxlocCmd.X} x {maxlocCmd.Y}"); double maxvalSci = ScaleInvariantTemplateMatch(bottom, scaledSci, out maxlocSci); //Console.WriteLine($"For SCI height {height} we got {maxvalSci} at location {maxlocSci.X} x {maxlocSci.Y}"); if ((maxvalCmd > 0.9) && (maxvalSci > 0.9)) { scaledWidth = scaledSci.Cols; break; } } if (scaledWidth == 0) { return(false); } double widthScale = (double)scaledWidth / _skill_sci.Width; result.cmd.SkillValue = OCRNumber(bottom.SubMat(maxlocCmd.Y, maxlocCmd.Y + height, maxlocCmd.X - (scaledWidth * 5), maxlocCmd.X - (scaledWidth / 8)), "cmd"); result.cmd.Primary = HasStar(bottom.SubMat(maxlocCmd.Y, maxlocCmd.Y + height, maxlocCmd.X + (scaledWidth * 9 / 8), maxlocCmd.X + (scaledWidth * 5 / 2)), "cmd"); result.dip.SkillValue = OCRNumber(bottom.SubMat(maxlocCmd.Y + height, maxlocSci.Y, maxlocCmd.X - (scaledWidth * 5), (int)(maxlocCmd.X - (_skill_dip.Width - _skill_sci.Width) * widthScale)), "dip"); result.dip.Primary = HasStar(bottom.SubMat(maxlocCmd.Y + height, maxlocSci.Y, maxlocCmd.X + (scaledWidth * 9 / 8), maxlocCmd.X + (scaledWidth * 5 / 2)), "dip"); result.eng.SkillValue = OCRNumber(bottom.SubMat(maxlocSci.Y, maxlocSci.Y + height, maxlocCmd.X - (scaledWidth * 5), (int)(maxlocCmd.X - (_skill_eng.Width - _skill_sci.Width) * widthScale)), "eng"); result.eng.Primary = HasStar(bottom.SubMat(maxlocSci.Y, maxlocSci.Y + height, maxlocCmd.X + (scaledWidth * 9 / 8), maxlocCmd.X + (scaledWidth * 5 / 2)), "eng"); result.sec.SkillValue = OCRNumber(bottom.SubMat(maxlocCmd.Y, maxlocCmd.Y + height, (int)(maxlocSci.X + scaledWidth * 1.4), maxlocSci.X + (scaledWidth * 6)), "sec"); result.sec.Primary = HasStar(bottom.SubMat(maxlocCmd.Y, maxlocCmd.Y + height, maxlocSci.X - (scaledWidth * 12 / 8), maxlocSci.X - (scaledWidth / 6)), "sec"); result.med.SkillValue = OCRNumber(bottom.SubMat(maxlocCmd.Y + height, maxlocSci.Y, (int)(maxlocSci.X + scaledWidth * 1.4), maxlocSci.X + (scaledWidth * 6)), "med"); result.med.Primary = HasStar(bottom.SubMat(maxlocCmd.Y + height, maxlocSci.Y, maxlocSci.X - (scaledWidth * 12 / 8), maxlocSci.X - (scaledWidth / 6)), "med"); result.sci.SkillValue = OCRNumber(bottom.SubMat(maxlocSci.Y, maxlocSci.Y + height, (int)(maxlocSci.X + scaledWidth * 1.4), maxlocSci.X + (scaledWidth * 6)), "sci"); result.sci.Primary = HasStar(bottom.SubMat(maxlocSci.Y, maxlocSci.Y + height, maxlocSci.X - (scaledWidth * 12 / 8), maxlocSci.X - (scaledWidth / 6)), "sci"); return(true); }
public VoyImageResult SearchUrl(string imageUrl) { DownloadResult downloadResult = ImgDownload.Download(imageUrl); if (downloadResult.image != null) { return(SearchMat(downloadResult.image)); } return(VoyImageResult.Invalid()); }
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()); } }
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()); } }