mirror of
https://github.com/babalae/better-genshin-impact
synced 2025-01-07 03:17:16 +08:00
adaptability modification
This commit is contained in:
parent
bee375484c
commit
3b7bf83b30
@ -43,9 +43,8 @@ public class PaddleOcrService : IOcrService
|
||||
long startTime = Stopwatch.GetTimestamp();
|
||||
var result = _ocrEngine.Run(mat).ToBgiOcrResult();
|
||||
TimeSpan time = Stopwatch.GetElapsedTime(startTime);
|
||||
Debug.WriteLine($"PaddleOcr 耗时 {time.TotalMilliseconds}ms 结果: {result}");
|
||||
Debug.WriteLine($"PaddleOcr 耗时 {time.TotalMilliseconds}ms 结果: {result.Text}");
|
||||
return result;
|
||||
}
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class DbNet
|
||||
using (IDisposableReadOnlyCollection<DisposableNamedOnnxValue> results = dbNet.Run(inputs))
|
||||
{
|
||||
var resultsArray = results.ToArray();
|
||||
Debug.WriteLine(resultsArray);
|
||||
// Debug.WriteLine(resultsArray);
|
||||
var textBoxes = GetTextBoxes(resultsArray, srcResize.Rows, srcResize.Cols, scale, boxScoreThresh, boxThresh, unClipRatio);
|
||||
return textBoxes;
|
||||
}
|
||||
|
@ -39,14 +39,27 @@ public class PaddleOcrEngine
|
||||
}
|
||||
}
|
||||
|
||||
public Mat ToChannel3Mat(Mat mat)
|
||||
{
|
||||
return mat.Channels() switch
|
||||
{
|
||||
4 => mat.CvtColor(ColorConversionCodes.RGBA2BGR),
|
||||
1 => mat.CvtColor(ColorConversionCodes.GRAY2RGB),
|
||||
3 => mat,
|
||||
var x => throw new Exception($"Unexpect src channel: {x}, allow: (1/3/4)")
|
||||
};
|
||||
}
|
||||
|
||||
public RapidOcrResult Run(Mat mat)
|
||||
{
|
||||
return Run(mat, 0, 1024, 0.5f, 0.3f, 1.6f, false, false);
|
||||
using var channel3 = ToChannel3Mat(mat);
|
||||
return Run(channel3, 0, 1024, 0.5f, 0.3f, 1.6f, false, false);
|
||||
}
|
||||
|
||||
public string OnlyRecognizerRun(Mat mat)
|
||||
{
|
||||
var textLine = crnnNet.GetTextLine(mat);
|
||||
using var channel3 = ToChannel3Mat(mat);
|
||||
var textLine = crnnNet.GetTextLine(channel3);
|
||||
return textLine.Text;
|
||||
}
|
||||
|
||||
@ -78,14 +91,14 @@ public class PaddleOcrEngine
|
||||
{
|
||||
// Mat textBoxPaddingImg = src.Clone();
|
||||
// int thickness = OcrUtils.GetThickness(src);
|
||||
Debug.WriteLine("=====Start detect=====");
|
||||
// Debug.WriteLine("=====Start detect=====");
|
||||
var startTicks = DateTime.Now.Ticks;
|
||||
|
||||
Debug.WriteLine("---------- step: dbNet getTextBoxes ----------");
|
||||
// Debug.WriteLine("---------- step: dbNet getTextBoxes ----------");
|
||||
var textBoxes = dbNet.GetTextBoxes(src, scale, boxScoreThresh, boxThresh, unClipRatio);
|
||||
var dbNetTime = (DateTime.Now.Ticks - startTicks) / 10000F;
|
||||
|
||||
Debug.WriteLine($"TextBoxesSize({textBoxes.Count})");
|
||||
// Debug.WriteLine($"TextBoxesSize({textBoxes.Count})");
|
||||
textBoxes.ForEach(x => Debug.WriteLine(x));
|
||||
//Debug.WriteLine($"dbNetTime({dbNetTime}ms)");
|
||||
|
||||
@ -103,7 +116,7 @@ public class PaddleOcrEngine
|
||||
}
|
||||
}
|
||||
|
||||
Debug.WriteLine("---------- step: angleNet getAngles ----------");
|
||||
// Debug.WriteLine("---------- step: angleNet getAngles ----------");
|
||||
List<Angle> angles = angleNet.GetAngles(partImages, doAngle, mostAngle);
|
||||
//angles.ForEach(x => Debug.WriteLine(x));
|
||||
|
||||
@ -120,7 +133,7 @@ public class PaddleOcrEngine
|
||||
}
|
||||
}
|
||||
|
||||
Debug.WriteLine("---------- step: crnnNet getTextLines ----------");
|
||||
// Debug.WriteLine("---------- step: crnnNet getTextLines ----------");
|
||||
List<TextLine> textLines = crnnNet.GetTextLines(partImages);
|
||||
//textLines.ForEach(x => Debug.WriteLine(x));
|
||||
|
||||
|
@ -375,7 +375,7 @@ public class AutoDomainTask
|
||||
using var ra = GetRectAreaFromDispatcher();
|
||||
|
||||
var endTipsRect = ra.DeriveCrop(AutoFightContext.Instance.FightAssets.EndTipsUpperRect);
|
||||
var text = OcrFactory.Paddle.Ocr(endTipsRect.SrcGreyMat);
|
||||
var text = OcrFactory.Paddle.Ocr(endTipsRect.SrcMat);
|
||||
if (text.Contains("挑战") || text.Contains("达成"))
|
||||
{
|
||||
Logger.LogInformation("检测到秘境结束提示(挑战达成),结束秘境");
|
||||
@ -383,7 +383,7 @@ public class AutoDomainTask
|
||||
}
|
||||
|
||||
endTipsRect = ra.DeriveCrop(AutoFightContext.Instance.FightAssets.EndTipsRect);
|
||||
text = OcrFactory.Paddle.Ocr(endTipsRect.SrcGreyMat);
|
||||
text = OcrFactory.Paddle.Ocr(endTipsRect.SrcMat);
|
||||
if (text.Contains("自动") || text.Contains("退出"))
|
||||
{
|
||||
Logger.LogInformation("检测到秘境结束提示(xxx秒后自动退出),结束秘境");
|
||||
@ -758,7 +758,7 @@ public class AutoDomainTask
|
||||
// 图像右侧就是浓缩树脂数量
|
||||
var countArea = ra.DeriveCrop(condensedResinCountRa.X + condensedResinCountRa.Width, condensedResinCountRa.Y, condensedResinCountRa.Width, condensedResinCountRa.Height);
|
||||
// Cv2.ImWrite($"log/resin_{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff")}.png", countArea.SrcGreyMat);
|
||||
var count = OcrFactory.Paddle.OcrWithoutDetector(countArea.SrcGreyMat);
|
||||
var count = OcrFactory.Paddle.OcrWithoutDetector(countArea.SrcMat);
|
||||
condensedResinCount = StringUtils.TryParseInt(count);
|
||||
}
|
||||
|
||||
@ -768,7 +768,7 @@ public class AutoDomainTask
|
||||
{
|
||||
// 图像右侧就是脆弱树脂数量
|
||||
var countArea = ra.DeriveCrop(fragileResinCountRa.X + fragileResinCountRa.Width, fragileResinCountRa.Y, (int)(fragileResinCountRa.Width * 3), fragileResinCountRa.Height);
|
||||
var count = OcrFactory.Paddle.Ocr(countArea.SrcGreyMat);
|
||||
var count = OcrFactory.Paddle.Ocr(countArea.SrcMat);
|
||||
fragileResinCount = StringUtils.TryParseInt(count);
|
||||
}
|
||||
|
||||
|
@ -299,7 +299,7 @@ public class Avatar
|
||||
public double GetSkillCurrentCd(ImageRegion imageRegion)
|
||||
{
|
||||
var eRa = imageRegion.DeriveCrop(AutoFightContext.Instance.FightAssets.ERect);
|
||||
var text = OcrFactory.Paddle.Ocr(eRa.SrcGreyMat);
|
||||
var text = OcrFactory.Paddle.Ocr(eRa.SrcMat);
|
||||
return StringUtils.TryParseDouble(text);
|
||||
}
|
||||
|
||||
@ -353,7 +353,7 @@ public class Avatar
|
||||
// public double GetBurstCurrentCd(CaptureContent content)
|
||||
// {
|
||||
// var qRa = content.CaptureRectArea.Crop(AutoFightContext.Instance.FightAssets.QRect);
|
||||
// var text = OcrFactory.Paddle.Ocr(qRa.SrcGreyMat);
|
||||
// var text = OcrFactory.Paddle.Ocr(qRa.SrcMat);
|
||||
// return StringUtils.TryParseDouble(text);
|
||||
// }
|
||||
|
||||
|
@ -136,14 +136,14 @@ public class AutoPickTrigger : ITaskTrigger
|
||||
// 计算出文字区域
|
||||
var textRect = new Rect(foundRectArea.X + (int)(config.ItemTextLeftOffset * scale), foundRectArea.Y,
|
||||
(int)((config.ItemTextRightOffset - config.ItemTextLeftOffset) * scale), foundRectArea.Height);
|
||||
if (textRect.X + textRect.Width > content.CaptureRectArea.SrcGreyMat.Width
|
||||
|| textRect.Y + textRect.Height > content.CaptureRectArea.SrcGreyMat.Height)
|
||||
if (textRect.X + textRect.Width > content.CaptureRectArea.SrcMat.Width
|
||||
|| textRect.Y + textRect.Height > content.CaptureRectArea.SrcMat.Height)
|
||||
{
|
||||
Debug.WriteLine("AutoPickTrigger: 文字区域 out of range");
|
||||
return;
|
||||
}
|
||||
|
||||
var textMat = new Mat(content.CaptureRectArea.SrcGreyMat, textRect);
|
||||
var textMat = new Mat(content.CaptureRectArea.SrcMat, textRect);
|
||||
|
||||
string text;
|
||||
if (config.OcrEngine == PickOcrEngineEnum.Yap.ToString())
|
||||
|
@ -260,7 +260,7 @@ public class AutoSkipTrigger : ITaskTrigger
|
||||
// OCR识别选项文字
|
||||
foreach (var hangoutOption in hangoutOptionList)
|
||||
{
|
||||
var text = OcrFactory.Paddle.Ocr(hangoutOption.TextRect!.SrcGreyMat);
|
||||
var text = OcrFactory.Paddle.Ocr(hangoutOption.TextRect!.SrcMat);
|
||||
hangoutOption.OptionTextSrc = StringUtils.RemoveAllEnter(text);
|
||||
}
|
||||
|
||||
|
@ -253,7 +253,7 @@ public class AutoTrackTask(AutoTrackParam param) : BaseIndependentTask
|
||||
wDown = false;
|
||||
}
|
||||
// 识别距离
|
||||
var text = OcrFactory.Paddle.OcrWithoutDetector(ra.SrcGreyMat[_missionDistanceRect]);
|
||||
var text = OcrFactory.Paddle.OcrWithoutDetector(ra.SrcMat[_missionDistanceRect]);
|
||||
if (StringUtils.TryExtractPositiveInt(text) is > -1 and <= 3)
|
||||
{
|
||||
Logger.LogInformation("任务追踪:到达目标,识别结果[{Text}]", text);
|
||||
|
@ -212,7 +212,7 @@ public class ExpeditionTask
|
||||
private OcrResult CaptureAndOcr(CaptureContent content)
|
||||
{
|
||||
using var ra = TaskControl.CaptureToRectArea();
|
||||
var result = OcrFactory.Paddle.OcrResult(ra.SrcGreyMat);
|
||||
var result = OcrFactory.Paddle.OcrResult(ra.SrcMat);
|
||||
//VisionContext.Instance().DrawContent.PutOrRemoveRectList("OcrResultRects", result.ToRectDrawableList(_pen));
|
||||
return result;
|
||||
}
|
||||
@ -220,7 +220,7 @@ public class ExpeditionTask
|
||||
private OcrResult CaptureAndOcr(CaptureContent content, Rect rect)
|
||||
{
|
||||
using var ra = TaskControl.CaptureToRectArea();
|
||||
var result = OcrFactory.Paddle.OcrResult(ra.SrcGreyMat);
|
||||
var result = OcrFactory.Paddle.OcrResult(ra.SrcMat);
|
||||
//VisionContext.Instance().DrawContent.PutOrRemoveRectList("OcrResultRects", result.ToRectDrawableList(_pen));
|
||||
return result;
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ public partial class AutoWoodTask
|
||||
{
|
||||
// OCR识别文本区域
|
||||
var woodCountRect = CaptureToRectArea().DeriveCrop(assert.WoodCountUpperRect);
|
||||
return OcrFactory.Paddle.Ocr(woodCountRect.SrcGreyMat);
|
||||
return OcrFactory.Paddle.Ocr(woodCountRect.SrcMat);
|
||||
}
|
||||
|
||||
private bool HasDetectedWoodText(string recognizedText)
|
||||
|
@ -197,10 +197,10 @@ public class ImageRegion : Region
|
||||
throw new Exception($"[OCR]识别对象{ro.Name}的匹配文本不能全为空");
|
||||
}
|
||||
|
||||
var roi = SrcGreyMat;
|
||||
var roi = SrcMat;
|
||||
if (ro.RegionOfInterest != Rect.Empty)
|
||||
{
|
||||
roi = new Mat(SrcGreyMat, ro.RegionOfInterest);
|
||||
roi = new Mat(SrcMat, ro.RegionOfInterest);
|
||||
}
|
||||
|
||||
var result = OcrFactory.Paddle.OcrResult(roi);
|
||||
@ -289,10 +289,10 @@ public class ImageRegion : Region
|
||||
}
|
||||
else
|
||||
{
|
||||
roi = SrcGreyMat;
|
||||
roi = SrcMat;
|
||||
if (ro.RegionOfInterest != Rect.Empty)
|
||||
{
|
||||
roi = new Mat(SrcGreyMat, ro.RegionOfInterest);
|
||||
roi = new Mat(SrcMat, ro.RegionOfInterest);
|
||||
}
|
||||
}
|
||||
|
||||
@ -414,10 +414,10 @@ public class ImageRegion : Region
|
||||
}
|
||||
else if (RecognitionTypes.Ocr.Equals(ro.RecognitionType))
|
||||
{
|
||||
var roi = SrcGreyMat;
|
||||
var roi = SrcMat;
|
||||
if (ro.RegionOfInterest != Rect.Empty)
|
||||
{
|
||||
roi = new Mat(SrcGreyMat, ro.RegionOfInterest);
|
||||
roi = new Mat(SrcMat, ro.RegionOfInterest);
|
||||
}
|
||||
|
||||
var result = OcrFactory.Paddle.OcrResult(roi);
|
||||
|
Loading…
Reference in New Issue
Block a user