Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. public static bool EmguBool(Image<Bgr, byte> source, string picture, out Point found, bool screenshot = false)
  2. {
  3. string file = @"C:\tmp\search\" + picture;
  4. if (!File.Exists(file))
  5. {
  6. Console.WriteLine("picture not found {0}", picture);
  7. found = Point.Empty;
  8. return false;
  9. }
  10. var template = new Image<Bgr, byte>(file); // Image A
  11. var imageToShow = source.Copy();
  12.  
  13. using (Image<Gray, float> result = source.MatchTemplate(template, global::Emgu.CV.CvEnum.TemplateMatchingType.CcoeffNormed))
  14. {
  15. double[] minValues, maxValues;
  16. Point[] minLocations, maxLocations;
  17. result.MinMax(out minValues, out maxValues, out minLocations, out maxLocations);
  18.  
  19. if (screenshot)
  20. {
  21. if (maxValues[0] > 0.9)
  22. {
  23. // This is a match. Do something with it, for example draw a rectangle around it.
  24. Rectangle match = new Rectangle(maxLocations[0], template.Size);
  25. imageToShow.Draw(match, new Bgr(Color.Red), 3);
  26. imageToShow.Save(@"C:\tmp\getset.jpg");
  27. }
  28. }
  29.  
  30. if (maxValues[0] < 0.9)
  31. {
  32. found = Point.Empty;
  33. return false;
  34. }
  35.  
  36. found = new Point(maxLocations[0].X, maxLocations[0].Y);
  37. return true;
  38. }
  39. }
  40.  
  41. public static void OpenCapsules()
  42. {
  43. var screenshot = EmguCv.QueryFrame();
  44. if (EmguBool(screenshot, "disenchant_fail.png", out Point disenchant_fail))
  45. {
  46. MouseMove(disenchant_fail.X + 55, disenchant_fail.Y + 47);
  47. Console.WriteLine("disenchant_fail.png");
  48. LeftClick();
  49. return;
  50. }
  51.  
  52. if (EmguBool(screenshot, "close.png", out Point close))
  53. {
  54. MouseMove(close.X + 22, close.Y + 20);
  55. Console.WriteLine("close.png");
  56. LeftClick();
  57. return;
  58. }
  59.  
  60. if (EmguBool(screenshot, "unlock_permanent.png", out Point unlock_permanent))
  61. {
  62. MouseMove(unlock_permanent.X, unlock_permanent.Y);
  63. Console.WriteLine("unlock_permanent.png");
  64. LeftClick();
  65. return;
  66. }
  67.  
  68. if (EmguBool(screenshot, "add_to_loot.png", out Point add_to_loot))
  69. {
  70. MouseMove(add_to_loot.X, add_to_loot.Y);
  71. Console.WriteLine("add_to_loot.png");
  72. LeftClick();
  73. return;
  74. }
  75.  
  76. if (EmguBool(screenshot, "open.png", out Point open))
  77. {
  78. MouseMove(open.X, open.Y);
  79. Console.WriteLine("open.png");
  80. LeftClick();
  81. return;
  82. }
  83.  
  84. if (EmguBool(screenshot, "capsules_V_2.png", out Point capsules_V_2))
  85. {
  86. MouseMove(capsules_V_2.X, capsules_V_2.Y);
  87. Console.WriteLine("capsules_V_2.png");
  88. LeftClick();
  89. return;
  90. }
  91.  
  92. if (EmguBool(screenshot, "capsules.png", out Point capsules))
  93. {
  94. MouseMove(capsules.X, capsules.Y);
  95. Console.WriteLine("capsules.png");
  96. LeftClick();
  97. return;
  98. }
  99. disenchantChampionShards();
  100. }
  101.  
  102. public static void disenchantChampionShards()
  103. {
  104. var screenshot = EmguCv.QueryFrame();
  105. if (EmguBool(screenshot, "disenchant.png", out Point disenchant))
  106. {
  107. MouseMove(disenchant.X, disenchant.Y);
  108. Console.WriteLine("disenchant.png");
  109. LeftClick();
  110. return;
  111. }
  112.  
  113. if (EmguBool(screenshot, "disenchant_into.png", out Point disenchant_into))
  114. {
  115. MouseMove(disenchant_into.X, disenchant_into.Y);
  116. Console.WriteLine("disenchant_into.png");
  117. LeftClick();
  118. return;
  119. }
  120.  
  121. if (EmguBool(screenshot, "champions.png", out Point champions))
  122. {
  123. if (EmguBool(screenshot, "skins.png", out Point skins) || !EmguBool(screenshot, "skins.png", out Point skins2))
  124. {
  125. if (skins.Y - champions.Y > 70 || skins == Point.Empty)
  126. {
  127. MouseMove(champions.X + 40, champions.Y + 70);
  128. Console.WriteLine("skinshard.png");
  129. LeftClick();
  130. return;
  131. }
  132.  
  133. if (skins.Y - champions.Y < 70)
  134. {
  135. Console.WriteLine("finish");
  136. Console.ReadKey();
  137. }
  138. return;
  139. }
  140. return;
  141. }
  142. Console.WriteLine("finish");
  143. Console.ReadKey();
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement