Browse Source

增加“加载数据”按钮

ZIM 1 năm trước cách đây
mục cha
commit
789e767ff3

+ 1 - 3
Assets/InfraredProject/InfraredCamera/Scripts/ScreenLocate.cs

@@ -44,9 +44,7 @@ public partial class ScreenLocate : MonoBehaviour
               new o0.Geometry2D.Float.Vector(points[2].x * size.x, points[2].y * size.y),
               size.o0Vector());
 
-            //screenIdentification?.SetScreenQuad(quad);
-            screenIdentification.QuadManual = quad;
-            Debug.Log($"[ScreenLocate] 记录手动数据: {quad}");
+            screenIdentification?.SetScreenQuad(quad);
         }
         ToMode(Mode.InfraredLocate);
     }

+ 12 - 7
Assets/InfraredProject/WebCamera/Script/ZIM/InfraredLocate/ScreenIdentification.cs

@@ -97,13 +97,7 @@ namespace o0.Project
 
         public bool SelectScreenAfterLocate(ScreenLocate.ScreenIdentificationTag tag)
         {
-            QuadrilateralInCamera target = tag switch
-            {
-                ScreenLocate.ScreenIdentificationTag.Manual => QuadManual,
-                ScreenLocate.ScreenIdentificationTag.SemiAuto => QuadSemiAuto,
-                ScreenLocate.ScreenIdentificationTag.Auto => QuadAuto,
-                _ => null
-            };
+            QuadrilateralInCamera target = GetScreenAfterLocate(tag);
 
             if (target == null)
                 return false;
@@ -112,6 +106,17 @@ namespace o0.Project
             return true;
         }
 
+        public QuadrilateralInCamera GetScreenAfterLocate(ScreenLocate.ScreenIdentificationTag tag)
+        {
+            return tag switch
+            {
+                ScreenLocate.ScreenIdentificationTag.Manual => QuadManual,
+                ScreenLocate.ScreenIdentificationTag.SemiAuto => QuadSemiAuto,
+                ScreenLocate.ScreenIdentificationTag.Auto => QuadAuto,
+                _ => null
+            };
+        }
+
         // 自动识别开始的入口
         public void LocateScreen(int Capture = 30, int Delay = 30)  //数值单位是frame
         {

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

@@ -73,6 +73,10 @@ public partial class ScreenLocate : MonoBehaviour
     /// 如果选择的是null,即没有识别到屏幕,则返回false,否则返回true
     /// </summary>
     public bool SelectScreenAfterLocate(ScreenIdentificationTag tag) => ScreenIdentification.SelectScreenAfterLocate(tag);
+    /// <summary>
+    /// 定位之后,获取定位数据,返回null代表没有数据
+    /// </summary>
+    public QuadrilateralInCamera GetScreenAfterLocate(ScreenIdentificationTag tag) => ScreenIdentification.GetScreenAfterLocate(tag);
 
     /// <summary>
     /// 上一次半自动识别的情况, 还未识别的时候数组是null

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 907 - 70
Assets/SmartBow/Resources/SmartBow/Prefabs/Views/Home/InfraredScreenPositioningView.prefab


+ 93 - 23
Assets/SmartBow/Scripts/Views/InfraredViewParts/InfraredScreenPositioningView.cs

@@ -11,6 +11,8 @@ using InfraredManager;
 using Org.BouncyCastle.Asn1.Crmf;
 using ZIM.Unity;
 using o0.Project;
+using System;
+using o0.Num;
 
 public class LinePosition
 {
@@ -73,6 +75,8 @@ public class InfraredScreenPositioningView : JCUnityLib.ViewBase
     [SerializeField] Color normalTextColor = Color.black;
     [SerializeField] Color highlightedTextColor = Color.white;
 
+    [SerializeField] Text QuadInfo;
+
     bool doLocateAuto;
 
     int DefaultResolutionIndex;
@@ -99,29 +103,20 @@ public class InfraredScreenPositioningView : JCUnityLib.ViewBase
         //手动不高亮
         //ResetButton(btnHandMovement);
 
-        //quadUnityVectorList.Clear();
-        //quadUnityVectorList.Add(new Vector2(16.39f, 35.91f));
-        //quadUnityVectorList.Add(new Vector2(233.35f, 51.08f));
-        //quadUnityVectorList.Add(new Vector2(94.15f, 219.11f));
-        //quadUnityVectorList.Add(new Vector2(243.12f, 237.40f));
-        Debug.Log("quadUnityVectorList count:" + ScreenLocate.quadUnityVectorList.Count);
-        if (ScreenLocate.quadUnityVectorList.Count == 0)
-        {
-            Debug.Log("GetLocalPos");
-            GetLocalPos();
-        }
-        else
-        {
-            Vector2 texSize = ScreenLocate.Main.getUVCCameraInfoSize;
-            Debug.Log("texSize:" + texSize + " = " + 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);
-        }
-
+        Debug.Log("GetDefalutPos");     // ZIM 改成加载默认(读数据或者手动数据)
+        GetDefalutPos();
+        //if (ScreenLocate.quadUnityVectorList.Count == 0)
+        //{
+        //    Debug.Log("GetLocalPos");
+        //    GetLocalPos();
+        //}
+        //else
+        //{
+        //    Vector2 texSize = ScreenLocate.Main.getUVCCameraInfoSize;
+        //    Debug.Log("texSize:" + texSize + " = " + canvasRectTransform.rect);
+        //    //自动识别时候四个点
+        //    SyncQuadUnityVectorListToPos();
+        //}
 
         //记录操作的位置信息
         oldLinePosition = new List<LinePosition>();
@@ -181,6 +176,11 @@ public class InfraredScreenPositioningView : JCUnityLib.ViewBase
 
         }
 
+        if (ScreenLocate.Main.DebugOnZIMDemo)
+        {
+            onHandMovement();       // 默认启用手动定位
+            GameObject.Find("DropdownQuad").GetComponent<Dropdown>().onValueChanged.AddListener(OnLoadQuadChanged);
+        }
 
         //if (ScreenLocate.Main.getUVCTexture)
         //{
@@ -526,6 +526,31 @@ public class InfraredScreenPositioningView : JCUnityLib.ViewBase
         }
     }
 
