asmrobot
2019-11-21 589ed88a5924a7494e21b95b6bbff5e46ff49ddd
src/RichCreator.Utility/CV/LindongCVHelper.cs
@@ -19,170 +19,6 @@
    /// </summary>
    public class LindongCVHelper
    {
        private static Hsv minMonsterHsv = new Hsv(165, 247, 175);
        private static Hsv maxMonsterHsv = new Hsv(173, 255, 230);
        private static ZTSize monsterBlockSize = new ZTSize(30, 30);
        /// <summary>
        /// 查找所有怪的位置
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public static Structs.ZTPoint[] FindMonster(Image<Hsv, byte> image,ZTRectangle gameRect)
        {
            List<ZTRectangle> rects = CVHelper.FindBlocks(image, minMonsterHsv, maxMonsterHsv, monsterBlockSize);
            Structs.ZTPoint[] monsterPoints = new Structs.ZTPoint[rects.Count];
            for (int i = 0; i < rects.Count; i++)
            {
                monsterPoints[i] = rects[i].GetCenterPoint().Add(gameRect.Start);
            }
            return monsterPoints;
        }
        public static ZTSize minDoorBlockSize = new ZTSize(25, 25);//门的最小大小
        public static Hsv minUpDoorColor = new Hsv(17, 254, 254);
        public static Hsv maxUpDoorColor = new Hsv(19, 255, 255);
        public static Hsv minRightDoorColor = new Hsv(143, 254, 254);
        public static Hsv maxRightDoorColor = new Hsv(145, 255, 255);
        public static Hsv minBottomDoorColor = new Hsv(17, 254, 254);
        public static Hsv maxBottomDoorColor = new Hsv(19, 255, 255);
        public static Hsv minLeftDoorColor = new Hsv(107, 254, 254);
        public static Hsv maxLeftDoorColor = new Hsv(109, 255, 255);
        public static Hsv minRealBottomDoorColor = new Hsv(35, 254, 254);
        public static Hsv maxRealBottomDoorColor = new Hsv(37, 255, 255);
        /// <summary>
        /// 查找门
        /// </summary>
        /// <param name="directions"></param>
        /// <returns></returns>
        public static ZTPoint FindDoor(out Direction targetDirection, Image<Hsv, byte> image, Direction[] directions, ZTRectangle gameRect)
        {
            targetDirection = Direction.None;
            Int32 height = gameRect.End.Y - gameRect.Start.Y;
            Int32 width = gameRect.End.X - gameRect.Start.X;
            Int32 yHalf = height / 2;
            Int32 xHalf = width / 2;
            ZTRectangle limitRect = ZTRectangle.Empty;
            Hsv minDoorHsvColor = default(Hsv), maxDoorHsvColor = default(Hsv);
            for (int doorIndex = 0; doorIndex < directions.Length; doorIndex++)
            {
                targetDirection = directions[doorIndex];
                switch (targetDirection)
                {
                    case Direction.Up:
                        minDoorHsvColor = minUpDoorColor;
                        maxDoorHsvColor = maxUpDoorColor;
                        limitRect = new ZTRectangle(0, 0, width, yHalf);
                        break;
                    case Direction.Right:
                        minDoorHsvColor = minRightDoorColor;
                        maxDoorHsvColor = maxRightDoorColor;
                        limitRect = new ZTRectangle(xHalf, 0, width, height);
                        break;
                    case Direction.Bottom:
                        minDoorHsvColor = minBottomDoorColor;
                        maxDoorHsvColor = maxBottomDoorColor;
                        limitRect = new ZTRectangle(0, yHalf, width, height);
                        break;
                    case Direction.Left:
                        minDoorHsvColor = minLeftDoorColor;
                        maxDoorHsvColor = maxLeftDoorColor;
                        limitRect = new ZTRectangle(0, 0, xHalf, height);
                        break;
                }
                List<ZTRectangle> doors = CVHelper.FindBlocks(image, minDoorHsvColor, maxDoorHsvColor, minDoorBlockSize);
                if (doors.Count <= 0)
                {
                    continue;
                }
                Structs.ZTPoint doorPosition = Structs.ZTPoint.Empty;
                for (int i = 0; i < doors.Count; i++)
                {
                    doorPosition = new Structs.ZTPoint(doors[i].Start.X + (doors[i].End.X - doors[i].Start.X) / 2, doors[i].Start.Y + (doors[i].End.Y - doors[i].Start.Y) / 2);
                    if (doorPosition.X >= limitRect.Start.X &&
                        doorPosition.X <= limitRect.End.X &&
                        doorPosition.Y >= limitRect.Start.Y &&
                        doorPosition.Y <= limitRect.End.Y)
                    {
                        return doorPosition + gameRect.Start;
                    }
                }
            }
            return Structs.ZTPoint.Empty;
        }
        /// <summary>
        /// 地图右上角素喃文字
        /// </summary>
        public static ColorArray MapTopSunan = ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "1401,72,230,200,155$1381,69,230,200,155$1380,68,0,0,0$1385,68,0,0,0$1386,68,230,200,155$1386,67,0,0,0$1387,67,0,0,0$1387,68,0,0,0$1391,68,0,0,0$1391,69,230,200,155$1392,69,0,0,0$1393,69,230,200,155$1393,68,0,0,0$1396,69,0,0,0$1395,69,230,200,155$1397,69,230,200,155$1399,68,0,0,0$1401,68,0,0,0$1404,69,0,0,0$1404,72,0,0,0$1403,72,230,200,155$1402,72,0,0,0$1400,72,0,0,0$1399,72,230,200,155$1398,72,0,0,0$1397,72,230,200,155$1396,72,0,0,0$1395,72,230,200,155$1394,72,0,0,0$1393,72,230,200,155$1392,72,0,0,0$1381,79,0,0,0$1382,79,230,200,155$1383,79,0,0,0$1385,79,230,200,155$1387,79,0,0,0$1390,79,230,200,155$1391,79,0,0,0$1396,79,0,0,0$1397,79,230,200,155$1398,79,0,0,0$1397,80,0,0,0$1401,79,0,0,0$1402,79,230,200,155$1402,80,0,0,0$1403,80,0,0,0$1403,79,230,200,155$1404,79,0,0,0$1404,80,0,0,0");
        /// <summary>
        /// 是否进入素喃
        /// </summary>
        /// <param name="image"></param>
        /// <param name="gameRect"></param>
        /// <returns></returns>
        public static bool IsInSunan(ZTRectangle gameRect)
        {
            Image<Rgb, byte> image = ScreenCapture.Instance.CaptureScreenReturnImage();
            ZTRectangle limit = new ZTRectangle(gameRect.End.X - 130, gameRect.Start.Y, gameRect.End.X, gameRect.Start.Y + 60);
            ZTRectangle position = ZTRectangle.Empty;
            return CVHelper.FindColorArray(out position, image, MapTopSunan, limit);
        }
        /// <summary>
        /// 地图右上角时空之门文字
        /// </summary>
        public static ColorArray MapTopShikongzhimen = ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "1187,48,230,200,155$1177,46,230,200,155$1180,46,230,200,155$1180,55,230,200,155$1177,55,230,200,155$1184,56,230,200,155$1186,56,230,200,155$1186,45,230,200,155$1189,48,230,200,155$1193,45,230,200,155$1196,48,230,200,155$1199,47,230,200,155$1199,48,230,200,155$1201,48,230,200,155$1209,48,230,200,155$1204,45,230,200,155$1212,45,230,200,155$1213,46,230,200,155$1215,45,230,200,155$1221,45,230,200,155$1221,56,230,200,155$1219,56,230,200,155$1212,56,230,200,155$1210,56,230,200,155$1205,56,230,200,155$1199,56,230,200,155$1189,56,230,200,155$1194,55,230,200,155");
        /// <summary>
        /// 是否进入时空之门
        /// </summary>
        /// <param name="image"></param>
        /// <param name="gameRect"></param>
        /// <returns></returns>
        public static bool IsInShikongzhimen(ZTRectangle gameRect)
        {
            Image<Rgb, byte> image = ScreenCapture.Instance.CaptureScreenReturnImage();
            ZTRectangle limit = new ZTRectangle(gameRect.End.X - 210, gameRect.Start.Y, gameRect.End.X, gameRect.Start.Y + 60);
            ZTRectangle position = ZTRectangle.Empty;
            return CVHelper.FindColorArray(out position, image, MapTopShikongzhimen, limit);
        }
        /// <summary>
        /// 选择进那个副本界面的下方space区域
        /// </summary>
        public static ColorArray ChoiceTaskPage_0 = ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "873,736,201,176,126$855,736,17,15,11$854,736,17,15,11$851,736,206,181,130$858,736,206,181,130$860,736,10,9,6$862,736,17,15,11$865,736,204,178,128$868,736,17,15,11$869,736,17,15,11$876,736,17,15,11$880,736,203,178,128$883,736,17,15,11$888,736,208,182,131$888,738,208,182,131$884,738,52,45,33$879,738,179,156,113$874,738,55,48,35$871,738,12,11,8$865,738,158,139,100$862,738,208,182,131$859,738,50,43,31$854,738,52,45,33$850,738,208,182,131$850,740,208,182,131$852,740,128,112,80$854,740,208,182,131$858,740,201,176,127$859,740,50,43,31$862,740,208,182,131$867,740,89,78,56$869,740,208,182,131$876,740,208,182,131$881,740,21,18,13$884,740,208,182,131$886,740,145,127,91$887,742,208,182,131$884,742,17,15,11$880,742,208,182,131$877,742,17,15,11$874,742,158,138,99$870,742,17,15,11$865,742,208,182,131$862,742,17,15,11$859,742,50,43,31$858,742,208,182,131$855,742,17,15,11$851,742,208,182,131");
        public static ColorArray ChoiceTaskPage_1 = ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "889,793,119,104,75$872,788,208,182,131$935,786,203,177,128$939,793,208,182,131$868,795,208,182,131$879,792,208,182,131$889,793,119,104,75$916,796,17,15,11$916,796,17,15,11$916,796,17,15,11$916,796,17,15,11");
        /// <summary>
        /// 是否打开选择副本界面
        /// </summary>
        /// <param name="image"></param>
        /// <param name="gameRect"></param>
        /// <returns></returns>
        public static bool IsInChoiceTaskPage(Image<Rgb, byte> image, ZTRectangle gameRect)
        {
            ZTRectangle limit = new ZTRectangle(gameRect.Start.X + 600, gameRect.End.Y - 35, gameRect.Start.X + 800, gameRect.End.Y);
            ZTRectangle position = ZTRectangle.Empty;
            if (CVHelper.FindColorArray(out position, image, ChoiceTaskPage_0, gameRect))
            {
                return true;
            }
            return CVHelper.FindColorArray(out position, image, ChoiceTaskPage_1, gameRect);
        }
        /// <summary>
        /// 凛冬难度选择向右的箭头
        /// </summary>
