|
|
@@ -82,8 +82,8 @@ namespace o0.Project
|
|
|
public ScreenIdentification()
|
|
|
{
|
|
|
Screen = new ScreenMap();
|
|
|
- OnLocateScreenEnter += () => Application.targetFrameRate = 30; // 固定识别的帧率,确保摄像机拍到正确的画面
|
|
|
- OnLocateScreenEnd += () => Application.targetFrameRate = 60;
|
|
|
+ //OnLocateScreenEnter += () => Application.targetFrameRate = 30; // 固定识别的帧率,确保摄像机拍到正确的画面
|
|
|
+ //OnLocateScreenEnd += () => Application.targetFrameRate = 60;
|
|
|
}
|
|
|
|
|
|
public void SetScreenQuad(QuadrilateralInCamera quad) => Screen.QuadInCamera = quad;
|
|
|
@@ -667,8 +667,8 @@ namespace o0.Project
|
|
|
// 屏幕黑白差值,存放多批次的图像用于识别, 该List数量不能等于 0
|
|
|
List<UnityEngine.Color[]> PixelsMultipleBatches = new List<UnityEngine.Color[]>();
|
|
|
|
|
|
- var sw = new System.Diagnostics.Stopwatch();
|
|
|
- sw.Start();
|
|
|
+ //var sw = new System.Diagnostics.Stopwatch();
|
|
|
+ //sw.Start();
|
|
|
|
|
|
//读取数据
|
|
|
if (debugImages != null && debugImages.Count != 0)
|
|
|
@@ -689,7 +689,8 @@ namespace o0.Project
|
|
|
if (maxWhite < m)
|
|
|
maxWhite = m;
|
|
|
}
|
|
|
- var scale = 1.0f / maxWhite; // 放大对比度
|
|
|
+ //var scale = 1.0f / maxWhite; // 放大对比度
|
|
|
+ //Debug.Log("[ScreenIdentification] 提高亮度倍数: " + scale);
|
|
|
|
|
|
var differPixel = new UnityEngine.Color[Size.x * Size.y];
|
|
|
var whitePixel = new UnityEngine.Color[Size.x * Size.y];
|
|
|
@@ -699,8 +700,8 @@ namespace o0.Project
|
|
|
{
|
|
|
var i = y * Size.x + x;
|
|
|
var d = ScreenWhiteTexture[i] - ScreenBlackTexture[i];
|
|
|
- differPixel[i] = new UnityEngine.Color(d.x, d.y, d.z) * scale;
|
|
|
- whitePixel[i] = new UnityEngine.Color(ScreenWhiteTexture[i].x, ScreenWhiteTexture[i].y, ScreenWhiteTexture[i].z) * scale;
|
|
|
+ differPixel[i] = new UnityEngine.Color(d.x, d.y, d.z);
|
|
|
+ whitePixel[i] = new UnityEngine.Color(ScreenWhiteTexture[i].x, ScreenWhiteTexture[i].y, ScreenWhiteTexture[i].z);
|
|
|
}
|
|
|
});
|
|
|
PixelsMultipleBatches.Add(differPixel); // 色差图
|
|
|
@@ -710,19 +711,25 @@ namespace o0.Project
|
|
|
int conSize = (int)Math.Ceiling(0.007f * Size.y) * 2 + 1;
|
|
|
conSize = Math.Max(conSize, 7); // 设置最小为7
|
|
|
|
|
|
- float minLength = conSize * 7.7f;
|
|
|
- minLength = locateIndex == -1 ? minLength : minLength * areaPercent; // minLength需要按比例缩小
|
|
|
+ float minLength = conSize * 4f;
|
|
|
+ minLength = locateIndex == -1 ? minLength : minLength * areaPercent; // minLength需要按areaPercent比例缩小
|
|
|
string log = $"[Log][ScreenLocate Auto] Size: ({Size.x},{Size.y}), 卷积核Size: {conSize}, 最小线段长度: {minLength}";
|
|
|
|
|
|
var allLines = new List<LineIdentified>();
|
|
|
List<Texture2D> LocateTexTemp = new List<Texture2D>();
|
|
|
List<Matrix> ScreenLocateMatList = new List<Matrix>();
|
|
|
+ var LineCaptureSizes = new Vector[2] { Vector.One * minLength, new Vector(10, 6) };
|
|
|
foreach (var batch in PixelsMultipleBatches.Index())
|
|
|
{
|
|
|
var locateTex = ToLocateTex(PixelsMultipleBatches[batch]);
|
|
|
LocateTexTemp.Add(locateTex);
|
|
|
var ScreenLocateMat = locateTex.Too0Mat(); // 用于获取Lines的Matrix
|
|
|
- var lineCount = ZIMIdentifyQuadLSD(ref allLines, batch, ScreenLocateMat.zimIdentifyEdgeGradientAny(conSize), minLength);
|
|
|
+ var lineCount = ZIMIdentifyQuadLSD(
|
|
|
+ ref allLines,
|
|
|
+ batch,
|
|
|
+ ScreenLocateMat.zimIdentifyEdgeGradientAny(conSize),
|
|
|
+ minLength,
|
|
|
+ LineCaptureSizes[batch]);
|
|
|
log += $"\r\n识别图片{batch}, 识别到的线段数量为: {lineCount}";
|
|
|
ScreenLocateMatList.Add(ScreenLocateMat);
|
|
|
}
|
|
|
@@ -910,9 +917,9 @@ namespace o0.Project
|
|
|
|
|
|
// 返回查找到的线段数量,0是查找失败
|
|
|
int ZIMIdentifyQuadLSD(ref List<LineIdentified> allLines, int batch, (Matrix edgeMat, Matrix edgeDirMat) edgeGradient,
|
|
|
- float minLength = 100)
|
|
|
+ float minLength, Vector LineCaptureSize)
|
|
|
{
|
|
|
- var l = edgeGradient.edgeMat.IdentifyLineLSD(edgeGradient.edgeDirMat, minLength, 50, LineCaptureSize: new Vector(10, 6));
|
|
|
+ var l = edgeGradient.edgeMat.IdentifyLineLSD(edgeGradient.edgeDirMat, minLength, 50, LineCaptureSize);
|
|
|
if (l == null || l.Count == 0)
|
|
|
return 0;
|
|
|
allLines.AddRange(l.Select((i) => new LineIdentified(batch, i)));
|
|
|
@@ -971,9 +978,9 @@ namespace o0.Project
|
|
|
lg.Add(screenLocateMatList[line.Batch][(int)ga.x, (int)ga.y] - screenLocateMatList[line.Batch][(int)gb.x, (int)gb.y]);
|
|
|
}
|
|
|
|
|
|
- float e = (float)Math.Sqrt(Math.Ceiling(line.Line.Length / minLength)); // 长度系数,筛选时梯度更大、长度更长的线段更优
|
|
|
- float d = (3 - distanceRatio) / 2; // 距离系数,距离越近,系数越大
|
|
|
- return e * d * Math.Abs(lg.Mean());
|
|
|
+ //float e = (float)Math.Sqrt(Math.Ceiling(line.Line.Length / minLength)); // 长度系数,筛选时梯度更大、长度更长的线段更优
|
|
|
+ float d = (1.5f - distanceRatio) * 2; // 距离系数,距离越近,系数越大
|
|
|
+ return d * Math.Abs(lg.Mean());
|
|
|
}
|
|
|
// 根据线段梯度的角度,判断是不是屏幕的边,out index代表是哪条边(顺序是: 下、右、上、左)
|
|
|
bool isScreenLine(LineIdentified line, out int index)
|