Selaa lähdekoodia

准心识别算法的测试代码 修改位置

ZIM 10 kuukautta sitten
vanhempi
sitoutus
f7be4a6c45

+ 1 - 47
Assets/InfraredProject/WebCamera/Script/ZIM/InfraredLocate/InfraredLocate.cs

@@ -213,10 +213,6 @@ namespace ZIM
                 //var spotArea = DbscanToSpotAreas(db, brightPoint);
                 var spotArea = PixelSpotArea.Cluster(spotPoint, brightPoint, screenIdentification.Screen.UVInScreen);
 
-                if (ScreenLocate.Main.DebugOnZIMDemo)
-                    DebugAreas(spotArea);
-
-
                 //Debug.Log("db: " + db.Clusters.Count);
                 //Debug.Log("db noise: " + db.Noise.Count);
                 //foreach (var i in spotArea)
@@ -269,49 +265,7 @@ namespace ZIM
             return new List<PixelSpotArea>();
         }
 
-        private void DebugAreas(List<PixelSpotArea> areas)
-        {
-            ScreenLocate.Main.Info.transform.GetChild(0).GetComponent<Text>().text = $"areas.Count: {areas.Count}";
-            PixelSpotArea a0 = null;  // 表示最大半径的区域
-            PixelSpotArea a1 = null;  // 表示第二大半径的区域
-
-            foreach (var a in areas)
-            {
-                if (a0 == null || a.Radius > a0.Radius)
-                {
-                    a1 = a0;  // 更新第二大为之前最大
-                    a0 = a;   // 更新最大为当前的
-                }
-                else if (a1 == null || a.Radius > a1.Radius)
-                {
-                    a1 = a;   // 更新第二大
-                }
-            }
-
-            Texture2D texture = new Texture2D(ScreenLocate.Main.CameraSize.x, ScreenLocate.Main.CameraSize.y);
-            Color[] blackPixels = new Color[texture.width * texture.height];
-            for (int i = 0; i < blackPixels.Length; i++)
-                blackPixels[i] = Color.black;
-            texture.SetPixels(blackPixels);
-
-            if (a0 != null)
-            {
-                foreach (var p in a0.Pixels0)
-                    texture.SetPixel((int)p.x, (int)p.y, Color.yellow);
-                foreach (var p in a0.Pixels1)
-                    texture.SetPixel((int)p.x, (int)p.y, Color.white);
-            }
-            if (a1 != null)
-            {
-                foreach (var p in a1.Pixels0)
-                    texture.SetPixel((int)p.x, (int)p.y, Color.green);
-                foreach (var p in a1.Pixels1)
-                    texture.SetPixel((int)p.x, (int)p.y, Color.blue);
-            }
-
-            texture.Apply();
-            ScreenLocate.DebugTexture(6, texture);
-        }
+        
 
         private List<PixelSpotArea_DbScan> DbscanToSpotAreas(DbscanResult<Vector2> db, List<Vector2> brightPoint)
         {

+ 47 - 0
Assets/InfraredProject/WebCamera/Script/ZIM/ScreenLocate.cs

@@ -746,6 +746,9 @@ public partial class ScreenLocate : MonoBehaviour
             infraredSpotBuffer = infraredLocate.UpdateSingle(cameraPixels);
         else
             infraredSpotBuffer = infraredLocate.Update(cameraPixels);
+
+        if (DebugOnZIMDemo)
+            DebugPixelSpotArea();
     }
 
     private bool RefreshCameraSize()
@@ -805,6 +808,50 @@ public partial class ScreenLocate : MonoBehaviour
         }
     }
 
+    public void DebugPixelSpotArea(List<PixelSpotArea> areas)
+    {
+        Info.transform.GetChild(0).GetComponent<Text>().text = $"areas.Count: {areas.Count}";
+        PixelSpotArea a0 = null;  // 表示最大半径的区域
+        PixelSpotArea a1 = null;  // 表示第二大半径的区域
+
+        foreach (var a in areas)
+        {
+            if (a0 == null || a.Radius > a0.Radius)
+            {
+                a1 = a0;  // 更新第二大为之前最大
+                a0 = a;   // 更新最大为当前的
+            }
+            else if (a1 == null || a.Radius > a1.Radius)
+            {
+                a1 = a;   // 更新第二大
+            }
+        }
+
+        Texture2D texture = new Texture2D(CameraSize.x, CameraSize.y);
+        Color[] blackPixels = new Color[texture.width * texture.height];
+        for (int i = 0; i < blackPixels.Length; i++)
+            blackPixels[i] = Color.black;
+        texture.SetPixels(blackPixels);
+
+        if (a0 != null)
+        {
+            foreach (var p in a0.Pixels0)
+                texture.SetPixel((int)p.x, (int)p.y, Color.yellow);
+            foreach (var p in a0.Pixels1)
+                texture.SetPixel((int)p.x, (int)p.y, Color.white);
+        }
+        if (a1 != null)
+        {
+            foreach (var p in a1.Pixels0)
+                texture.SetPixel((int)p.x, (int)p.y, Color.green);
+            foreach (var p in a1.Pixels1)
+                texture.SetPixel((int)p.x, (int)p.y, Color.blue);
+        }
+
+        texture.Apply();
+        DebugTexture(6, texture);
+    }
+
     #region 自动识别 
     int Capture = 30;
     int Delay = 30;