From 2aeab450471cb80b59002da7da80faf251a0c4f4 Mon Sep 17 00:00:00 2001
From: asmrobot <asmrobot@hotmail.com>
Date: Mon, 25 Nov 2019 15:02:53 +0000
Subject: [PATCH] sigle computer

---
 src/RichCreator.Utility/CV/DnfCVHelper.cs |  244 +++++++++++++++++++++++++++---------------------
 1 files changed, 135 insertions(+), 109 deletions(-)

diff --git a/src/RichCreator.Utility/CV/DnfCVHelper.cs b/src/RichCreator.Utility/CV/DnfCVHelper.cs
index 6f1d787..e76e1e7 100644
--- a/src/RichCreator.Utility/CV/DnfCVHelper.cs
+++ b/src/RichCreator.Utility/CV/DnfCVHelper.cs
@@ -487,90 +487,6 @@
         }
 
 
-        private const Int32 radisXMaxRange = 8;//x容差范围
-        private const Int32 radisYMaxRange = 45;//y容差范围
-        private const Int32 xLineMin = 46;//横向最小宽度
-        private const Int32 yLineMin = 26;//纵向最小高度
-        private const Int32 thingItemYOffset = 50;//查找的横线与物体垂直偏移
-
-        //other remove:min:(0.0166666675359011,0.0584795325994492,0.564705908298492),max:(0.115740731358528,0.543589770793915,0.764705896377563)
-        //min:(0.0454545430839062,0.148148149251938,0.454901963472366),max:(0.146666660904884,0.53804349899292,0.952941179275513)
-        //边框颜色
-        static ZTHsvFloatColor min = new ZTHsvFloatColor(0.0166f,  0.0584f, 0.5647f);
-        static ZTHsvFloatColor max = new ZTHsvFloatColor(0.1467f, 0.5436f, 0.9530f);
-
-        //other remove:min:(0,0.111111111938953,0.0666666701436043),max:(0.958333313465118,0.65625,0.129411771893501)
-        //min:(0,0,0.0392156876623631),max:(0.833333313465118,1,0.219607844948769)
-        //内部颜色
-        static ZTHsvFloatColor innerMin = new ZTHsvFloatColor(0, 0f, 0.0392f);
-        static ZTHsvFloatColor innerMax = new ZTHsvFloatColor(1, 1f, 0.2197f); 
-        /// <summary>
-        /// 获取物品项点位
-        /// </summary>
-        /// <param name="image"></param>
-        /// <param name="gameRect"></param>
-        /// <returns></returns>
-        public static List<Structs.ZTPoint> GetThingItemPoints(Image<Rgb, byte> image, ZTRectangle gameRect)
-        {
-            List<ZTLine> lines = CVHelper.FindLines(image, xLineMin,gameRect, Orientation.Horizontal, min, max);
-            List<ZTLine> filterLines = new List<ZTLine>();
-            List<Structs.ZTPoint> points = new List<Structs.ZTPoint>();
-            Func<ZTLine, bool> existsLines = (line) =>
-            {
-                for (int i = 0; i < filterLines.Count; i++)
-                {
-                    //离得太近
-                    if (Math.Abs(filterLines[i].Y - line.Y) <= 3)
-                    {
-                        //横坐标是否重合
-                        if ((line.X + line.Length) < filterLines[i].X || line.X > (filterLines[i].X + filterLines[i].Length))
-                        {
-                            //未重合
-                            continue;
-                        }
-                        return true;
-                    }
-                }
-                return false;
-            };
-
-            ZTRectangle limit = ZTRectangle.Empty;
-            ZTLine vline = ZTLine.Empty;
-            //bool isLeft = true;
-            for (int i = 0; i < lines.Count; i++)
-            {
-                ZTLine line = lines[i];
-                //是否存在距离比较近的线
-                if (existsLines(line))
-                {
-                    continue;
-                }
-
-                //查找左边
-                //isLeft = true;
-                limit = new ZTRectangle(line.X - radisXMaxRange, line.Y, line.X, line.Y + radisYMaxRange);
-                if (!CVHelper.FindLine(out vline, image, yLineMin, limit, RichCreator.Utility.Structs.Orientation.Vertical, min, max))
-                {
-                    limit = new ZTRectangle(line.X + line.Length, line.Y, line.X + line.Length + radisXMaxRange, line.Y + radisYMaxRange);
-                    if (!CVHelper.FindLine(out vline, image, yLineMin, limit, Orientation.Vertical, min, max))
-                    {
-                        continue;
-                    }
-                    //isLeft = false;
-                }
-
-                //内部是否黑色
-                if (!CVHelper.InRange(image.Data, line.X + 3, line.Y + 3, innerMin, innerMax))
-                {
-                    continue;
-                }
-                
-                filterLines.Add(line);
-                points.Add(new Structs.ZTPoint(line.X + line.Length / 2, line.Y + thingItemYOffset));
-            }
-            return points;
-        }
-
 
         #region Location Point 1
         private static readonly Hsv LocationPointMinHsv = new Hsv(0, 0, 0);
@@ -730,7 +646,11 @@
         #endregion
 
         #region Location Point 2
-        private static ColorArray LocationPoint = ColorArray.FromColorString(0, 0, "800,352,0,0,0$791,343,255,255,255$793,343,0,0,0$796,343,255,255,255$798,343,0,0,0$801,343,255,255,255$802,345,0,0,0$802,347,255,255,255$802,349,0,0,0$802,352,255,255,255$797,352,255,255,255$795,352,0,0,0$791,352,255,255,255$791,350,0,0,0$791,348,255,255,255$791,346,0,0,0$796,347,255,255,255$797,348,255,255,255");
+        ////部分定位框数据
+        //private static ColorArray LocationPoint = ColorArray.FromColorString(0, 0, "800,352,0,0,0$791,343,255,255,255$793,343,0,0,0$796,343,255,255,255$798,343,0,0,0$801,343,255,255,255$802,345,0,0,0$802,347,255,255,255$802,349,0,0,0$802,352,255,255,255$797,352,255,255,255$795,352,0,0,0$791,352,255,255,255$791,350,0,0,0$791,348,255,255,255$791,346,0,0,0$796,347,255,255,255$797,348,255,255,255");
+
+        //全部定位框数据
+        private static ColorArray LocationPoint = ColorArray.FromColorString(0, 0, "1629,368,255,255,255$1619,367,255,255,255$1620,367,255,255,255$1621,367,0,0,0$1622,367,0,0,0$1623,367,0,0,0$1624,367,255,255,255$1625,367,255,255,255$1626,367,0,0,0$1627,367,0,0,0$1628,367,0,0,0$1629,367,255,255,255$1630,367,255,255,255$1630,368,255,255,255$1628,368,0,0,0$1627,368,0,0,0$1626,368,0,0,0$1625,368,255,255,255$1624,368,255,255,255$1623,368,0,0,0$1622,368,0,0,0$1621,368,0,0,0$1620,368,255,255,255$1619,368,255,255,255$1619,369,0,0,0$1620,369,0,0,0$1629,369,0,0,0$1630,369,0,0,0$1630,370,0,0,0$1629,370,0,0,0$1620,370,0,0,0$1619,370,0,0,0$1619,371,255,255,255$1620,371,255,255,255$1621,371,0,0,0$1622,371,0,0,0$1623,371,0,0,0$1624,371,255,255,255$1625,371,255,255,255$1626,371,0,0,0$1627,371,0,0,0$1628,371,0,0,0$1629,371,255,255,255$1630,371,255,255,255$1630,372,255,255,255$1629,372,255,255,255$1628,372,0,0,0$1627,372,0,0,0$1626,372,0,0,0$1625,372,255,255,255$1624,372,255,255,255$1623,372,0,0,0$1622,372,0,0,0$1621,372,0,0,0$1620,372,255,255,255$1619,372,255,255,255$1619,373,0,0,0$1620,373,0,0,0$1629,373,0,0,0$1630,373,0,0,0$1630,374,0,0,0$1629,374,0,0,0$1620,374,0,0,0$1619,374,0,0,0$1619,375,255,255,255$1620,375,255,255,255$1621,375,0,0,0$1622,375,0,0,0$1623,375,0,0,0$1624,375,255,255,255$1625,375,255,255,255$1626,375,0,0,0$1627,375,0,0,0$1628,375,0,0,0$1629,375,255,255,255$1630,375,255,255,255$1630,376,255,255,255$1629,376,255,255,255$1628,376,0,0,0$1627,376,0,0,0$1626,376,0,0,0$1625,376,255,255,255$1624,376,255,255,255$1623,376,0,0,0$1622,376,0,0,0$1621,376,0,0,0$1620,376,255,255,255$1619,376,255,255,255");
         /// <summary>
         /// 获取定位点
         /// </summary>
