88
99namespace Sdcb . PaddleOCR . Tests ;
1010
11- public class OnlineModelsTest
11+ public class OnlineModelsTest ( ITestOutputHelper console )
1212{
13- private readonly ITestOutputHelper _console ;
14-
15- public OnlineModelsTest ( ITestOutputHelper console )
16- {
17- _console = console ;
18- }
19-
20- [ Fact ]
21- public async Task FastCheckOCR ( )
22- {
23- FullOcrModel model = await OnlineFullModels . EnglishV3 . DownloadAsync ( ) ;
24-
25- // from: https://visualstudio.microsoft.com/wp-content/uploads/2021/11/Home-page-extension-visual-updated.png
26- byte [ ] sampleImageData = File . ReadAllBytes ( @"./samples/vsext.png" ) ;
27-
28- using ( PaddleOcrAll all = new ( model )
29- {
30- AllowRotateDetection = true ,
31- Enable180Classification = false ,
32- } )
33- {
34- // Load local file by following code:
35- // using (Mat src2 = Cv2.ImRead(@"C:\test.jpg"))
36- using ( Mat src = Cv2 . ImDecode ( sampleImageData , ImreadModes . Color ) )
37- {
38- Stopwatch sw = Stopwatch . StartNew ( ) ;
39- PaddleOcrResult result = all . Run ( src ) ;
40- _console . WriteLine ( $ "lapsed={ sw . ElapsedMilliseconds } ms") ;
41- _console . WriteLine ( "Detected all texts: \n " + result . Text ) ;
42- foreach ( PaddleOcrResultRegion region in result . Regions )
43- {
44- _console . WriteLine ( $ "Text: { region . Text } , Score: { region . Score } , RectCenter: { region . Rect . Center } , RectSize: { region . Rect . Size } , Angle: { region . Rect . Angle } ") ;
45- }
46- }
47- }
48- }
13+ //[Fact]
14+ //public async Task FastCheckOCR()
15+ //{
16+ // FullOcrModel model = await OnlineFullModels.EnglishV3.DownloadAsync();
17+
18+ // // from: https://visualstudio.microsoft.com/wp-content/uploads/2021/11/Home-page-extension-visual-updated.png
19+ // byte[] sampleImageData = File.ReadAllBytes(@"./samples/vsext.png");
20+
21+ // using (PaddleOcrAll all = new(model)
22+ // {
23+ // AllowRotateDetection = true,
24+ // Enable180Classification = false,
25+ // })
26+ // {
27+ // // Load local file by following code:
28+ // // using (Mat src2 = Cv2.ImRead(@"C:\test.jpg"))
29+ // using (Mat src = Cv2.ImDecode(sampleImageData, ImreadModes.Color))
30+ // {
31+ // Stopwatch sw = Stopwatch.StartNew();
32+ // PaddleOcrResult result = all.Run(src);
33+ // console.WriteLine($"lapsed={sw.ElapsedMilliseconds} ms");
34+ // console.WriteLine("Detected all texts: \n" + result.Text);
35+ // foreach (PaddleOcrResultRegion region in result.Regions)
36+ // {
37+ // console.WriteLine($"Text: {region.Text}, Score: {region.Score}, RectCenter: {region.Rect.Center}, RectSize: {region.Rect.Size}, Angle: {region.Rect.Angle}");
38+ // }
39+ // }
40+ // }
41+ //}
4942
5043 [ Fact ]
5144 public async Task V4MkldnnRecTest ( )
@@ -57,70 +50,40 @@ public async Task V4MkldnnRecTest()
5750 {
5851 Stopwatch sw = Stopwatch . StartNew ( ) ;
5952 PaddleOcrRecognizerResult result = r . Run ( src ) ;
60- _console . WriteLine ( $ "elapsed={ sw . ElapsedMilliseconds } ms") ;
61- _console . WriteLine ( result . ToString ( ) ) ;
53+ console . WriteLine ( $ "elapsed={ sw . ElapsedMilliseconds } ms") ;
54+ console . WriteLine ( result . ToString ( ) ) ;
6255 Assert . True ( result . Score > 0.9 ) ;
6356 }
6457 }
6558
66- [ Fact ]
67- public async Task V4FastCheckOCR ( )
68- {
69- OnlineFullModels onlineModels = new OnlineFullModels (
70- OnlineDetectionModel . ChineseV4 , OnlineClassificationModel . ChineseMobileV2 , LocalDictOnlineRecognizationModel . EnglishV4 ) ;
71- FullOcrModel model = await onlineModels . DownloadAsync ( ) ;
72-
73- // from: https://visualstudio.microsoft.com/wp-content/uploads/2021/11/Home-page-extension-visual-updated.png
74- byte [ ] sampleImageData = File . ReadAllBytes ( @"./samples/vsext.png" ) ;
75-
76- using ( PaddleOcrAll all = new ( model )
77- {
78- AllowRotateDetection = true ,
79- Enable180Classification = false ,
80- } )
81- {
82- // Load local file by following code:
83- // using (Mat src2 = Cv2.ImRead(@"C:\test.jpg"))
84- using ( Mat src = Cv2 . ImDecode ( sampleImageData , ImreadModes . Color ) )
85- {
86- PaddleOcrResult result = null ! ;
87- Stopwatch sw = Stopwatch . StartNew ( ) ;
88- result = all . Run ( src ) ;
89- sw . Stop ( ) ;
90-
91- _console . WriteLine ( $ "elapsed={ sw . ElapsedMilliseconds } ms") ;
92- _console . WriteLine ( "Detected all texts: \n " + result . Text ) ;
93- }
94- }
95- }
96-
97- [ Fact ( Skip = "Too slow" ) ]
98- public async Task V4ServerTest ( )
99- {
100- OnlineFullModels onlineModels = OnlineFullModels . ChineseServerV4 ;
101- FullOcrModel model = await onlineModels . DownloadAsync ( ) ;
102-
103- // from: https://visualstudio.microsoft.com/wp-content/uploads/2021/11/Home-page-extension-visual-updated.png
104- byte [ ] sampleImageData = File . ReadAllBytes ( @"./samples/vsext.png" ) ;
105-
106- using ( PaddleOcrAll all = new ( model )
107- {
108- AllowRotateDetection = true ,
109- Enable180Classification = false ,
110- } )
111- {
112- // Load local file by following code:
113- // using (Mat src2 = Cv2.ImRead(@"C:\test.jpg"))
114- using ( Mat src = Cv2 . ImDecode ( sampleImageData , ImreadModes . Color ) )
115- {
116- PaddleOcrResult result = null ! ;
117- Stopwatch sw = Stopwatch . StartNew ( ) ;
118- result = all . Run ( src ) ;
119- sw . Stop ( ) ;
120-
121- _console . WriteLine ( $ "elapsed={ sw . ElapsedMilliseconds } ms") ;
122- _console . WriteLine ( "Detected all texts: \n " + result . Text ) ;
123- }
124- }
125- }
59+ //[Fact]
60+ //public async Task V4FastCheckOCR()
61+ //{
62+ // OnlineFullModels onlineModels = new OnlineFullModels(
63+ // OnlineDetectionModel.ChineseV4, OnlineClassificationModel.ChineseMobileV2, LocalDictOnlineRecognizationModel.EnglishV4);
64+ // FullOcrModel model = await onlineModels.DownloadAsync();
65+
66+ // // from: https://visualstudio.microsoft.com/wp-content/uploads/2021/11/Home-page-extension-visual-updated.png
67+ // byte[] sampleImageData = File.ReadAllBytes(@"./samples/vsext.png");
68+
69+ // using (PaddleOcrAll all = new(model)
70+ // {
71+ // AllowRotateDetection = true,
72+ // Enable180Classification = false,
73+ // })
74+ // {
75+ // // Load local file by following code:
76+ // // using (Mat src2 = Cv2.ImRead(@"C:\test.jpg"))
77+ // using (Mat src = Cv2.ImDecode(sampleImageData, ImreadModes.Color))
78+ // {
79+ // PaddleOcrResult result = null!;
80+ // Stopwatch sw = Stopwatch.StartNew();
81+ // result = all.Run(src);
82+ // sw.Stop();
83+
84+ // _console.WriteLine($"elapsed={sw.ElapsedMilliseconds}ms");
85+ // _console.WriteLine("Detected all texts: \n" + result.Text);
86+ // }
87+ // }
88+ //}
12689}
0 commit comments