@@ -223,11 +59,11 @@
        /// 凛冬难度,1¬5级
        /// </summary>
        private static ColorArray[] LindongNandu = new ColorArray[] {
            ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "591,625,157,0,17$537,625,255,255,255$551,625,0,93,157$564,625,93,0,157$577,625,150,0,126"),
            ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "577,625,150,0,126$537,625,93,157,0$551,625,255,255,255$564,625,93,0,157$590,625,157,0,17"),
            ColorArray.FromHsvFloatString(0.002f,0.002f,0.002f,"591,625,157,0,17$538,625,93,157,0$551,625,0,93,157$564,625,255,255,255$577,625,150,0,126"),
            ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "577,625,255,255,255$538,625,93,157,0$551,625,0,93,157$564,625,93,0,157$590,625,157,0,17"),
            ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "590,625,255,255,255$537,625,93,157,0$551,625,0,93,157$564,625,93,0,157$577,625,150,0,126")
            ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "1391,650,102,0,170$1368,650,255,255,255$1380,650,0,102,170$1402,650,160,0,136$1413,650,170,0,17"),
            ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "1391,650,102,0,170$1369,650,102,170,0$1380,650,255,255,255$1402,650,160,0,136$1413,650,170,0,17"),
            ColorArray.FromHsvFloatString(0.002f,0.002f,0.002f,"1390,650,255,255,255$1369,650,102,170,0$1380,650,0,102,170$1402,650,160,0,136$1413,650,170,0,17"),
            ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "1402,650,255,255,255$1369,650,102,170,0$1380,650,0,102,170$1391,650,102,0,170$1413,650,170,0,17"),
            ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "1391,650,102,0,170$1369,650,102,170,0$1380,650,0,102,170$1401,650,160,0,136$1412,650,255,255,255")
        };
@@ -241,7 +77,7 @@
        /// <returns></returns>
        public static bool GetChoiceLingdongNandu(out Int32 choiceNandu,Image<Rgb, byte> image, ZTRectangle gameRect)
        {
            ZTRectangle limit = new ZTRectangle(gameRect.Start.X + 400, gameRect.End.Y - 150, gameRect.Start.X + 650, gameRect.End.Y-90);
            ZTRectangle limit = new ZTRectangle(gameRect.Start.X + 270, gameRect.Start.Y +505, gameRect.Start.X + 354, gameRect.Start.Y+519);
            ZTRectangle position = ZTRectangle.Empty;
            for (int i = 0; i < LindongNandu.Length; i++)
            {