1+ classdef (SharedTestFixtures = {DownloadPretrainedCRAFTFixture }) tTextDetection < matlab .unittest .TestCase
2+ % Test for TextDetection
3+
4+ % Copyright 2021 The MathWorks, Inc.
5+
6+ % The shared test fixture downloads the model. Here we check the
7+ % inference on the pretrained model.
8+ properties
9+ RepoRoot = getRepoRoot;
10+ end
11+
12+ methods (Test )
13+ function exerciseDetection(test )
14+ model = load(fullfile(test .RepoRoot ,' model' ,' craftNet.mat' ));
15+ inpImage = imread(' businessCard.png' );
16+ outputNames = {' Conv_118' ,' Relu_109' };
17+ out = cell(size(outputNames ' ));
18+
19+ expectedBBoxes = [161.3333 , 61.3333 ,542.6667 , 61.3333 ,542.6667 ,145.3333 ,161.3333 ,145.3333 ;
20+ 169.3333 ,312.0000 ,192.0000 ,312.0000 ,192.0000 ,340.0000 ,169.3333 ,340.0000 ;
21+ 170.6667 ,272.0000 ,218.6667 ,272.0000 ,218.6667 ,304.0000 ,170.6667 ,304.0000 ;
22+ 170.6667 ,348.0000 ,260.0000 ,348.0000 ,260.0000 ,384.0000 ,170.6667 ,384.0000 ;
23+ 170.6667 ,386.6667 ,228.0000 ,386.6667 ,228.0000 ,418.6667 ,170.6667 ,418.6667 ;
24+ 170.6667 ,424.0000 ,416.0000 ,424.0000 ,416.0000 ,454.6667 ,170.6667 ,454.6667 ;
25+ 196.0000 ,310.6667 ,270.6667 ,310.6667 ,270.6667 ,349.3333 ,196.0000 ,349.3333 ;
26+ 217.6480 ,269.3688 ,363.4014 ,272.5033 ,362.6325 ,308.2573 ,216.8791 ,305.1228 ;
27+ 261.3333 ,349.3333 ,308.0000 ,349.3333 ,308.0000 ,380.0000 ,261.3333 ,380.0000 ;
28+ 270.6667 ,310.6667 ,314.6667 ,310.6667 ,314.6667 ,342.6667 ,270.6667 ,342.6667 ;
29+ 309.3333 ,349.3333 ,465.3333 ,349.3333 ,465.3333 ,381.3333 ,309.3333 ,381.3333 ;
30+ 314.6667 ,312.0000 ,381.3333 ,312.0000 ,381.3333 ,344.0000 ,314.6667 ,344.0000 ;
31+ 364.0000 ,276.0000 ,408.0000 ,276.0000 ,408.0000 ,304.0000 ,364.0000 ,304.0000 ];
32+ % Pre process
33+ [image , imageScale ] = helper .preprocess(inpImage );
34+
35+ % Inferance
36+ [out{: }] = predict(model .craftNet ,dlarray(image ,' SSCB' ),' Outputs' ,outputNames );
37+
38+ % Post process to get the boundingBoxes
39+ boundingBoxes = helper .postprocess(out ,imageScale );
40+
41+ test .verifyEqual(boundingBoxes ,expectedBBoxes ,' AbsTol' ,double(1e-4 ));
42+ end
43+ end
44+ end
0 commit comments