|
@@ -14,14 +14,6 @@ using Debug = UnityEngine.Debug;
|
|
|
|
|
|
|
|
namespace ZIM
|
|
namespace ZIM
|
|
|
{
|
|
{
|
|
|
- //class DescendingComparer<T> : IComparer<T>
|
|
|
|
|
- //{
|
|
|
|
|
- // public int Compare(T x, T y)
|
|
|
|
|
- // {
|
|
|
|
|
- // return Comparer<T>.Default.Compare(y, x);
|
|
|
|
|
- // }
|
|
|
|
|
- //}
|
|
|
|
|
-
|
|
|
|
|
public enum InfraredMatch
|
|
public enum InfraredMatch
|
|
|
{
|
|
{
|
|
|
Nomatch = 0,
|
|
Nomatch = 0,
|
|
@@ -112,7 +104,7 @@ namespace ZIM
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// New, 返回由大到小排序的点
|
|
// New, 返回由大到小排序的点
|
|
|
- public List<PixelSpotArea> LocateToScreen(Color[] pixels, Rect rect)
|
|
|
|
|
|
|
+ public List<ISpotArea> LocateToScreen(Color[] pixels, Rect rect)
|
|
|
{
|
|
{
|
|
|
if (!screenIdentification.Screen.Active)
|
|
if (!screenIdentification.Screen.Active)
|
|
|
rect = new Rect(0, 0, screenIdentification.Size.x, screenIdentification.Size.y);
|
|
rect = new Rect(0, 0, screenIdentification.Size.x, screenIdentification.Size.y);
|
|
@@ -172,12 +164,12 @@ namespace ZIM
|
|
|
// if (spotPoint.Count > 400) // 如果亮点太多,控制亮点数量在200左右
|
|
// if (spotPoint.Count > 400) // 如果亮点太多,控制亮点数量在200左右
|
|
|
// {
|
|
// {
|
|
|
// samplingScale = (int)Math.Ceiling(samplingScale * Math.Sqrt(spotPoint.Count / 400.0));
|
|
// samplingScale = (int)Math.Ceiling(samplingScale * Math.Sqrt(spotPoint.Count / 400.0));
|
|
|
- // return new List<PixelSpotArea>();
|
|
|
|
|
|
|
+ // return new List<ISpotArea>();
|
|
|
// }
|
|
// }
|
|
|
// else if (samplingScale > 1 && spotPoint.Count < 100)
|
|
// else if (samplingScale > 1 && spotPoint.Count < 100)
|
|
|
// {
|
|
// {
|
|
|
// samplingScale = Math.Max((int)Math.Ceiling(samplingScale * Math.Sqrt(spotPoint.Count / 200.0)), 1);
|
|
// samplingScale = Math.Max((int)Math.Ceiling(samplingScale * Math.Sqrt(spotPoint.Count / 200.0)), 1);
|
|
|
- // return new List<PixelSpotArea>();
|
|
|
|
|
|
|
+ // return new List<ISpotArea>();
|
|
|
// }
|
|
// }
|
|
|
//}
|
|
//}
|
|
|
|
|
|
|
@@ -230,29 +222,30 @@ namespace ZIM
|
|
|
return spotArea;
|
|
return spotArea;
|
|
|
|
|
|
|
|
//半径再按透视修正一遍,降低一点常规角度下反射的影响
|
|
//半径再按透视修正一遍,降低一点常规角度下反射的影响
|
|
|
- foreach (var i in spotArea)
|
|
|
|
|
- {
|
|
|
|
|
- var r0 = i.Radius / 2 / mCameraInfo.CurrentWidth;
|
|
|
|
|
- var center = i.Centroid;
|
|
|
|
|
- var offset1 = center + new Vector2(i.Radius / 2, 0);
|
|
|
|
|
- var offset2 = center - new Vector2(i.Radius / 2, 0);
|
|
|
|
|
- var offset3 = center + new Vector2(0, i.Radius / 2);
|
|
|
|
|
- var offset4 = center - new Vector2(0, i.Radius / 2);
|
|
|
|
|
- var transR = ((screenIdentification.Screen.TransformToScreen(offset1) - screenIdentification.Screen.TransformToScreen(offset2)).magnitude +
|
|
|
|
|
- (screenIdentification.Screen.TransformToScreen(offset3) - screenIdentification.Screen.TransformToScreen(offset4)).magnitude) / 4;
|
|
|
|
|
- var r1 = transR / screenIdentification.Screen.UVSize.x;
|
|
|
|
|
- //Debug.Log(r1 / r0);
|
|
|
|
|
- i.Radius *= (float)Math.Pow(r1 / r0, 2); // 摄像机位置不同参数也可能不同
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ //foreach (var i in spotArea)
|
|
|
|
|
+ //{
|
|
|
|
|
+ // var r0 = i.Radius / 2 / mCameraInfo.CurrentWidth;
|
|
|
|
|
+ // var center = i.Centroid;
|
|
|
|
|
+ // var offset1 = center + new Vector2(i.Radius / 2, 0);
|
|
|
|
|
+ // var offset2 = center - new Vector2(i.Radius / 2, 0);
|
|
|
|
|
+ // var offset3 = center + new Vector2(0, i.Radius / 2);
|
|
|
|
|
+ // var offset4 = center - new Vector2(0, i.Radius / 2);
|
|
|
|
|
+ // var transR = ((screenIdentification.Screen.TransformToScreen(offset1) - screenIdentification.Screen.TransformToScreen(offset2)).magnitude +
|
|
|
|
|
+ // (screenIdentification.Screen.TransformToScreen(offset3) - screenIdentification.Screen.TransformToScreen(offset4)).magnitude) / 4;
|
|
|
|
|
+ // var r1 = transR / screenIdentification.Screen.UVSize.x;
|
|
|
|
|
+ // //Debug.Log(r1 / r0);
|
|
|
|
|
+ // i.Radius *= (float)Math.Pow(r1 / r0, 2); // 摄像机位置不同参数也可能不同
|
|
|
|
|
+ //}
|
|
|
|
|
|
|
|
//if (spotArea.Count == 1)
|
|
//if (spotArea.Count == 1)
|
|
|
//Debug.Log($"{spotArea[0].MaxRadius}");
|
|
//Debug.Log($"{spotArea[0].MaxRadius}");
|
|
|
|
|
|
|
|
- return spotArea;
|
|
|
|
|
|
|
+ //return spotArea;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
//// 排序亮区
|
|
//// 排序亮区
|
|
|
//spotArea.Sort((a, b) => b.MaxRadius.CompareTo(a.MaxRadius));
|
|
//spotArea.Sort((a, b) => b.MaxRadius.CompareTo(a.MaxRadius));
|
|
|
- ////var areas = new SortedList<float, PixelSpotArea>(new DescendingComparer<float>());
|
|
|
|
|
|
|
+ ////var areas = new SortedList<float, ISpotArea>(new DescendingComparer<float>());
|
|
|
////foreach (var i in spotArea)
|
|
////foreach (var i in spotArea)
|
|
|
//// areas.Add(i.MaxRadius, i);
|
|
//// areas.Add(i.MaxRadius, i);
|
|
|
|
|
|
|
@@ -266,14 +259,16 @@ namespace ZIM
|
|
|
//return result;
|
|
//return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return new List<PixelSpotArea>();
|
|
|
|
|
|
|
+ return new List<ISpotArea>();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void DebugAreas(List<PixelSpotArea> areas)
|
|
|
|
|
|
|
+ private void DebugAreas(List<ISpotArea> areas)
|
|
|
{
|
|
{
|
|
|
- ScreenLocate.Main.Info.transform.GetChild(0).GetComponent<Text>().text = $"areas.Count: {areas.Count}";
|
|
|
|
|
- PixelSpotArea a0 = null; // 表示最大半径的区域
|
|
|
|
|
- PixelSpotArea a1 = null; // 表示第二大半径的区域
|
|
|
|
|
|
|
+ var debugText = $"当前相机分辨率: {ScreenLocate.Main.CameraSize}";
|
|
|
|
|
+ debugText += $"\r\nareas.Count: {areas.Count}";
|
|
|
|
|
+
|
|
|
|
|
+ ISpotArea a0 = null; // 表示最大半径的区域
|
|
|
|
|
+ ISpotArea a1 = null; // 表示第二大半径的区域
|
|
|
|
|
|
|
|
foreach (var a in areas)
|
|
foreach (var a in areas)
|
|
|
{
|
|
{
|
|
@@ -300,6 +295,7 @@ namespace ZIM
|
|
|
texture.SetPixel((int)p.x, (int)p.y, Color.yellow);
|
|
texture.SetPixel((int)p.x, (int)p.y, Color.yellow);
|
|
|
foreach (var p in a0.Pixels1)
|
|
foreach (var p in a0.Pixels1)
|
|
|
texture.SetPixel((int)p.x, (int)p.y, Color.white);
|
|
texture.SetPixel((int)p.x, (int)p.y, Color.white);
|
|
|
|
|
+ debugText += $"\r\n最大的区域半径: {a0.Radius}";
|
|
|
}
|
|
}
|
|
|
if (a1 != null)
|
|
if (a1 != null)
|
|
|
{
|
|
{
|
|
@@ -307,19 +303,21 @@ namespace ZIM
|
|
|
texture.SetPixel((int)p.x, (int)p.y, Color.green);
|
|
texture.SetPixel((int)p.x, (int)p.y, Color.green);
|
|
|
foreach (var p in a1.Pixels1)
|
|
foreach (var p in a1.Pixels1)
|
|
|
texture.SetPixel((int)p.x, (int)p.y, Color.blue);
|
|
texture.SetPixel((int)p.x, (int)p.y, Color.blue);
|
|
|
|
|
+ debugText += $"\r\n第二大的区域半径: {a1.Radius}";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
texture.Apply();
|
|
texture.Apply();
|
|
|
ScreenLocate.DebugTexture(6, texture);
|
|
ScreenLocate.DebugTexture(6, texture);
|
|
|
|
|
+ ScreenLocate.Main.Info.transform.GetChild(0).GetComponent<Text>().text = debugText;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private List<PixelSpotArea_DbScan> DbscanToSpotAreas(DbscanResult<Vector2> db, List<Vector2> brightPoint)
|
|
|
|
|
|
|
+ private List<ISpotArea> DbscanToSpotAreas(DbscanResult<Vector2> db, List<Vector2> brightPoint)
|
|
|
{
|
|
{
|
|
|
if (db.Clusters.Count == 0)
|
|
if (db.Clusters.Count == 0)
|
|
|
- return new List<PixelSpotArea_DbScan>();
|
|
|
|
|
|
|
+ return new List<ISpotArea>();
|
|
|
|
|
|
|
|
// 用dbscan的结果创建SpotArea,先用高亮区算一遍半径
|
|
// 用dbscan的结果创建SpotArea,先用高亮区算一遍半径
|
|
|
- var clusters = new List<PixelSpotArea_DbScan>();
|
|
|
|
|
|
|
+ var clusters = new List<ISpotArea>();
|
|
|
var areaIncludeRadius = new List<(Vector2, float)>();
|
|
var areaIncludeRadius = new List<(Vector2, float)>();
|
|
|
foreach (var i in db.Clusters.Values)
|
|
foreach (var i in db.Clusters.Values)
|
|
|
{
|
|
{
|
|
@@ -335,11 +333,11 @@ namespace ZIM
|
|
|
{
|
|
{
|
|
|
var index = FindNearestAreaIndex(i, areaIncludeRadius);
|
|
var index = FindNearestAreaIndex(i, areaIncludeRadius);
|
|
|
if (index < clusters.Count)
|
|
if (index < clusters.Count)
|
|
|
- clusters[index].Add1(i);
|
|
|
|
|
|
|
+ clusters[index].Pixels1.Add(i);
|
|
|
}
|
|
}
|
|
|
// 添加了泛光点后,重新计算半径
|
|
// 添加了泛光点后,重新计算半径
|
|
|
foreach (var i in clusters)
|
|
foreach (var i in clusters)
|
|
|
- i.Radius = i.CalculateRadius();
|
|
|
|
|
|
|
+ i.CalculateRadius();
|
|
|
|
|
|
|
|
return clusters;
|
|
return clusters;
|
|
|
}
|
|
}
|
|
@@ -364,9 +362,9 @@ namespace ZIM
|
|
|
return nearestIndex;
|
|
return nearestIndex;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- InfraredSpot[] MatchInfraredRaySingle(List<PixelSpotArea> spotArea)
|
|
|
|
|
|
|
+ InfraredSpot[] MatchInfraredRaySingle(List<ISpotArea> spotArea)
|
|
|
{
|
|
{
|
|
|
- var matchedArea = new Dictionary<InfraredMatch, PixelSpotArea>() { { InfraredMatch.Match0, null } };
|
|
|
|
|
|
|
+ var matchedArea = new Dictionary<InfraredMatch, ISpotArea>() { { InfraredMatch.Match0, null } };
|
|
|
var v0 = InfraredSpots[0].Verify(spotArea, matchedArea);
|
|
var v0 = InfraredSpots[0].Verify(spotArea, matchedArea);
|
|
|
|
|
|
|
|
if (v0)
|
|
if (v0)
|
|
@@ -396,9 +394,9 @@ namespace ZIM
|
|
|
return InfraredSpots;
|
|
return InfraredSpots;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- InfraredSpot[] MatchInfraredRay(List<PixelSpotArea> spotArea)
|
|
|
|
|
|
|
+ InfraredSpot[] MatchInfraredRay(List<ISpotArea> spotArea)
|
|
|
{
|
|
{
|
|
|
- var matchedArea = new Dictionary<InfraredMatch, PixelSpotArea>() { { InfraredMatch.Match0, null }, { InfraredMatch.Match1, null } };
|
|
|
|
|
|
|
+ var matchedArea = new Dictionary<InfraredMatch, ISpotArea>() { { InfraredMatch.Match0, null }, { InfraredMatch.Match1, null } };
|
|
|
var v0 = InfraredSpots[0].Verify(spotArea, matchedArea);
|
|
var v0 = InfraredSpots[0].Verify(spotArea, matchedArea);
|
|
|
var v1 = InfraredSpots[1].Verify(spotArea, matchedArea);
|
|
var v1 = InfraredSpots[1].Verify(spotArea, matchedArea);
|
|
|
|
|
|
|
@@ -446,8 +444,8 @@ namespace ZIM
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- PixelSpotArea select = null;
|
|
|
|
|
- PixelSpotArea selectOther = null;
|
|
|
|
|
|
|
+ ISpotArea select = null;
|
|
|
|
|
+ ISpotArea selectOther = null;
|
|
|
InfraredMatch oneFailed = InfraredMatch.Nomatch;
|
|
InfraredMatch oneFailed = InfraredMatch.Nomatch;
|
|
|
if (!v0)
|
|
if (!v0)
|
|
|
{
|
|
{
|
|
@@ -538,7 +536,7 @@ namespace ZIM
|
|
|
if (v0)
|
|
if (v0)
|
|
|
{
|
|
{
|
|
|
var overlapAera = matchedArea[InfraredMatch.Match0];
|
|
var overlapAera = matchedArea[InfraredMatch.Match0];
|
|
|
- (PixelSpotArea, float) split = (null, float.MaxValue);
|
|
|
|
|
|
|
+ (ISpotArea, float) split = (null, float.MaxValue);
|
|
|
foreach (var i in spotArea)
|
|
foreach (var i in spotArea)
|
|
|
{
|
|
{
|
|
|
if (i != overlapAera)
|
|
if (i != overlapAera)
|