Skip to content

Commit 8799f34

Browse files
committed
修复 Yap 无法正常使用的问题 #1459
1 parent 9284a51 commit 8799f34

File tree

3 files changed

+36
-36
lines changed

3 files changed

+36
-36
lines changed

BetterGenshinImpact/Core/Recognition/ONNX/SVTR/TextInferenceFactory.cs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,32 @@ public static ITextInference Create(OcrEngineTypes type)
1616
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null),
1717
};
1818
}
19-
public static Mat PreProcessForInference(Mat mat)
20-
{
21-
if (mat.Channels() == 3)
22-
{
23-
mat = mat.CvtColor(ColorConversionCodes.BGR2GRAY);
24-
}
25-
else if (mat.Channels() == 4)
26-
{
27-
mat = mat.CvtColor(ColorConversionCodes.BGRA2GRAY);
28-
}
29-
else if (mat.Channels() != 1)
30-
{
31-
throw new ArgumentException("mat must be 1, 3 or 4 channels");
32-
}
33-
34-
// Yap 已经改用灰度图了 https://github.com/Alex-Beng/Yap/commit/c2ad1e7b1442aaf2d80782a032e00876cd1c6c84
35-
// 二值化
36-
// Cv2.Threshold(mat, mat, 0, 255, ThresholdTypes.Otsu | ThresholdTypes.Binary);
37-
//Cv2.AdaptiveThreshold(mat, mat, 255, AdaptiveThresholdTypes.GaussianC, ThresholdTypes.Binary, 31, 3); // 效果不错 但是和模型不搭
38-
//mat = OpenCvCommonHelper.Threshold(mat, Scalar.FromRgb(235, 235, 235), Scalar.FromRgb(255, 255, 255)); // 识别物品不太行
39-
// 不知道为什么要强制拉伸到 221x32
40-
mat = ResizeHelper.ResizeTo(mat, 221, 32);
41-
// 填充到 384x32
42-
var padded = new Mat(new Size(384, 32), MatType.CV_8UC1, Scalar.Black);
43-
padded[new Rect(0, 0, mat.Width, mat.Height)] = mat;
44-
//Cv2.ImWrite(Global.Absolute("padded.png"), padded);
45-
return padded;
46-
}
19+
// public static Mat PreProcessForInference(Mat mat)
20+
// {
21+
// if (mat.Channels() == 3)
22+
// {
23+
// mat = mat.CvtColor(ColorConversionCodes.BGR2GRAY);
24+
// }
25+
// else if (mat.Channels() == 4)
26+
// {
27+
// mat = mat.CvtColor(ColorConversionCodes.BGRA2GRAY);
28+
// }
29+
// else if (mat.Channels() != 1)
30+
// {
31+
// throw new ArgumentException("mat must be 1, 3 or 4 channels");
32+
// }
33+
//
34+
// // Yap 已经改用灰度图了 https://github.com/Alex-Beng/Yap/commit/c2ad1e7b1442aaf2d80782a032e00876cd1c6c84
35+
// // 二值化
36+
// // Cv2.Threshold(mat, mat, 0, 255, ThresholdTypes.Otsu | ThresholdTypes.Binary);
37+
// //Cv2.AdaptiveThreshold(mat, mat, 255, AdaptiveThresholdTypes.GaussianC, ThresholdTypes.Binary, 31, 3); // 效果不错 但是和模型不搭
38+
// //mat = OpenCvCommonHelper.Threshold(mat, Scalar.FromRgb(235, 235, 235), Scalar.FromRgb(255, 255, 255)); // 识别物品不太行
39+
// // 不知道为什么要强制拉伸到 221x32
40+
// mat = ResizeHelper.ResizeTo(mat, 221, 32);
41+
// // 填充到 384x32
42+
// var padded = new Mat(new Size(384, 32), MatType.CV_8UC1, Scalar.Black);
43+
// padded[new Rect(0, 0, mat.Width, mat.Height)] = mat;
44+
// //Cv2.ImWrite(Global.Absolute("padded.png"), padded);
45+
// return padded;
46+
// }
4747
}

BetterGenshinImpact/GameTask/AutoPick/AutoPickTrigger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public void OnCapture(CaptureContent content)
198198
if (config.OcrEngine == PickOcrEngineEnum.Yap.ToString())
199199
{
200200
var textMat = new Mat(content.CaptureRectArea.CacheGreyMat, textRect);
201-
text = _pickTextInference.Inference(TextInferenceFactory.PreProcessForInference(textMat));
201+
text = _pickTextInference.Inference(textMat);
202202
}
203203
else
204204
{

Test/BetterGenshinImpact.Test/Simple/OcrTest.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ public class OcrTest
1010
{
1111
public static void TestYap()
1212
{
13-
Mat mat = Cv2.ImRead(@"E:\HuiTask\更好的原神\临时文件\fuben_jueyuan.png");
14-
var text = TextInferenceFactory.Pick.Inference(TextInferenceFactory.PreProcessForInference(mat));
15-
Debug.WriteLine(text);
16-
17-
Mat mat2 = Cv2.ImRead(@"E:\HuiTask\更好的原神\临时文件\fuben_jueyuan.png");
18-
var text2 = OcrFactory.Paddle.Ocr(mat2);
19-
Debug.WriteLine(text2);
13+
// Mat mat = Cv2.ImRead(@"E:\HuiTask\更好的原神\临时文件\fuben_jueyuan.png");
14+
// var text = TextInferenceFactory.Pick.Inference(TextInferenceFactory.PreProcessForInference(mat));
15+
// Debug.WriteLine(text);
16+
//
17+
// Mat mat2 = Cv2.ImRead(@"E:\HuiTask\更好的原神\临时文件\fuben_jueyuan.png");
18+
// var text2 = OcrFactory.Paddle.Ocr(mat2);
19+
// Debug.WriteLine(text2);
2020
}
2121

2222

0 commit comments

Comments
 (0)