Browse Source

改下参数

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

BIN
Assets/InfraredProject/WebCamera/Image/2-测试图片.png


+ 123 - 0
Assets/InfraredProject/WebCamera/Image/2-测试图片.png.meta

@@ -0,0 +1,123 @@
+fileFormatVersion: 2
+guid: 23ae41a042c184944bdd0ede090de3af
+TextureImporter:
+  internalIDToNameTable: []
+  externalObjects: {}
+  serializedVersion: 12
+  mipmaps:
+    mipMapMode: 0
+    enableMipMap: 0
+    sRGBTexture: 1
+    linearTexture: 0
+    fadeOut: 0
+    borderMipMap: 0
+    mipMapsPreserveCoverage: 0
+    alphaTestReferenceValue: 0.5
+    mipMapFadeDistanceStart: 1
+    mipMapFadeDistanceEnd: 3
+  bumpmap:
+    convertToNormalMap: 0
+    externalNormalMap: 0
+    heightScale: 0.25
+    normalMapFilter: 0
+  isReadable: 1
+  streamingMipmaps: 0
+  streamingMipmapsPriority: 0
+  vTOnly: 0
+  ignoreMasterTextureLimit: 0
+  grayScaleToAlpha: 0
+  generateCubemap: 6
+  cubemapConvolution: 0
+  seamlessCubemap: 0
+  textureFormat: 1
+  maxTextureSize: 2048
+  textureSettings:
+    serializedVersion: 2
+    filterMode: 1
+    aniso: 1
+    mipBias: 0
+    wrapU: 1
+    wrapV: 1
+    wrapW: 0
+  nPOTScale: 0
+  lightmap: 0
+  compressionQuality: 50
+  spriteMode: 1
+  spriteExtrude: 1
+  spriteMeshType: 1
+  alignment: 0
+  spritePivot: {x: 0.5, y: 0.5}
+  spritePixelsToUnits: 100
+  spriteBorder: {x: 0, y: 0, z: 0, w: 0}
+  spriteGenerateFallbackPhysicsShape: 1
+  alphaUsage: 1
+  alphaIsTransparency: 1
+  spriteTessellationDetail: -1
+  textureType: 8
+  textureShape: 1
+  singleChannelComponent: 0
+  flipbookRows: 1
+  flipbookColumns: 1
+  maxTextureSizeSet: 0
+  compressionQualitySet: 0
+  textureFormatSet: 0
+  ignorePngGamma: 0
+  applyGammaDecoding: 0
+  cookieLightType: 0
+  platformSettings:
+  - serializedVersion: 3
+    buildTarget: DefaultTexturePlatform
+    maxTextureSize: 2048
+    resizeAlgorithm: 0
+    textureFormat: -1
+    textureCompression: 1
+    compressionQuality: 50
+    crunchedCompression: 0
+    allowsAlphaSplitting: 0
+    overridden: 0
+    androidETC2FallbackOverride: 0
+    forceMaximumCompressionQuality_BC6H_BC7: 0
+  - serializedVersion: 3
+    buildTarget: Standalone
+    maxTextureSize: 2048
+    resizeAlgorithm: 0
+    textureFormat: -1
+    textureCompression: 1
+    compressionQuality: 50
+    crunchedCompression: 0
+    allowsAlphaSplitting: 0
+    overridden: 0
+    androidETC2FallbackOverride: 0
+    forceMaximumCompressionQuality_BC6H_BC7: 0
+  - serializedVersion: 3
+    buildTarget: Android
+    maxTextureSize: 2048
+    resizeAlgorithm: 0
+    textureFormat: -1
+    textureCompression: 1
+    compressionQuality: 50
+    crunchedCompression: 0
+    allowsAlphaSplitting: 0
+    overridden: 0
+    androidETC2FallbackOverride: 0
+    forceMaximumCompressionQuality_BC6H_BC7: 0
+  spriteSheet:
+    serializedVersion: 2
+    sprites: []
+    outline: []
+    physicsShape: []
+    bones: []
+    spriteID: 5e97eb03825dee720800000000000000
+    internalID: 0
+    vertices: []
+    indices: 
+    edges: []
+    weights: []
+    secondaryTextures: []
+    nameFileIdTable: {}
+  spritePackingTag: 
+  pSDRemoveMatte: 0
+  pSDShowRemoveMatteOption: 0
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 2 - 3
Assets/InfraredProject/WebCamera/Script/ZIM/InfraredLocate/ScreenIdentification.cs

@@ -87,7 +87,7 @@ namespace o0.Project
         public bool bStartLocateScreen { get; set; } = false;//是否进行捕获
 
         // 自动识别开始的入口
-        public void LocateScreen(int Capture = 30, int Delay = 30)  //数值单位是frame
+        public void LocateScreen(int Capture = 45, int Delay = 45)  //数值单位是frame
         {
             if (ScreenLocate.Main.DebugScreenImage != null && ScreenLocate.Main.DebugOnZIMDemo)     // 这段仅用于测试图片
             {
@@ -659,10 +659,9 @@ namespace o0.Project
 
             //var (edge, edgeDir) = ScreenLocateTexLightedMat.IdentifyEdge();
             int conSize = (int)Math.Ceiling(0.007f * Size.y) * 2 + 1;
-            float minLength = conSize * 1.2f;
             conSize = Math.Max(conSize, 7);     // 设置最小为7
-            minLength = Math.Max(conSize, 10);     // 设置最小为10
 
+            float minLength = conSize * 7.7f;
             minLength = locateIndex == -1 ? minLength : minLength * areaPercent;    // minLength需要按比例缩小
             Debug.Log($"[ScreenIdentification] Size: ({Size.x},{Size.y}), 卷积核Size: {conSize}, 最小线段长度: {minLength}");
             var (edge, edgeDir) = ScreenLocateTexLightedMat.zimIdentifyEdgeGradientAny(conSize);

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

@@ -278,6 +278,8 @@ public partial class ScreenLocate : MonoBehaviour
     {
         //mainContext = SynchronizationContext.Current;
 
+        // 设置目标帧率为60
+        Application.targetFrameRate = 60;
         canvas = transform.GetComponent<RectTransform>();
 
         mode = Mode.InfraredLocate;

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

@@ -1036,7 +1036,7 @@ RectTransform:
   m_ConstrainProportionsScale: 0
   m_Children: []
   m_Father: {fileID: 1867793102}
-  m_RootOrder: 8
+  m_RootOrder: 10
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0.5, y: 0.5}
   m_AnchorMax: {x: 0.5, y: 0.5}
@@ -1190,7 +1190,7 @@ RectTransform:
   - {fileID: 1731784227}
   - {fileID: 619252550}
   m_Father: {fileID: 1867793102}
-  m_RootOrder: 13
+  m_RootOrder: 2
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0.5, y: 0.5}
   m_AnchorMax: {x: 0.5, y: 0.5}
@@ -1276,7 +1276,7 @@ RectTransform:
   m_ConstrainProportionsScale: 0
   m_Children: []
   m_Father: {fileID: 1867793102}
-  m_RootOrder: 11
+  m_RootOrder: 13
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 0.5}
   m_AnchorMax: {x: 0, y: 0.5}
@@ -1491,7 +1491,7 @@ RectTransform:
   - {fileID: 1190139017}
   - {fileID: 1120077961}
   m_Father: {fileID: 1867793102}
-  m_RootOrder: 12
+  m_RootOrder: 1
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0.5, y: 0.5}
   m_AnchorMax: {x: 0.5, y: 0.5}
@@ -1904,7 +1904,7 @@ RectTransform:
   m_ConstrainProportionsScale: 0
   m_Children: []
   m_Father: {fileID: 1867793102}
-  m_RootOrder: 6
+  m_RootOrder: 8
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0.5, y: 0.5}
   m_AnchorMax: {x: 0.5, y: 0.5}
@@ -3117,7 +3117,7 @@ RectTransform:
   m_Children:
   - {fileID: 713242658}
   m_Father: {fileID: 1867793102}
-  m_RootOrder: 7
+  m_RootOrder: 9
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0.5, y: 0.5}
   m_AnchorMax: {x: 0.5, y: 0.5}
@@ -3324,7 +3324,7 @@ RectTransform:
   m_ConstrainProportionsScale: 0
   m_Children: []
   m_Father: {fileID: 1867793102}
-  m_RootOrder: 9
+  m_RootOrder: 11
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0.5, y: 0.5}
   m_AnchorMax: {x: 0.5, y: 0.5}
@@ -3626,7 +3626,7 @@ RectTransform:
   m_ConstrainProportionsScale: 0
   m_Children: []
   m_Father: {fileID: 1867793102}
-  m_RootOrder: 5
+  m_RootOrder: 7
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0.5, y: 0.5}
   m_AnchorMax: {x: 0.5, y: 0.5}
@@ -4539,7 +4539,7 @@ RectTransform:
   - {fileID: 147698546}
   - {fileID: 1142717919}
   m_Father: {fileID: 1867793102}
-  m_RootOrder: 1
+  m_RootOrder: 3
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 0}
   m_AnchorMax: {x: 1, y: 0}
@@ -4814,6 +4814,8 @@ RectTransform:
   m_ConstrainProportionsScale: 0
   m_Children:
   - {fileID: 394028722}
+  - {fileID: 601288812}
+  - {fileID: 517576268}
   - {fileID: 1801784546}
   - {fileID: 1946863619}
   - {fileID: 2101632896}
@@ -4825,8 +4827,6 @@ RectTransform:
   - {fileID: 1309947137}
   - {fileID: 3098480069149916812}
   - {fileID: 557727041}
-  - {fileID: 601288812}
-  - {fileID: 517576268}
   - {fileID: 1438266374}
   - {fileID: 922494663}
   - {fileID: 1697954114}
@@ -4900,7 +4900,7 @@ MonoBehaviour:
   ScreenPixelCheaker: {fileID: 36100230}
   InfraredSpotSettings: {fileID: 11400000, guid: ca2f3b215f8d9d64caed905436a89b86, type: 2}
   DebugScreenImage: {fileID: 0}
-  DebugOnEditorWin: 1
+  DebugOnZIMDemo: 1
   bSinglePoint: 1
   m_UITime: {fileID: 849339071}
   updateInterval: 0.5
@@ -5005,7 +5005,7 @@ RectTransform:
   - {fileID: 228594326}
   - {fileID: 1289810228}
   m_Father: {fileID: 1867793102}
-  m_RootOrder: 2
+  m_RootOrder: 4
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 1}
   m_AnchorMax: {x: 1, y: 1}
@@ -5153,7 +5153,7 @@ RectTransform:
   m_ConstrainProportionsScale: 0
   m_Children: []
   m_Father: {fileID: 1867793102}
-  m_RootOrder: 4
+  m_RootOrder: 6
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0.5, y: 0.5}
   m_AnchorMax: {x: 0.5, y: 0.5}
@@ -5231,7 +5231,7 @@ RectTransform:
   - {fileID: 681002957}
   - {fileID: 1922585532}
   m_Father: {fileID: 1867793102}
-  m_RootOrder: 3
+  m_RootOrder: 5
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0.5, y: 0.5}
   m_AnchorMax: {x: 0.5, y: 0.5}
@@ -5313,7 +5313,7 @@ RectTransform:
   m_ConstrainProportionsScale: 0
   m_Children: []
   m_Father: {fileID: 1867793102}
-  m_RootOrder: 10
+  m_RootOrder: 12
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0.5, y: 0.5}
   m_AnchorMax: {x: 0.5, y: 0.5}

+ 9 - 6
Assets/InfraredProject/o0/zimIdentifyLineLSD.cs

@@ -11,6 +11,7 @@ using ZIM;
 using ZIM.Unity;
 using o0.Num;
 using o0.Geometry2D;
+using System.Drawing.Drawing2D;
 
 namespace o0.Project
 {
@@ -141,8 +142,8 @@ namespace o0.Project
             for (int i = 0; i < lines.Count; i++)
                 lines[i] = (lines[i].Item1 + offset, lines[i].Item2, lines[i].Item3);
 
-            // 沿直线计算平均梯度
-            float averageGradient(Line line)
+            // 沿直线计算综合梯度(梯度乘以长度系数)
+            float estimateGradient(Line line)
             {
                 var dir = (line.B - line.A).Normalized;
                 var vertical = new Vector(-dir.y, dir.x) * (gradientLength / 2);
@@ -156,7 +157,9 @@ namespace o0.Project
                     var gb = point - vertical;
                     lg.Add(screenLocateMat[(int)ga.x, (int)ga.y] - screenLocateMat[(int)gb.x, (int)gb.y]);
                 }
-                return Math.Abs(lg.Mean());
+
+                float e = (float)Math.Sqrt(Math.Max(1, line.Length / minLength / 3));       // 长度系数,筛选时梯度更大、长度更长的线段更优
+                return e * Math.Abs(lg.Mean());
             }
 
             // 下、右、上、左
@@ -191,7 +194,7 @@ namespace o0.Project
                     //Debug.Log(minDistance +", -----------"+ calibration);
                     if (minDistance < calibration)      // 垂足的距离足够近
                     {
-                        quadLines[index].Add((averageGradient(i.Item1), i.Item1));
+                        quadLines[index].Add((estimateGradient(i.Item1), i.Item1));
                         lightLines.Add(i.Item1);
                     }
                 }
@@ -242,7 +245,7 @@ namespace o0.Project
 
                         //quadLines[index].Add((lineGradient, line));
 
-                        quadLines[index].Add((averageGradient(line), line));
+                        quadLines[index].Add((estimateGradient(line), line));
                     }
                 }
             }
@@ -251,7 +254,7 @@ namespace o0.Project
             for (int i = 0; i < 4; i++)
             {
                 if (quadLines[i].Count > 0)
-                    result[i] = quadLines[i].Max((a, b) => a.Item1.CompareTo(b.Item1)).Item2;
+                    result[i] = quadLines[i].Max((a, b) =>a.Item1.CompareTo(b.Item1)).Item2;
             }
             return result.ToList();
         }