+    // by zim, 加载数据
+    public void OnLoadQuadChanged(int value)
+    {
+        if (!doLocateAuto)
+        {
+            var quadTag = value switch
+            {
+                0 => ScreenLocate.ScreenIdentificationTag.Manual,
+                1 => ScreenLocate.ScreenIdentificationTag.Auto,
+                2 => ScreenLocate.ScreenIdentificationTag.SemiAuto,
+                _ => ScreenLocate.ScreenIdentificationTag.Manual,
+            };
+
+            var quad = ScreenLocate.Main.GetScreenAfterLocate(quadTag);
+            if (quad != null)
+            {
+                AddOldLinePosition();
+                GetQuadPos(quad);
+                QuadInfo.text = "加载成功";
+            }
+            else
+                QuadInfo.text = "加载失败";
+        }
+    }
+
     #endregion
 
 
@@ -607,8 +632,25 @@ public class InfraredScreenPositioningView : JCUnityLib.ViewBase
 
         setPointsLocation(_locatePointList,pointsParent.gameObject,!bAuto);
         if (!doLocateAuto)  // 设置手动定位数据
+        {
             setPointsManual(_locatePointList, GameObject.Find("WebCameraView/CameraImage0/ScreenQuad"));
 
+            var size = ScreenLocate.Main.getUVCCameraInfoSize;
+            var quad = new QuadrilateralInCamera(
+              new o0.Geometry2D.Float.Vector(_locatePointList[0].x * size.x, _locatePointList[0].y * size.y),
+              new o0.Geometry2D.Float.Vector(_locatePointList[1].x * size.x, _locatePointList[1].y * size.y),
+              new o0.Geometry2D.Float.Vector(_locatePointList[3].x * size.x, _locatePointList[3].y * size.y),
+              new o0.Geometry2D.Float.Vector(_locatePointList[2].x * size.x, _locatePointList[2].y * size.y),
+              size.o0Vector());
+
+            if (ScreenLocate.Main.ScreenIdentification!=null)
+            {
+                ScreenLocate.Main.ScreenIdentification.SetScreenQuad(quad);
+                ScreenLocate.Main.ScreenIdentification.QuadManual = quad;
+                Debug.Log($"[ScreenLocate] 记录手动数据: {quad}");
+            }
+        }
+
         //同步数据
         ScreenLocate.quadUnityVectorList.Clear();
         ScreenLocate.quadUnityVectorList.Add(new Vector2(_locatePointList[0].x, _locatePointList[0].y));
@@ -663,6 +705,34 @@ public class InfraredScreenPositioningView : JCUnityLib.ViewBase
 
     }
 
+    // by zim
+    void GetDefalutPos()
+    {
+        if (ScreenLocate.Main.DebugOnZIMDemo)
+        {
+            var quad = ScreenLocate.Main.GetScreenAfterLocate(ScreenLocate.ScreenIdentificationTag.Manual);
+            if (quad != null)
+                GetQuadPos(quad);
+            else
+                GetLocalPos();
+        }
+        else
+            GetLocalPos();
+    }
+
+    void GetQuadPos(QuadrilateralInCamera quad)
+    {
+        var qPos1 = quad.Quad.A.pixelToLocalPosition_AnchorCenter(quad.CameraSize, Bg.rectTransform.rect);
+        var qPos2 = quad.Quad.B.pixelToLocalPosition_AnchorCenter(quad.CameraSize, Bg.rectTransform.rect);
+        var qPos4 = quad.Quad.C.pixelToLocalPosition_AnchorCenter(quad.CameraSize, Bg.rectTransform.rect);
+        var qPos3 = quad.Quad.D.pixelToLocalPosition_AnchorCenter(quad.CameraSize, Bg.rectTransform.rect);
+        pos1.anchoredPosition = qPos1;
+        pos2.anchoredPosition = qPos2;
+        pos3.anchoredPosition = qPos3;
+        pos4.anchoredPosition = qPos4;
+        SetRectanglePoints(linePosConversion(qPos1, qPos2, qPos3, qPos4));
+    }
+
     void GetLocalPos()
     {
         string posListStr = PlayerPrefs.GetString("ScreenPositioningView", "");

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác