ZIM 1 éve
szülő
commit
a2930611b6

+ 2 - 2
Assets/InfraredProject/WebCamera/Script/ZIM/DebugOnWin.cs → Assets/InfraredProject/WebCamera/Script/ZIM/DebugOnDemo.cs

@@ -2,7 +2,7 @@
 using System.Collections.Generic;
 using UnityEngine;
 
-public class DebugOnWin : MonoBehaviour
+public class DebugOnDemo : MonoBehaviour
 {
     void Start()
     {
@@ -12,7 +12,7 @@ public class DebugOnWin : MonoBehaviour
     IEnumerator OpenDebug()
     {
         yield return null;
-        ScreenLocate.Main.DebugOnEditorWin = true;
+        ScreenLocate.Main.DebugOnZIMDemo = true;
     }
 
     void Update()

+ 0 - 0
Assets/InfraredProject/WebCamera/Script/ZIM/DebugOnWin.cs.meta → Assets/InfraredProject/WebCamera/Script/ZIM/DebugOnDemo.cs.meta


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

@@ -215,7 +215,7 @@ namespace ZIM
                 var db = Dbscan.Run(spotPoint, ZIM.Unity.ZIMMath.LengthManhattan, samplingScale * 2, 3);
                 var spotArea = DbscanToSpotAreas(db, brightPoint);
 
-                if (ScreenLocate.Main.DebugOnEditorWin)
+                if (ScreenLocate.Main.DebugOnZIMDemo)
                     DebugAreas(spotArea);
 
 

+ 6 - 9
Assets/InfraredProject/WebCamera/Script/ZIM/InfraredLocate/ScreenIdentification.cs

@@ -89,7 +89,7 @@ namespace o0.Project
         // 自动识别开始的入口
         public void LocateScreen(int Capture = 30, int Delay = 30)  //数值单位是frame
         {
-            if (ScreenLocate.Main.DebugScreenImage != null && ScreenLocate.Main.DebugOnEditorWin)     // 这段仅用于测试图片
+            if (ScreenLocate.Main.DebugScreenImage != null && ScreenLocate.Main.DebugOnZIMDemo)     // 这段仅用于测试图片
             {
                 ScreenLocate.Main.CameraSize = new Geometry2D.Vector<int>(ScreenLocate.Main.DebugScreenImage.width, ScreenLocate.Main.DebugScreenImage.height);
                 DebugImage(ScreenLocate.Main.DebugScreenImage);
@@ -281,14 +281,11 @@ namespace o0.Project
             else
             {
                 QuadrilateralFit(out Texture2D LocateLightedRedTex,out Texture2D ChoosableLineTex, out Texture2D ScreenQuadTex);
-                if (ScreenLocate.Main.DebugOnEditorWin)
-                {
-                    ScreenLocate.DebugTexture(2, LocateLightedRedTex);
-                    ScreenLocate.DebugTexture(3, ScreenQuadTex);
-                    // 融合线段和原图
-                    ScreenLocate.DebugTexture(4, LocateLightedRedTex.Merge(ScreenQuadTex));
-                    ScreenLocate.DebugTexture(5, ChoosableLineTex);
-                }
+                ScreenLocate.DebugTexture(2, LocateLightedRedTex);
+                ScreenLocate.DebugTexture(3, ScreenQuadTex);
+                // 融合线段和原图
+                ScreenLocate.DebugTexture(4, LocateLightedRedTex.Merge(ScreenQuadTex));
+                ScreenLocate.DebugTexture(5, ChoosableLineTex);
 
                 if (quadTemp.Count != LocateAreaData[0].Length)
                 {

+ 23 - 17
Assets/InfraredProject/WebCamera/Script/ZIM/ScreenLocate.cs

@@ -102,7 +102,7 @@ public partial class ScreenLocate : MonoBehaviour
     // output的图像
     // 图0是摄像机原图,图1是屏幕识别的全部可选线段,图2是识别出的屏幕画面,图3是识别出的屏幕四条边,图4是图2和图3的叠加,图5显示3种不同颜色的算法识别线段
     public List<RawImage> outputRawImages;
-    [NonSerialized] public Texture[] outputTexture2D;
+    [NonSerialized] public Texture[] outputTexture2D = new Texture[8];
     public RawImage FullScreenImage;
 
     public PixelCheaker ScreenPixelCheaker;
@@ -111,7 +111,7 @@ public partial class ScreenLocate : MonoBehaviour
     public o0.Geometry2D.Vector<int> CameraSize { get; set; }
 
     public Texture2D DebugScreenImage;
-    public bool DebugOnEditorWin = false;
+    public bool DebugOnZIMDemo = false;
 
     // private SynchronizationContext mainContext;
 
@@ -176,15 +176,23 @@ public partial class ScreenLocate : MonoBehaviour
     {
         var newTex = pixels.zimAutoLightSimple(width, height);
         DebugTexture(7, newTex);
-        Main.FullScreenImage.texture = newTex;
+        try
+        {
+            Main.FullScreenImage.texture = newTex;
+        }
+        catch { }
     }
 
     static public void DebugTexture(int index, Texture texture)
     {
-        LateDestory(Main.outputRawImages[index].texture);
-        Main.outputRawImages[index].texture = texture;
-        if (Main.outputTexture2D != null) 
-            Main.outputTexture2D[index] = texture;
+        LateDestory(Main.outputTexture2D[index]);
+
+        Main.outputTexture2D[index] = texture;
+        try
+        {
+            Main.outputRawImages[index].texture = texture;
+        }
+        catch { }
     }
     static void LateDestory(UnityEngine.Object o) => Main.StartCoroutine(Main.LateDestoryIEnum(o));
 
@@ -270,12 +278,11 @@ public partial class ScreenLocate : MonoBehaviour
     {
         //mainContext = SynchronizationContext.Current;
 
-        outputTexture2D = new Texture[8];
         canvas = transform.GetComponent<RectTransform>();
 
         mode = Mode.InfraredLocate;
 
-        if (DebugScreenImage && DebugOnEditorWin)
+        if (DebugScreenImage && DebugOnZIMDemo)
         {
             screenIdentification = new o0.Project.ScreenIdentification();
             screenIdentification.LocateScreen();
@@ -300,7 +307,7 @@ public partial class ScreenLocate : MonoBehaviour
 
     IEnumerator LateDestoryIEnum(UnityEngine.Object o)
     {
-        while (true)
+        if (o)
         {
             yield return new WaitForEndOfFrame();
             Destroy(o);
@@ -423,8 +430,7 @@ public partial class ScreenLocate : MonoBehaviour
                 Debug.LogError("[ScreenLocate] RefreshCameraSize 屏幕size改变,存在NaN值,重新校准:" + PrintVector2List(quadUnityVectorList));
             }
          
-
-            if (DebugOnEditorWin)
+            if (DebugOnZIMDemo)
                 Main.ShowScreen(Main.ScreenQuad, screenIdentification.Screen.QuadInCamera);
 
         }
@@ -463,7 +469,7 @@ public partial class ScreenLocate : MonoBehaviour
             CreateUVCTexture2DIfNeeded((int)getUVCCameraInfoSize.x, (int)getUVCCameraInfoSize.y);
             if (!screenIdentification.Update(mUVCTexture2D))
             {
-                CameraSize = new o0.Geometry2D.Vector<int>((int)getUVCCameraInfoSize.x, (int)getUVCCameraInfoSize.y);
+                CameraSize = new o0.Geometry2D.Vector<int>(mUVCTexture2D.width, mUVCTexture2D.height);
                 var pixels = mUVCTexture2D.GetPixels();       // 从左往右、从下往上
 
                 AutoLightPixels(pixels, CameraSize.x, CameraSize.y);
@@ -588,7 +594,7 @@ public partial class ScreenLocate : MonoBehaviour
                     }
 
                 }
-                else if (mode == Mode.ScreenMap && DebugOnEditorWin)
+                else if (mode == Mode.ScreenMap && DebugOnZIMDemo)
                 {
                     for (int i = 0; i < infraredSpotBuffer.Length; i++)
                     {
@@ -739,7 +745,7 @@ public partial class ScreenLocate : MonoBehaviour
         Vector2 _HighResolution = mUVCCameraInfo.CurrentCalibrationResolution; //最高的分辨率
         Resize((int)_HighResolution.x, (int)_HighResolution.y);
 
-        if (DebugOnEditorWin)
+        if (DebugOnZIMDemo)
             screenIdentification.LocateScreen();
 
         //CreateUVCTexture2DIfNeeded();
@@ -906,7 +912,7 @@ public partial class ScreenLocate : MonoBehaviour
             ScreenQuadObject.gameObject.SetActive(true);
             for (int i = 0; i < 4; i++)
             {
-                if (DebugOnEditorWin)
+                if (DebugOnZIMDemo)
                 {
                     RectTransform t = ScreenQuadObject.GetChild(i) as RectTransform;
                     t.anchoredPosition = screen.Quad[i].pixelToLocalPosition_AnchorCenter(screen.CameraSize, ScreenQuadObject.rect);
@@ -918,7 +924,7 @@ public partial class ScreenLocate : MonoBehaviour
         {
             SaveScreenLocateVectorList();
             //SyncInfraredDemo();
-            if (DebugOnEditorWin)
+            if (DebugOnZIMDemo)
                 SyncInfraredScreenPositioningView();
 
             InfraredCameraHelper?.InvokeOnUVCPosUpdate(quadUnityVectorList);

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

@@ -4854,7 +4854,7 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: 69761566ec3b1054fb4eaf1a515fa3ce, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
-  cameraIndex: 1
+  cameraIndex: 2
   width: 1280
   height: 720
   fps: 30

+ 1 - 1
Assets/SmartBow/Scripts/Views/InfraredViewParts/InfraredScreenPositioningView.cs

@@ -185,7 +185,7 @@ public class InfraredScreenPositioningView : JCUnityLib.ViewBase
 
     void Update()
     {
-        if (enterFromZimWebCamera && ScreenLocate.Main.DebugOnEditorWin) {
+        if (enterFromZimWebCamera && ScreenLocate.Main.DebugOnZIMDemo) {
             // ZimWebCamera场景测试
             rawImage.texture = ScreenLocate.Main.outputRawImages[7].texture;
             if (ScreenLocate.Main.infraredSpotBuffer[0].CameraLocation.HasValue)