@@ -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}
0 commit comments