Procházet zdrojové kódy

1.修复图像识别线框选择

slambb před 1 rokem
rodič
revize
7593e2cda2

+ 2 - 2
Assets/BowArrow/InfraredCamera/InfraredDemo.cs

@@ -581,8 +581,8 @@ public class InfraredDemo : MonoBehaviour
             //屏幕变化时候
             //屏幕变化时候
             infraredCameraHelper.OnUVCPosUpdate += (list) =>
             infraredCameraHelper.OnUVCPosUpdate += (list) =>
             {
             {
-                Debug.Log("OnUVCPosUpdate");
-                 SetLocatePointsToCameraRender(list, 1, 1);
+                Debug.Log("OnUVCPosUpdate list.Count" + list.Count);
+                SetLocatePointsToCameraRender(list, 1, 1);
                 //InfraredScreenPositioningView 页面
                 //InfraredScreenPositioningView 页面
                 if (list.Count == 4)
                 if (list.Count == 4)
                 {
                 {

+ 1 - 2
Assets/InfraredProject/InfraredCamera/Scripts/InfraredCameraHelper.cs

@@ -333,10 +333,9 @@ namespace InfraredManager
         public delegate void OnUVCPosUpdateEvent(List<Vector2> list);
         public delegate void OnUVCPosUpdateEvent(List<Vector2> list);
         public void InvokeOnUVCPosUpdate(List<Vector2> list)
         public void InvokeOnUVCPosUpdate(List<Vector2> list)
         {
         {
-            OnUVCPosUpdate?.Invoke(list);
             try
             try
             {
             {
-             
+                OnUVCPosUpdate?.Invoke(list);
             }
             }
             catch (Exception e)
             catch (Exception e)
             {
             {

+ 2 - 2
Assets/InfraredProject/InfraredCamera/Scripts/ScreenLocate.cs

@@ -87,8 +87,8 @@ public partial class ScreenLocate : MonoBehaviour
     public void EnterScreenLocateManualAuto()
     public void EnterScreenLocateManualAuto()
     {
     {
         //自动定位时候,清除一下记录的点
         //自动定位时候,清除一下记录的点
-        quadUnityVectorList.Clear();
-        InfraredCameraHelper?.InvokeOnUVCPosUpdate(quadUnityVectorList);
+        //quadUnityVectorList.Clear();
+        //InfraredCameraHelper?.InvokeOnUVCPosUpdate(quadUnityVectorList);
         BtnScreenLocate();
         BtnScreenLocate();
     }
     }
     /// <summary>
     /// <summary>

+ 8 - 1
Assets/InfraredProject/WebCamera/Script/ZIM/ScreenLocate.cs

@@ -394,7 +394,14 @@ public partial class ScreenLocate : MonoBehaviour
                 infraredLocate.SetBrightnessThreshold(value);     // 参数是 红外灯的亮度阈值,阈值越小能够检测到的亮度就越低,默认值是0.93
                 infraredLocate.SetBrightnessThreshold(value);     // 参数是 红外灯的亮度阈值,阈值越小能够检测到的亮度就越低,默认值是0.93
         }
         }
     }
     }
-
+    /// <summary>
+    /// 选择模式后更新 quadUnityVectorList
+    /// </summary>
+    public void UpdateQuadUnityVectorList()
+    {
+        quadUnityVectorList = screenIdentification.Screen.QuadInCamera.GetUnityVertexNormalizedList();
+        SaveScreenLocateVectorList();
+    }
     void Update()
     void Update()
     {
     {
         //++frames;
         //++frames;

+ 92 - 29
Assets/SmartBow/Scripts/Views/InfraredViewParts/InfraredScreenPositioningView.cs

@@ -153,12 +153,12 @@ public class InfraredScreenPositioningView : JCUnityLib.ViewBase
         {
         {
             Vector2 texSize = ScreenLocate.Main.getUVCCameraInfoSize;
             Vector2 texSize = ScreenLocate.Main.getUVCCameraInfoSize;
             Debug.Log("texSize:" + texSize + " = " + canvasRectTransform.rect);
             Debug.Log("texSize:" + texSize + " = " + canvasRectTransform.rect);
-
             //自动识别时候四个点
             //自动识别时候四个点
-            pos1.anchoredPosition = ScreenLocate.quadUnityVectorList[0].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
-            pos2.anchoredPosition = ScreenLocate.quadUnityVectorList[1].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
-            pos4.anchoredPosition = ScreenLocate.quadUnityVectorList[2].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
-            pos3.anchoredPosition = ScreenLocate.quadUnityVectorList[3].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
+            SyncQuadUnityVectorListToPos();
+            //pos1.anchoredPosition = ScreenLocate.quadUnityVectorList[0].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
+            //pos2.anchoredPosition = ScreenLocate.quadUnityVectorList[1].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
+            //pos4.anchoredPosition = ScreenLocate.quadUnityVectorList[2].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
+            //pos3.anchoredPosition = ScreenLocate.quadUnityVectorList[3].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
         }
         }
 
 
 
 
@@ -174,6 +174,9 @@ public class InfraredScreenPositioningView : JCUnityLib.ViewBase
 
 
             //重置识别点
             //重置识别点
             ScreenLocate.Main.ScreenIdentification.ClearQuadCache();
             ScreenLocate.Main.ScreenIdentification.ClearQuadCache();
+            //清除一下记录的点
+            ScreenLocate.quadUnityVectorList.Clear();
+
 
 
             slider.onValueChanged.AddListener((value) =>
             slider.onValueChanged.AddListener((value) =>
             {
             {
@@ -343,10 +346,11 @@ public class InfraredScreenPositioningView : JCUnityLib.ViewBase
         Vector2 texSize = ScreenLocate.Main.getUVCCameraInfoSize;
         Vector2 texSize = ScreenLocate.Main.getUVCCameraInfoSize;
         Debug.Log("texSize:" + texSize + " = " + canvasRectTransform.rect);
         Debug.Log("texSize:" + texSize + " = " + canvasRectTransform.rect);
         //自动识别时候四个点
         //自动识别时候四个点
-        pos1.anchoredPosition = ScreenLocate.quadUnityVectorList[0].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
-        pos2.anchoredPosition = ScreenLocate.quadUnityVectorList[1].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
-        pos4.anchoredPosition = ScreenLocate.quadUnityVectorList[2].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
-        pos3.anchoredPosition = ScreenLocate.quadUnityVectorList[3].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
+        //pos1.anchoredPosition = ScreenLocate.quadUnityVectorList[0].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
+        //pos2.anchoredPosition = ScreenLocate.quadUnityVectorList[1].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
+        //pos4.anchoredPosition = ScreenLocate.quadUnityVectorList[2].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
+        //pos3.anchoredPosition = ScreenLocate.quadUnityVectorList[3].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
+        SyncQuadUnityVectorListToPos();
 
 
         SetRectanglePoints(linePosConversion(pos1.localPosition, pos2.localPosition, pos3.localPosition, pos4.localPosition));
         SetRectanglePoints(linePosConversion(pos1.localPosition, pos2.localPosition, pos3.localPosition, pos4.localPosition));
 
 
@@ -371,29 +375,39 @@ public class InfraredScreenPositioningView : JCUnityLib.ViewBase
         QuadrilateralInCamera screenAuto = ScreenLocate.Main.ScreenIdentification.QuadAuto;
         QuadrilateralInCamera screenAuto = ScreenLocate.Main.ScreenIdentification.QuadAuto;
         QuadrilateralInCamera screenSemiAuto = ScreenLocate.Main.ScreenIdentification.QuadSemiAuto;
         QuadrilateralInCamera screenSemiAuto = ScreenLocate.Main.ScreenIdentification.QuadSemiAuto;
 
 
-        var size = ScreenLocate.Main.getUVCCameraInfoSize;
         var lo = new Vector2(-0.5f, -0.5f);
         var lo = new Vector2(-0.5f, -0.5f);
         if (screenAuto != null)
         if (screenAuto != null)
         {
         {
             FirstUILineGenerator.Points = new Vector2[4] {
             FirstUILineGenerator.Points = new Vector2[4] {
-                2 * (new Vector2(screenAuto.Quad[0].x/size.x,screenAuto.Quad[0].y/size.y) + lo),
-                2 * (new Vector2(screenAuto.Quad[1].x/size.x,screenAuto.Quad[1].y/size.y) + lo),
-                2 * (new Vector2(screenAuto.Quad[3].x/size.x,screenAuto.Quad[3].y/size.y) + lo),
-                2 * (new Vector2(screenAuto.Quad[2].x/size.x,screenAuto.Quad[2].y/size.y) + lo) };
+                2 * (new Vector2(screenAuto.Quad[0].x/texSize.x,screenAuto.Quad[0].y/texSize.y) + lo),
+                2 * (new Vector2(screenAuto.Quad[1].x/texSize.x,screenAuto.Quad[1].y/texSize.y) + lo),
+                2 * (new Vector2(screenAuto.Quad[3].x/texSize.x,screenAuto.Quad[3].y/texSize.y) + lo),
+                2 * (new Vector2(screenAuto.Quad[2].x/texSize.x,screenAuto.Quad[2].y/texSize.y) + lo) };
 
 
+            // 打印 Points 的值,合并为一个字符串
+            string pointsOutput = "1 Points: ";
             for (int i = 0; i < FirstUILineGenerator.Points.Length; i++)
             for (int i = 0; i < FirstUILineGenerator.Points.Length; i++)
             {
             {
-                Debug.Log("Point " + i + ": " + FirstUILineGenerator.Points[i]);
+                pointsOutput += "[" + FirstUILineGenerator.Points[i].x + ", " + FirstUILineGenerator.Points[i].y + "]";
+                if (i < FirstUILineGenerator.Points.Length - 1)
+                {
+                    pointsOutput += ", "; // 添加逗号分隔符,最后一个元素后不加
+                }
             }
             }
-            // 打印 Quad 的值,使用自定义顺序访问
+            Debug.Log(pointsOutput);
+
+            // 打印 Quad 的值,合并为一个字符串
             int[] customOrder = new int[] { 0, 1, 3, 2 };
             int[] customOrder = new int[] { 0, 1, 3, 2 };
-            for (int i = 0; i < 4; i++)
+            string quadOutput = "1 Quad Points: ";
+            for (int i = 0; i < customOrder.Length; i++)
             {
             {
-                Debug.Log("Quad Point " + i + " (Index " + customOrder[i] + "): " + "["+ screenAuto.Quad[customOrder[i]].x + ","+ screenAuto.Quad[customOrder[i]].y + "]");
+                quadOutput += "[" + screenAuto.Quad[customOrder[i]].x + ", " + screenAuto.Quad[customOrder[i]].y + "]";
+                if (i < customOrder.Length - 1)
+                {
+                    quadOutput += ", "; // 添加逗号分隔符,最后一个元素后不加
+                }
             }
             }
-            // 打印 CameraSize 的值
-            Debug.Log("size: " + size);
-
+            Debug.Log(quadOutput);
 
 
         }
         }
         else {
         else {
@@ -402,15 +416,43 @@ public class InfraredScreenPositioningView : JCUnityLib.ViewBase
         if (screenSemiAuto != null)
         if (screenSemiAuto != null)
         {
         {
             SecondUILineGenerator.Points = new Vector2[4] {
             SecondUILineGenerator.Points = new Vector2[4] {
-                2 * (new Vector2(screenSemiAuto.Quad[0].x/size.x,screenSemiAuto.Quad[0].y/size.y) + lo),
-                2 * (new Vector2(screenSemiAuto.Quad[1].x/size.x,screenSemiAuto.Quad[1].y/size.y) + lo),
-                2 * (new Vector2(screenSemiAuto.Quad[3].x/size.x,screenSemiAuto.Quad[3].y/size.y) + lo),
-                2 * (new Vector2(screenSemiAuto.Quad[2].x/size.x,screenSemiAuto.Quad[2].y/size.y) + lo) };
+                2 * (new Vector2(screenSemiAuto.Quad[0].x/texSize.x,screenSemiAuto.Quad[0].y/texSize.y) + lo),
+                2 * (new Vector2(screenSemiAuto.Quad[1].x/texSize.x,screenSemiAuto.Quad[1].y/texSize.y) + lo),
+                2 * (new Vector2(screenSemiAuto.Quad[3].x/texSize.x,screenSemiAuto.Quad[3].y/texSize.y) + lo),
+                2 * (new Vector2(screenSemiAuto.Quad[2].x/texSize.x,screenSemiAuto.Quad[2].y/texSize.y) + lo) };
+
+            // 打印 Points 的值,合并为一个字符串
+            string pointsOutput = "2 Points: ";
+            for (int i = 0; i < SecondUILineGenerator.Points.Length; i++)
+            {
+                pointsOutput += "[" + SecondUILineGenerator.Points[i].x + ", " + SecondUILineGenerator.Points[i].y + "]";
+                if (i < SecondUILineGenerator.Points.Length - 1)
+                {
+                    pointsOutput += ", "; // 添加逗号分隔符,最后一个元素后不加
+                }
+            }
+            Debug.Log(pointsOutput);
+
+            // 打印 Quad 的值,合并为一个字符串
+            int[] customOrder = new int[] { 0, 1, 3, 2 };
+            string quadOutput = "2 Quad Points: ";
+            for (int i = 0; i < customOrder.Length; i++)
+            {
+                quadOutput += "[" + screenSemiAuto.Quad[customOrder[i]].x + ", " + screenSemiAuto.Quad[customOrder[i]].y + "]";
+                if (i < customOrder.Length - 1)
+                {
+                    quadOutput += ", "; // 添加逗号分隔符,最后一个元素后不加
+                }
+            }
+            Debug.Log(quadOutput);
+
         }
         }
         else {
         else {
             Debug.LogError("screenSemiAuto 不存在!");
             Debug.LogError("screenSemiAuto 不存在!");
         }
         }
-      
+
+
+
     }
     }
 
 
     #region 绘制线段部分
     #region 绘制线段部分
@@ -972,15 +1014,16 @@ public class InfraredScreenPositioningView : JCUnityLib.ViewBase
     //选择全自动结果后进入游戏
     //选择全自动结果后进入游戏
     void OnFirstResult()
     void OnFirstResult()
     {
     {
-       // ScreenLocate.Main.SelectScreenAfterLocate(ScreenLocate.ScreenIdentificationTag.Auto);
-        
+        ScreenLocate.Main.SelectScreenAfterLocate(ScreenLocate.ScreenIdentificationTag.Auto);
+        UpdateQuadUnityVectorList();
         onCompelete();
         onCompelete();
     }
     }
 
 
     //选择半自动结果
     //选择半自动结果
     void OnSecondResult()
     void OnSecondResult()
     {
     {
-        //ScreenLocate.Main.SelectScreenAfterLocate(ScreenLocate.ScreenIdentificationTag.SemiAuto);
+        ScreenLocate.Main.SelectScreenAfterLocate(ScreenLocate.ScreenIdentificationTag.SemiAuto);
+        UpdateQuadUnityVectorList();
 
 
         onCompelete();
         onCompelete();
     }
     }
@@ -1022,5 +1065,25 @@ public class InfraredScreenPositioningView : JCUnityLib.ViewBase
         SaveLocalPos();
         SaveLocalPos();
     }
     }
 
 
+    /// <summary>
+    /// 选择模式后更新 quadUnityVectorList
+    /// </summary>
+    void UpdateQuadUnityVectorList() {
+
+        ScreenLocate.Main.UpdateQuadUnityVectorList();
+        SyncQuadUnityVectorListToPos();
+        InfraredDemo._ins?.SetLocatePointsToCameraRender(ScreenLocate.quadUnityVectorList, 1, 1);
+        _locatePointList.Clear();
+        
+    }
+
+    void SyncQuadUnityVectorListToPos() {
+        Debug.Log("[ScreenLocate] SyncQuadUnityVectorListToPos quadUnityVectorList:" + ScreenLocate.Main.PrintVector2List(ScreenLocate.quadUnityVectorList));
+        pos1.anchoredPosition = ScreenLocate.quadUnityVectorList[0].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
+        pos2.anchoredPosition = ScreenLocate.quadUnityVectorList[1].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
+        pos4.anchoredPosition = ScreenLocate.quadUnityVectorList[2].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
+        pos3.anchoredPosition = ScreenLocate.quadUnityVectorList[3].pixelToLocalPosition_AnchorCenter(Vector2.one, canvasRectTransform.rect);
+    }
+
     #endregion
     #endregion
 }
 }