@@ -742,29 +662,7 @@
             ZTRectangle rect = ZTRectangle.Empty;
             if (CVHelper.FindColorArray(out rect, image, LocationPoint, gameRect))
             {
-                //获取定位标记,解析参数
-                byte number = 0;
-                bool bitValue = true;
-
-                Int32 x = 0, y = 0;
-                for (int bitIndex = 0; bitIndex <= 7; bitIndex++)
-                {
-                    //获取图像中存值的坐标
-                    GetBitCoordinate(out x, out y, bitIndex);
-                    
-                    //解析并设置值
-                    if (!ParseBit(out bitValue, image, rect.Start.Add(x, y)))
-                    {
-                        return ParametersPoint.Empty;
-                    }
-                    else
-                    {
-                        number=SetBit(number, bitIndex, bitValue);
-                    }
-                }
-
-                return new ParametersPoint(rect.GetCenterPoint(), number);
-                
+                return GetLocationPointParameter(image, rect);
             }
 
             return ParametersPoint.Empty;
@@ -787,6 +685,10 @@
 
             bool result = CVHelper.FindColorArray(out rect, image, LocationPoint, gameRect, (lpRect) => {
                 ParametersPoint pp = GetLocationPointParameter(image, lpRect);
+                if (pp.Equals( ParametersPoint.Empty))
+                {
+                    return false;
+                }
                 if (withoutNumber.ContainsKey(pp.Parameter))
                 {
                     return false;
@@ -810,6 +712,11 @@
         /// <returns></returns>
         private static ParametersPoint GetLocationPointParameter(Image<Rgb,byte> image,ZTRectangle rect)
         {
+            if (!VaildLocationRect(image, rect))
+            {
+                return ParametersPoint.Empty;
+            }
+
             //获取定位标记,解析参数
             byte number = 0;
             bool bitValue = true;
@@ -834,7 +741,16 @@
             return new ParametersPoint(rect.GetCenterPoint(), number);
         }
 
-
+        /// <summary>
+        /// 验证定位点方块是否正常
+        /// </summary>
+        /// <param name="image"></param>
+        /// <param name="rect"></param>
+        /// <returns></returns>
+        private static bool VaildLocationRect(Image<Rgb, byte> image, ZTRectangle rect)
+        {
+            return true;
+        }
 
 
         /// <summary>
@@ -1161,5 +1077,115 @@
         #endregion
 
 
+        #region Things
+
+
+        private const Int32 radisXMaxRange = 8;//x容差范围
+        private const Int32 radisYMaxRange = 45;//y容差范围
+        private const Int32 xLineMin = 46;//横向最小宽度
+        private const Int32 yLineMin = 26;//纵向最小高度
+        private const Int32 thingItemYOffset = 50;//查找的横线与物体垂直偏移
+
+        //other remove:min:(0.0166666675359011,0.0584795325994492,0.564705908298492),max:(0.115740731358528,0.543589770793915,0.764705896377563)
+        //min:(0.0454545430839062,0.148148149251938,0.454901963472366),max:(0.146666660904884,0.53804349899292,0.952941179275513)
+        //边框颜色
+        static ZTHsvFloatColor min = new ZTHsvFloatColor(0.0166f, 0.0584f, 0.5647f);
+        static ZTHsvFloatColor max = new ZTHsvFloatColor(0.1467f, 0.5436f, 0.9530f);
+
+        //other remove:min:(0,0.111111111938953,0.0666666701436043),max:(0.958333313465118,0.65625,0.129411771893501)
+        //min:(0,0,0.0392156876623631),max:(0.833333313465118,1,0.219607844948769)
+        //内部颜色
+        static ZTHsvFloatColor innerMin = new ZTHsvFloatColor(0, 0f, 0.0392f);
+        static ZTHsvFloatColor innerMax = new ZTHsvFloatColor(1, 1f, 0.2197f);
+        /// <summary>
+        /// 获取物品项点位
+        /// </summary>
+        /// <param name="image"></param>
+        /// <param name="gameRect"></param>
+        /// <returns></returns>
+        public static List<Structs.ZTPoint> GetThingItemPoints(Image<Rgb, byte> image, ZTRectangle gameRect)
+        {
+            List<ZTLine> lines = CVHelper.FindLines(image, xLineMin, gameRect, Orientation.Horizontal, min, max);
+            List<ZTLine> filterLines = new List<ZTLine>();
+            List<Structs.ZTPoint> points = new List<Structs.ZTPoint>();
+            Func<ZTLine, bool> existsLines = (line) =>
+            {
+                for (int i = 0; i < filterLines.Count; i++)
+                {
+                    //离得太近
+                    if (Math.Abs(filterLines[i].Y - line.Y) <= 3)
+                    {
+                        //横坐标是否重合
+                        if ((line.X + line.Length) < filterLines[i].X || line.X > (filterLines[i].X + filterLines[i].Length))
+                        {
+                            //未重合
+                            continue;
+                        }
+                        return true;
+                    }
+                }
+                return false;
+            };
+
+            ZTRectangle limit = ZTRectangle.Empty;
+            ZTLine vline = ZTLine.Empty;
+            //bool isLeft = true;
+            for (int i = 0; i < lines.Count; i++)
+            {
+                ZTLine line = lines[i];
+                //是否存在距离比较近的线
+                if (existsLines(line))
+                {
+                    continue;
+                }
+
+                //查找左边
+                //isLeft = true;
+                limit = new ZTRectangle(line.X - radisXMaxRange, line.Y, line.X, line.Y + radisYMaxRange);
+                if (!CVHelper.FindLine(out vline, image, yLineMin, limit, RichCreator.Utility.Structs.Orientation.Vertical, min, max))
+                {
+                    limit = new ZTRectangle(line.X + line.Length, line.Y, line.X + line.Length + radisXMaxRange, line.Y + radisYMaxRange);
+                    if (!CVHelper.FindLine(out vline, image, yLineMin, limit, Orientation.Vertical, min, max))
+                    {
+                        continue;
+                    }
+                    //isLeft = false;
+                }
+
+                //内部是否黑色
+                if (!CVHelper.InRange(image.Data, line.X + 3, line.Y + 3, innerMin, innerMax))
+                {
+                    continue;
+                }
+
+                filterLines.Add(line);
+                points.Add(new Structs.ZTPoint(line.X + line.Length / 2, line.Y + thingItemYOffset));
+            }
+            return points;
+        }
+
+
+        private static Hsv minThingHsv = new Hsv(25, 250, 250);
+        private static Hsv maxThingHsv = new Hsv(29, 255, 255);
+        private static ZTSize thingBlockSize = new ZTSize(20, 20);
+        /// <summary>
+        /// 查找所有物品的位置
+        /// </summary>
+        /// <param name="image"></param>
+        /// <returns></returns>
+        public static Structs.ZTPoint[] FindThings(Image<Hsv, byte> image, ZTRectangle gameRect)
+        {
+            List<ZTRectangle> rects = CVHelper.FindBlocks(image, minThingHsv, maxThingHsv, thingBlockSize);
+            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;
+        }
+        #endregion
+
+
+
     }
 }

--
Gitblit v1.9.3