ZIM hace 1 año
padre
commit
fd81ad3db0

+ 42 - 24
Assets/InfraredProject/WebCamera/Script/ZIM/InfraredLocate/InfraredLocate.cs

@@ -167,19 +167,19 @@ namespace ZIM
                 }
             });
 
-            if (ScreenLocate.Main.DebugOnZIMDemo)
-            {
-                if (spotPoint.Count > 400)     // 如果亮点太多,控制亮点数量在200左右
-                {
-                    samplingScale = (int)Math.Ceiling(samplingScale * Math.Sqrt(spotPoint.Count / 400.0));
-                    return new List<PixelSpotArea>();
-                }
-                else if (samplingScale > 1 && spotPoint.Count < 100)
-                {
-                    samplingScale = Math.Max((int)Math.Ceiling(samplingScale * Math.Sqrt(spotPoint.Count / 200.0)), 1);
-                    return new List<PixelSpotArea>();
-                }
-            }
+            //if (ScreenLocate.Main.DebugOnZIMDemo)
+            //{
+            //    if (spotPoint.Count > 400)     // 如果亮点太多,控制亮点数量在200左右
+            //    {
+            //        samplingScale = (int)Math.Ceiling(samplingScale * Math.Sqrt(spotPoint.Count / 400.0));
+            //        return new List<PixelSpotArea>();
+            //    }
+            //    else if (samplingScale > 1 && spotPoint.Count < 100)
+            //    {
+            //        samplingScale = Math.Max((int)Math.Ceiling(samplingScale * Math.Sqrt(spotPoint.Count / 200.0)), 1);
+            //        return new List<PixelSpotArea>();
+            //    }
+            //}
 
             //times.Add(watch.ElapsedMilliseconds);
             //UnityEngine.Debug.Log("time1: " + (times[times.Count - 1] - times[times.Count - 2]));
@@ -271,24 +271,42 @@ namespace ZIM
 
         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);
 
-            Color[] colors = new Color[4] { Color.yellow, Color.white, Color.green, Color.blue };
-            int index = 0;
-            foreach (var i in areas)
+            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 i.Pixels0)
-                    texture.SetPixel((int)p.x, (int)p.y, colors[index]);
-                index++;
-                foreach (var p in i.Pixels1)
-                    texture.SetPixel((int)p.x, (int)p.y, colors[index]);
-                index++;
-                if (index >= 4)
-                    break;
+                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();

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

@@ -130,8 +130,7 @@ namespace ZIM
             }
 
             var predict = estimation.Update(area.Centroid);
-            //ScreenLocation = area.Center;
-            ScreenLocation = area.Centroid * 0.8f + predict * 0.2f;
+            ScreenLocation = area.Centroid * 0.8f + predict * 0.2f;     // 参考一点预测点,防止光标不稳定
             spots.Add(area);
             if (spots.Count > 15)
             {

+ 82 - 1
Assets/InfraredProject/WebCamera/zimWebCamera.unity

@@ -1383,7 +1383,8 @@ RectTransform:
   m_LocalPosition: {x: 0, y: 0, z: 0}
   m_LocalScale: {x: 1, y: 1, z: 1}
   m_ConstrainProportionsScale: 0
-  m_Children: []
+  m_Children:
+  - {fileID: 1821259942}
   m_Father: {fileID: 1867793102}
   m_RootOrder: 12
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -5468,6 +5469,86 @@ CanvasRenderer:
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 1819346505}
   m_CullTransparentMesh: 1
+--- !u!1 &1821259941
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 1821259942}
+  - component: {fileID: 1821259944}
+  - component: {fileID: 1821259943}
+  m_Layer: 5
+  m_Name: InfoDebug
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!224 &1821259942
+RectTransform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1821259941}
+  m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
+  m_LocalScale: {x: 1, y: 1, z: 1}
+  m_ConstrainProportionsScale: 0
+  m_Children: []
+  m_Father: {fileID: 557727041}
+  m_RootOrder: 0
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+  m_AnchorMin: {x: 0, y: 0.5}
+  m_AnchorMax: {x: 0, y: 0.5}
+  m_AnchoredPosition: {x: -214.62286, y: -1448.3071}
+  m_SizeDelta: {x: 286.5011, y: 416.2088}
+  m_Pivot: {x: 0.5, y: 0.5}
+--- !u!114 &1821259943
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1821259941}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  m_Material: {fileID: 0}
+  m_Color: {r: 1, g: 1, b: 1, a: 1}
+  m_RaycastTarget: 1
+  m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
+  m_Maskable: 1
+  m_OnCullStateChanged:
+    m_PersistentCalls:
+      m_Calls: []
+  m_FontData:
+    m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
+    m_FontSize: 28
+    m_FontStyle: 1
+    m_BestFit: 0
+    m_MinSize: 2
+    m_MaxSize: 48
+    m_Alignment: 0
+    m_AlignByGeometry: 0
+    m_RichText: 1
+    m_HorizontalOverflow: 0
+    m_VerticalOverflow: 0
+    m_LineSpacing: 1
+  m_Text: Debug
+--- !u!222 &1821259944
+CanvasRenderer:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1821259941}
+  m_CullTransparentMesh: 1
 --- !u!1 &1867793098
 GameObject:
   m_ObjectHideFlags: 0