mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-05 19:30:30 +08:00
111 lines
32 KiB
Go
111 lines
32 KiB
Go
//
|
|
// Copyright 2020 FoxyUtils ehf. All rights reserved.
|
|
//
|
|
// This is a commercial product and requires a license to operate.
|
|
// A trial license can be obtained at https://unidoc.io
|
|
//
|
|
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
|
|
//
|
|
// Use of this source code is governed by the UniDoc End User License Agreement
|
|
// terms that can be accessed at https://unidoc.io/eula/
|
|
|
|
package classer ;import (_f "github.com/unidoc/unipdf/v3/common";_bb "github.com/unidoc/unipdf/v3/internal/jbig2/basic";_bd "github.com/unidoc/unipdf/v3/internal/jbig2/bitmap";_e "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_d "image";_b "math";
|
|
);func (_df *Classer )verifyMethod (_dff Method )error {if _dff !=RankHaus &&_dff !=Correlation {return _e .Error ("\u0076\u0065\u0072i\u0066\u0079\u004d\u0065\u0074\u0068\u006f\u0064","\u0069\u006e\u0076\u0061li\u0064\u0020\u0063\u006c\u0061\u0073\u0073\u0065\u0072\u0020\u006d\u0065\u0074\u0068o\u0064");
|
|
};return nil ;};func (_gab *Settings )SetDefault (){if _gab .MaxCompWidth ==0{switch _gab .Components {case _bd .ComponentConn :_gab .MaxCompWidth =MaxConnCompWidth ;case _bd .ComponentCharacters :_gab .MaxCompWidth =MaxCharCompWidth ;case _bd .ComponentWords :_gab .MaxCompWidth =MaxWordCompWidth ;
|
|
};};if _gab .MaxCompHeight ==0{_gab .MaxCompHeight =MaxCompHeight ;};if _gab .Thresh ==0.0{_gab .Thresh =0.9;};if _gab .WeightFactor ==0.0{_gab .WeightFactor =0.75;};if _gab .RankHaus ==0.0{_gab .RankHaus =0.97;};if _gab .SizeHaus ==0{_gab .SizeHaus =2;
|
|
};};const (MaxConnCompWidth =350;MaxCharCompWidth =350;MaxWordCompWidth =1000;MaxCompHeight =120;);type Method int ;type Settings struct{MaxCompWidth int ;MaxCompHeight int ;SizeHaus int ;RankHaus float64 ;Thresh float64 ;WeightFactor float64 ;KeepClassInstances bool ;
|
|
Components _bd .Component ;Method Method ;};func _cff (_fea *Classer ,_baa *_bd .Bitmap )*similarTemplatesFinder {return &similarTemplatesFinder {Width :_baa .Width ,Height :_baa .Height ,Classer :_fea };};func DefaultSettings ()Settings {_aedb :=&Settings {};
|
|
_aedb .SetDefault ();return *_aedb };func _fcf (_ed *_bd .Bitmap ,_ecg ,_aeb ,_bab ,_fed int ,_fef *_bd .Bitmap )(_cd _d .Point ,_eca error ){const _gg ="\u0066i\u006e\u0061\u006c\u0041l\u0069\u0067\u006e\u006d\u0065n\u0074P\u006fs\u0069\u0074\u0069\u006f\u006e\u0069\u006eg";
|
|
if _ed ==nil {return _cd ,_e .Error (_gg ,"\u0073\u006f\u0075\u0072ce\u0020\u006e\u006f\u0074\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};if _fef ==nil {return _cd ,_e .Error (_gg ,"t\u0065\u006d\u0070\u006cat\u0065 \u006e\u006f\u0074\u0020\u0070r\u006f\u0076\u0069\u0064\u0065\u0064");
|
|
};_agb ,_ggg :=_fef .Width ,_fef .Height ;_fg ,_fgg :=_ecg -_bab -JbAddedPixels ,_aeb -_fed -JbAddedPixels ;_f .Log .Trace ("\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u002c\u0020\u0079\u003a\u0020\u0027\u0025\u0064'\u002c\u0020\u0077\u003a\u0020\u0027\u0025\u0064\u0027\u002c\u0020\u0068\u003a \u0027\u0025\u0064\u0027\u002c\u0020\u0062\u0078\u003a\u0020\u0027\u0025d'\u002c\u0020\u0062\u0079\u003a\u0020\u0027\u0025\u0064\u0027",_ecg ,_aeb ,_agb ,_ggg ,_fg ,_fgg );
|
|
_abc ,_eca :=_bd .Rect (_fg ,_fgg ,_agb ,_ggg );if _eca !=nil {return _cd ,_e .Wrap (_eca ,_gg ,"");};_ccd ,_ ,_eca :=_ed .ClipRectangle (_abc );if _eca !=nil {_f .Log .Error ("\u0043a\u006e\u0027\u0074\u0020\u0063\u006c\u0069\u0070\u0020\u0072\u0065c\u0074\u0061\u006e\u0067\u006c\u0065\u003a\u0020\u0025\u0076",_abc );
|
|
return _cd ,_e .Wrap (_eca ,_gg ,"");};_ege :=_bd .New (_ccd .Width ,_ccd .Height );_bfb :=_b .MaxInt32 ;var _acb ,_bfbd ,_fcfb ,_ecgc ,_cg int ;for _acb =-1;_acb <=1;_acb ++{for _bfbd =-1;_bfbd <=1;_bfbd ++{if _ ,_eca =_bd .Copy (_ege ,_ccd );_eca !=nil {return _cd ,_e .Wrap (_eca ,_gg ,"");
|
|
};if _eca =_ege .RasterOperation (_bfbd ,_acb ,_agb ,_ggg ,_bd .PixSrcXorDst ,_fef ,0,0);_eca !=nil {return _cd ,_e .Wrap (_eca ,_gg ,"");};_fcfb =_ege .CountPixels ();if _fcfb < _bfb {_ecgc =_bfbd ;_cg =_acb ;_bfb =_fcfb ;};};};_cd .X =_ecgc ;_cd .Y =_cg ;
|
|
return _cd ,nil ;};func (_ab *Classer )ComputeLLCorners ()(_ga error ){const _ea ="\u0043l\u0061\u0073\u0073\u0065\u0072\u002e\u0043\u006f\u006d\u0070\u0075t\u0065\u004c\u004c\u0043\u006f\u0072\u006e\u0065\u0072\u0073";if _ab .PtaUL ==nil {return _e .Error (_ea ,"\u0055\u004c\u0020\u0043or\u006e\u0065\u0072\u0073\u0020\u006e\u006f\u0074\u0020\u0064\u0065\u0066\u0069\u006ee\u0064");
|
|
};_be :=len (*_ab .PtaUL );_ab .PtaLL =&_bd .Points {};var (_ag ,_bf float32 ;_dc ,_c int ;_gf *_bd .Bitmap ;);for _gba :=0;_gba < _be ;_gba ++{_ag ,_bf ,_ga =_ab .PtaUL .GetGeometry (_gba );if _ga !=nil {_f .Log .Debug ("\u0047e\u0074\u0074\u0069\u006e\u0067\u0020\u0050\u0074\u0061\u0055\u004c \u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0076",_ga );
|
|
return _e .Wrap (_ga ,_ea ,"\u0050\u0074\u0061\u0055\u004c\u0020\u0047\u0065\u006fm\u0065\u0074\u0072\u0079");};_dc ,_ga =_ab .ClassIDs .Get (_gba );if _ga !=nil {_f .Log .Debug ("\u0047\u0065\u0074\u0074\u0069\u006e\u0067\u0020\u0043\u006c\u0061s\u0073\u0049\u0044\u0020\u0066\u0061\u0069\u006c\u0065\u0064:\u0020\u0025\u0076",_ga );
|
|
return _e .Wrap (_ga ,_ea ,"\u0043l\u0061\u0073\u0073\u0049\u0044");};_gf ,_ga =_ab .UndilatedTemplates .GetBitmap (_dc );if _ga !=nil {_f .Log .Debug ("\u0047\u0065t\u0074\u0069\u006e\u0067 \u0055\u006ed\u0069\u006c\u0061\u0074\u0065\u0064\u0054\u0065m\u0070\u006c\u0061\u0074\u0065\u0073\u0020\u0066\u0061\u0069\u006c\u0065d\u003a\u0020\u0025\u0076",_ga );
|
|
return _e .Wrap (_ga ,_ea ,"\u0055\u006e\u0064\u0069la\u0074\u0065\u0064\u0020\u0054\u0065\u006d\u0070\u006c\u0061\u0074\u0065\u0073");};_c =_gf .Height ;_ab .PtaLL .AddPoint (_ag ,_bf +float32 (_c ));};return nil ;};func (_cc *Classer )addPageComponents (_aec *_bd .Bitmap ,_ca *_bd .Boxes ,_abf *_bd .Bitmaps ,_gc int ,_fc Method )error {const _agc ="\u0043l\u0061\u0073\u0073\u0065r\u002e\u0041\u0064\u0064\u0050a\u0067e\u0043o\u006d\u0070\u006f\u006e\u0065\u006e\u0074s";
|
|
if _aec ==nil {return _e .Error (_agc ,"\u006e\u0069\u006c\u0020\u0069\u006e\u0070\u0075\u0074 \u0070\u0061\u0067\u0065");};if _ca ==nil ||_abf ==nil ||len (*_ca )==0{_f .Log .Trace ("\u0041\u0064\u0064P\u0061\u0067\u0065\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074\u0073\u003a\u0020\u0025\u0073\u002e\u0020\u004e\u006f\u0020\u0063\u006f\u006d\u0070\u006f\u006e\u0065n\u0074\u0073\u0020\u0066\u006f\u0075\u006e\u0064",_aec );
|
|
return nil ;};var _ac error ;switch _fc {case RankHaus :_ac =_cc .classifyRankHaus (_ca ,_abf ,_gc );case Correlation :_ac =_cc .classifyCorrelation (_ca ,_abf ,_gc );default:_f .Log .Debug ("\u0055\u006ek\u006e\u006f\u0077\u006e\u0020\u0063\u006c\u0061\u0073\u0073\u0069\u0066\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0064\u003a\u0020'%\u0076\u0027",_fc );
|
|
return _e .Error (_agc ,"\u0075\u006e\u006bno\u0077\u006e\u0020\u0063\u006c\u0061\u0073\u0073\u0069\u0066\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0064");};if _ac !=nil {return _e .Wrap (_ac ,_agc ,"");};if _ac =_cc .getULCorners (_aec ,_ca );_ac !=nil {return _e .Wrap (_ac ,_agc ,"");
|
|
};_ad :=len (*_ca );_cc .BaseIndex +=_ad ;if _ac =_cc .ComponentsNumber .Add (_ad );_ac !=nil {return _e .Wrap (_ac ,_agc ,"");};return nil ;};const (RankHaus Method =iota ;Correlation ;);const JbAddedPixels =6;func (_acbg *Classer )classifyCorrelation (_dbd *_bd .Boxes ,_ccc *_bd .Bitmaps ,_gaf int )error {const _cf ="\u0063\u006c\u0061\u0073si\u0066\u0079\u0043\u006f\u0072\u0072\u0065\u006c\u0061\u0074\u0069\u006f\u006e";
|
|
if _dbd ==nil {return _e .Error (_cf ,"\u006e\u0065\u0077\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074\u0073\u0020\u0062\u006f\u0075\u006e\u0064\u0069\u006e\u0067\u0020\u0062o\u0078\u0065\u0073\u0020\u006eo\u0074\u0020f\u006f\u0075\u006e\u0064");
|
|
};if _ccc ==nil {return _e .Error (_cf ,"\u006e\u0065wC\u006f\u006d\u0070o\u006e\u0065\u006e\u0074s b\u0069tm\u0061\u0070\u0020\u0061\u0072\u0072\u0061y \u006e\u006f\u0074\u0020\u0066\u006f\u0075n\u0064");};_degd :=len (_ccc .Values );if _degd ==0{_f .Log .Debug ("\u0063l\u0061\u0073s\u0069\u0066\u0079C\u006f\u0072\u0072\u0065\u006c\u0061\u0074i\u006f\u006e\u0020\u002d\u0020\u0070r\u006f\u0076\u0069\u0064\u0065\u0064\u0020\u0070\u0069\u0078\u0061s\u0020\u0069\u0073\u0020\u0065\u006d\u0070\u0074\u0079");
|
|
return nil ;};var (_agg ,_abg *_bd .Bitmap ;_cdf error ;);_eea :=&_bd .Bitmaps {Values :make ([]*_bd .Bitmap ,_degd )};for _aea ,_fa :=range _ccc .Values {_abg ,_cdf =_fa .AddBorderGeneral (JbAddedPixels ,JbAddedPixels ,JbAddedPixels ,JbAddedPixels ,0);
|
|
if _cdf !=nil {return _e .Wrap (_cdf ,_cf ,"");};_eea .Values [_aea ]=_abg ;};_afg :=_acbg .FgTemplates ;_dfa :=_bd .MakePixelSumTab8 ();_gga :=_bd .MakePixelCentroidTab8 ();_aggb :=make ([]int ,_degd );_fb :=make ([][]int ,_degd );_da :=_bd .Points (make ([]_bd .Point ,_degd ));
|
|
_gbaf :=&_da ;var (_bbe ,_cgg int ;_adf ,_gfa ,_faf int ;_bdg ,_fbf int ;_ecb byte ;);for _eeg ,_add :=range _eea .Values {_fb [_eeg ]=make ([]int ,_add .Height );_bbe =0;_cgg =0;_gfa =(_add .Height -1)*_add .RowStride ;_adf =0;for _fbf =_add .Height -1;
|
|
_fbf >=0;_fbf ,_gfa =_fbf -1,_gfa -_add .RowStride {_fb [_eeg ][_fbf ]=_adf ;_faf =0;for _bdg =0;_bdg < _add .RowStride ;_bdg ++{_ecb =_add .Data [_gfa +_bdg ];_faf +=_dfa [_ecb ];_bbe +=_gga [_ecb ]+_bdg *8*_dfa [_ecb ];};_adf +=_faf ;_cgg +=_faf *_fbf ;
|
|
};_aggb [_eeg ]=_adf ;if _adf > 0{(*_gbaf )[_eeg ]=_bd .Point {X :float32 (_bbe )/float32 (_adf ),Y :float32 (_cgg )/float32 (_adf )};}else {(*_gbaf )[_eeg ]=_bd .Point {X :float32 (_add .Width )/float32 (2),Y :float32 (_add .Height )/float32 (2)};};};
|
|
if _cdf =_acbg .CentroidPoints .Add (_gbaf );_cdf !=nil {return _e .Wrap (_cdf ,_cf ,"\u0063\u0065\u006et\u0072\u006f\u0069\u0064\u0020\u0061\u0064\u0064");};var (_gcc ,_aa ,_cge int ;_eec float64 ;_beed ,_fca ,_faa ,_acf float32 ;_bae ,_dca _bd .Point ;
|
|
_gff bool ;_fce *similarTemplatesFinder ;_adb int ;_dcg *_bd .Bitmap ;_degb *_d .Rectangle ;_dd *_bd .Bitmaps ;);for _adb ,_abg =range _eea .Values {_aa =_aggb [_adb ];if _beed ,_fca ,_cdf =_gbaf .GetGeometry (_adb );_cdf !=nil {return _e .Wrap (_cdf ,_cf ,"\u0070t\u0061\u0020\u002d\u0020\u0069");
|
|
};_gff =false ;_afa :=len (_acbg .UndilatedTemplates .Values );_fce =_cff (_acbg ,_abg );for _caf :=_fce .Next ();_caf > -1;{if _dcg ,_cdf =_acbg .UndilatedTemplates .GetBitmap (_caf );_cdf !=nil {return _e .Wrap (_cdf ,_cf ,"\u0075\u006e\u0069dl\u0061\u0074\u0065\u0064\u005b\u0069\u0063\u006c\u0061\u0073\u0073\u005d\u0020\u003d\u0020\u0062\u006d\u0032");
|
|
};if _cge ,_cdf =_afg .GetInt (_caf );_cdf !=nil {_f .Log .Trace ("\u0046\u0047\u0020T\u0065\u006d\u0070\u006ca\u0074\u0065\u0020\u005b\u0069\u0063\u006ca\u0073\u0073\u005d\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0076",_cdf );};if _faa ,_acf ,_cdf =_acbg .CentroidPointsTemplates .GetGeometry (_caf );
|
|
_cdf !=nil {return _e .Wrap (_cdf ,_cf ,"\u0043\u0065\u006e\u0074\u0072\u006f\u0069\u0064\u0050\u006f\u0069\u006e\u0074T\u0065\u006d\u0070\u006c\u0061\u0074e\u0073\u005b\u0069\u0063\u006c\u0061\u0073\u0073\u005d\u0020\u003d\u0020\u00782\u002c\u0079\u0032\u0020");
|
|
};if _acbg .Settings .WeightFactor > 0.0{if _gcc ,_cdf =_acbg .TemplateAreas .Get (_caf );_cdf !=nil {_f .Log .Trace ("\u0054\u0065\u006dp\u006c\u0061\u0074\u0065A\u0072\u0065\u0061\u0073\u005b\u0069\u0063l\u0061\u0073\u0073\u005d\u0020\u003d\u0020\u0061\u0072\u0065\u0061\u0020\u0025\u0076",_cdf );
|
|
};_eec =_acbg .Settings .Thresh +(1.0-_acbg .Settings .Thresh )*_acbg .Settings .WeightFactor *float64 (_cge )/float64 (_gcc );}else {_eec =_acbg .Settings .Thresh ;};_adg ,_cb :=_bd .CorrelationScoreThresholded (_abg ,_dcg ,_aa ,_cge ,_bae .X -_dca .X ,_bae .Y -_dca .Y ,MaxDiffWidth ,MaxDiffHeight ,_dfa ,_fb [_adb ],float32 (_eec ));
|
|
if _cb !=nil {return _e .Wrap (_cb ,_cf ,"");};if _dfc {var (_aggd ,_dee float64 ;_ddf ,_cda int ;);_aggd ,_cb =_bd .CorrelationScore (_abg ,_dcg ,_aa ,_cge ,_beed -_faa ,_fca -_acf ,MaxDiffWidth ,MaxDiffHeight ,_dfa );if _cb !=nil {return _e .Wrap (_cb ,_cf ,"d\u0065\u0062\u0075\u0067Co\u0072r\u0065\u006c\u0061\u0074\u0069o\u006e\u0053\u0063\u006f\u0072\u0065");
|
|
};_dee ,_cb =_bd .CorrelationScoreSimple (_abg ,_dcg ,_aa ,_cge ,_beed -_faa ,_fca -_acf ,MaxDiffWidth ,MaxDiffHeight ,_dfa );if _cb !=nil {return _e .Wrap (_cb ,_cf ,"d\u0065\u0062\u0075\u0067Co\u0072r\u0065\u006c\u0061\u0074\u0069o\u006e\u0053\u0063\u006f\u0072\u0065");
|
|
};_ddf =int (_b .Sqrt (_aggd *float64 (_aa )*float64 (_cge )));_cda =int (_b .Sqrt (_dee *float64 (_aa )*float64 (_cge )));if (_aggd >=_eec )!=(_dee >=_eec ){return _e .Errorf (_cf ,"\u0064\u0065\u0062\u0075\u0067\u0020\u0043\u006f\u0072r\u0065\u006c\u0061\u0074\u0069\u006f\u006e\u0020\u0073\u0063\u006f\u0072\u0065\u0020\u006d\u0069\u0073\u006d\u0061\u0074\u0063\u0068\u0020-\u0020\u0025d\u0028\u00250\u002e\u0034\u0066\u002c\u0020\u0025\u0076\u0029\u0020\u0076\u0073\u0020\u0025d(\u0025\u0030\u002e\u0034\u0066\u002c\u0020\u0025\u0076)\u0020\u0025\u0030\u002e\u0034\u0066",_ddf ,_aggd ,_aggd >=_eec ,_cda ,_dee ,_dee >=_eec ,_aggd -_dee );
|
|
};if _aggd >=_eec !=_adg {return _e .Errorf (_cf ,"\u0064\u0065\u0062\u0075\u0067\u0020\u0043o\u0072\u0072\u0065\u006c\u0061\u0074\u0069\u006f\u006e \u0073\u0063\u006f\u0072\u0065 \u004d\u0069\u0073\u006d\u0061t\u0063\u0068 \u0062\u0065\u0074w\u0065\u0065\u006e\u0020\u0063\u006frr\u0065\u006c\u0061\u0074\u0069\u006f\u006e\u0020/\u0020\u0074\u0068\u0072\u0065s\u0068\u006f\u006c\u0064\u002e\u0020\u0043\u006f\u006dpa\u0072\u0069\u0073\u006f\u006e:\u0020\u0025\u0030\u002e\u0034\u0066\u0028\u0025\u0030\u002e\u0034\u0066\u002c\u0020\u0025\u0064\u0029\u0020\u003e\u003d\u0020\u00250\u002e\u0034\u0066\u0028\u0025\u0030\u002e\u0034\u0066\u0029\u0020\u0076\u0073\u0020\u0025\u0076",_aggd ,_aggd *float64 (_aa )*float64 (_cge ),_ddf ,_eec ,float32 (_eec )*float32 (_aa )*float32 (_cge ),_adg );
|
|
};};if _adg {_gff =true ;if _cb =_acbg .ClassIDs .Add (_caf );_cb !=nil {return _e .Wrap (_cb ,_cf ,"\u006f\u0076\u0065\u0072\u0054\u0068\u0072\u0065\u0073\u0068\u006f\u006c\u0064");};if _cb =_acbg .ComponentPageNumbers .Add (_gaf );_cb !=nil {return _e .Wrap (_cb ,_cf ,"\u006f\u0076\u0065\u0072\u0054\u0068\u0072\u0065\u0073\u0068\u006f\u006c\u0064");
|
|
};if _acbg .Settings .KeepClassInstances {if _agg ,_cb =_ccc .GetBitmap (_adb );_cb !=nil {return _e .Wrap (_cb ,_cf ,"\u004b\u0065\u0065\u0070Cl\u0061\u0073\u0073\u0049\u006e\u0073\u0074\u0061\u006e\u0063\u0065\u0073\u0020\u002d \u0069");};if _dd ,_cb =_acbg .ClassInstances .GetBitmaps (_caf );
|
|
_cb !=nil {return _e .Wrap (_cb ,_cf ,"K\u0065\u0065\u0070\u0043\u006c\u0061s\u0073\u0049\u006e\u0073\u0074\u0061\u006e\u0063\u0065s\u0020\u002d\u0020i\u0043l\u0061\u0073\u0073");};_dd .AddBitmap (_agg );if _degb ,_cb =_dbd .Get (_adb );_cb !=nil {return _e .Wrap (_cb ,_cf ,"\u004be\u0065p\u0043\u006c\u0061\u0073\u0073I\u006e\u0073t\u0061\u006e\u0063\u0065\u0073");
|
|
};_dd .AddBox (_degb );};break ;};};if !_gff {if _cdf =_acbg .ClassIDs .Add (_afa );_cdf !=nil {return _e .Wrap (_cdf ,_cf ,"\u0021\u0066\u006f\u0075\u006e\u0064");};if _cdf =_acbg .ComponentPageNumbers .Add (_gaf );_cdf !=nil {return _e .Wrap (_cdf ,_cf ,"\u0021\u0066\u006f\u0075\u006e\u0064");
|
|
};_dd =&_bd .Bitmaps {};if _agg ,_cdf =_ccc .GetBitmap (_adb );_cdf !=nil {return _e .Wrap (_cdf ,_cf ,"\u0021\u0066\u006f\u0075\u006e\u0064");};_dd .AddBitmap (_agg );_ece ,_acfc :=_agg .Width ,_agg .Height ;_bc :=uint64 (_acfc )*uint64 (_ece );_acbg .TemplatesSize .Add (_bc ,_afa );
|
|
if _degb ,_cdf =_dbd .Get (_adb );_cdf !=nil {return _e .Wrap (_cdf ,_cf ,"\u0021\u0066\u006f\u0075\u006e\u0064");};_dd .AddBox (_degb );_acbg .ClassInstances .AddBitmaps (_dd );_acbg .CentroidPointsTemplates .AddPoint (_beed ,_fca );_acbg .FgTemplates .AddInt (_aa );
|
|
_acbg .UndilatedTemplates .AddBitmap (_agg );_gcc =(_abg .Width -2*JbAddedPixels )*(_abg .Height -2*JbAddedPixels );if _cdf =_acbg .TemplateAreas .Add (_gcc );_cdf !=nil {return _e .Wrap (_cdf ,_cf ,"\u0021\u0066\u006f\u0075\u006e\u0064");};};};_acbg .NumberOfClasses =len (_acbg .UndilatedTemplates .Values );
|
|
return nil ;};var TwoByTwoWalk =[]int {0,0,0,1,-1,0,0,-1,1,0,-1,1,1,1,-1,-1,1,-1,0,-2,2,0,0,2,-2,0,-1,-2,1,-2,2,-1,2,1,1,2,-1,2,-2,1,-2,-1,-2,-2,2,-2,2,2,-2,2};func Init (settings Settings )(*Classer ,error ){const _ba ="\u0063\u006c\u0061s\u0073\u0065\u0072\u002e\u0049\u006e\u0069\u0074";
|
|
_gb :=&Classer {Settings :settings ,Widths :map[int ]int {},Heights :map[int ]int {},TemplatesSize :_bb .IntsMap {},TemplateAreas :&_bb .IntSlice {},ComponentPageNumbers :&_bb .IntSlice {},ClassIDs :&_bb .IntSlice {},ComponentsNumber :&_bb .IntSlice {},CentroidPoints :&_bd .Points {},CentroidPointsTemplates :&_bd .Points {},UndilatedTemplates :&_bd .Bitmaps {},DilatedTemplates :&_bd .Bitmaps {},ClassInstances :&_bd .BitmapsArray {},FgTemplates :&_bb .NumSlice {}};
|
|
if _a :=_gb .Settings .Validate ();_a !=nil {return nil ,_e .Wrap (_a ,_ba ,"");};return _gb ,nil ;};func (_bedd Settings )Validate ()error {const _dfe ="\u0053\u0065\u0074\u0074\u0069\u006e\u0067\u0073\u002e\u0056\u0061\u006ci\u0064\u0061\u0074\u0065";
|
|
if _bedd .Thresh < 0.4||_bedd .Thresh > 0.98{return _e .Error (_dfe ,"\u006a\u0062i\u0067\u0032\u0020\u0065\u006e\u0063\u006f\u0064\u0065\u0072\u0020\u0074\u0068\u0072\u0065\u0073\u0068\u0020\u006e\u006f\u0074\u0020\u0069\u006e\u0020\u0072\u0061\u006e\u0067\u0065\u0020\u005b\u0030\u002e\u0034\u0020\u002d\u0020\u0030\u002e\u0039\u0038\u005d");
|
|
};if _bedd .WeightFactor < 0.0||_bedd .WeightFactor > 1.0{return _e .Error (_dfe ,"\u006a\u0062i\u0067\u0032\u0020\u0065\u006ec\u006f\u0064\u0065\u0072\u0020w\u0065\u0069\u0067\u0068\u0074\u0020\u0066\u0061\u0063\u0074\u006f\u0072\u0020\u006e\u006f\u0074\u0020\u0069\u006e\u0020\u0072\u0061\u006e\u0067\u0065\u0020\u005b\u0030\u002e\u0030\u0020\u002d\u0020\u0031\u002e\u0030\u005d");
|
|
};if _bedd .RankHaus < 0.5||_bedd .RankHaus > 1.0{return _e .Error (_dfe ,"\u006a\u0062\u0069\u0067\u0032\u0020\u0065\u006e\u0063\u006f\u0064\u0065\u0072\u0020\u0072a\u006e\u006b\u0020\u0068\u0061\u0075\u0073\u0020\u0076\u0061\u006c\u0075\u0065 \u006e\u006f\u0074\u0020\u0069\u006e\u0020\u0072\u0061\u006e\u0067\u0065 [\u0030\u002e\u0035\u0020\u002d\u0020\u0031\u002e\u0030\u005d");
|
|
};if _bedd .SizeHaus < 1||_bedd .SizeHaus > 10{return _e .Error (_dfe ,"\u006a\u0062\u0069\u0067\u0032 \u0065\u006e\u0063\u006f\u0064\u0065\u0072\u0020\u0073\u0069\u007a\u0065\u0020h\u0061\u0075\u0073\u0020\u0076\u0061\u006c\u0075\u0065\u0020\u006e\u006f\u0074\u0020\u0069\u006e\u0020\u0072\u0061\u006e\u0067\u0065\u0020\u005b\u0031\u0020\u002d\u0020\u0031\u0030]");
|
|
};switch _bedd .Components {case _bd .ComponentConn ,_bd .ComponentCharacters ,_bd .ComponentWords :default:return _e .Error (_dfe ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0063\u006c\u0061\u0073s\u0065r\u0020c\u006f\u006d\u0070\u006f\u006e\u0065\u006et");
|
|
};return nil ;};var _dfc bool ;func (_bbbe *Classer )classifyRankHaus (_fae *_bd .Boxes ,_ebe *_bd .Bitmaps ,_agcc int )error {const _bfc ="\u0063\u006ca\u0073\u0073\u0069f\u0079\u0052\u0061\u006e\u006b\u0048\u0061\u0075\u0073";if _fae ==nil {return _e .Error (_bfc ,"\u0062\u006fx\u0061\u0020\u006eo\u0074\u0020\u0064\u0065\u0066\u0069\u006e\u0065\u0064");
|
|
};if _ebe ==nil {return _e .Error (_bfc ,"\u0070\u0069x\u0061\u0020\u006eo\u0074\u0020\u0064\u0065\u0066\u0069\u006e\u0065\u0064");};_cgf :=len (_ebe .Values );if _cgf ==0{return _e .Error (_bfc ,"e\u006dp\u0074\u0079\u0020\u006e\u0065\u0077\u0020\u0063o\u006d\u0070\u006f\u006een\u0074\u0073");
|
|
};_dg :=_ebe .CountPixels ();_gdd :=_bbbe .Settings .SizeHaus ;_dfcd :=_bd .SelCreateBrick (_gdd ,_gdd ,_gdd /2,_gdd /2,_bd .SelHit );_dcag :=&_bd .Bitmaps {Values :make ([]*_bd .Bitmap ,_cgf )};_gbge :=&_bd .Bitmaps {Values :make ([]*_bd .Bitmap ,_cgf )};
|
|
var (_ff ,_aed ,_dcge *_bd .Bitmap ;_dag error ;);for _bdd :=0;_bdd < _cgf ;_bdd ++{_ff ,_dag =_ebe .GetBitmap (_bdd );if _dag !=nil {return _e .Wrap (_dag ,_bfc ,"");};_aed ,_dag =_ff .AddBorderGeneral (JbAddedPixels ,JbAddedPixels ,JbAddedPixels ,JbAddedPixels ,0);
|
|
if _dag !=nil {return _e .Wrap (_dag ,_bfc ,"");};_dcge ,_dag =_bd .Dilate (nil ,_aed ,_dfcd );if _dag !=nil {return _e .Wrap (_dag ,_bfc ,"");};_dcag .Values [_cgf ]=_aed ;_gbge .Values [_cgf ]=_dcge ;};_cdd ,_dag :=_bd .Centroids (_dcag .Values );if _dag !=nil {return _e .Wrap (_dag ,_bfc ,"");
|
|
};if _dag =_cdd .Add (_bbbe .CentroidPoints );_dag !=nil {_f .Log .Trace ("\u004e\u006f\u0020\u0063en\u0074\u0072\u006f\u0069\u0064\u0073\u0020\u0074\u006f\u0020\u0061\u0064\u0064");};if _bbbe .Settings .RankHaus ==1.0{_dag =_bbbe .classifyRankHouseOne (_fae ,_ebe ,_dcag ,_gbge ,_cdd ,_agcc );
|
|
}else {_dag =_bbbe .classifyRankHouseNonOne (_fae ,_ebe ,_dcag ,_gbge ,_cdd ,_dg ,_agcc );};if _dag !=nil {return _e .Wrap (_dag ,_bfc ,"");};return nil ;};func (_aecb *Classer )classifyRankHouseOne (_abd *_bd .Boxes ,_efg ,_aga ,_fba *_bd .Bitmaps ,_aab *_bd .Points ,_bddg int )(_dgd error ){const _cag ="\u0043\u006c\u0061\u0073s\u0065\u0072\u002e\u0063\u006c\u0061\u0073\u0073\u0069\u0066y\u0052a\u006e\u006b\u0048\u006f\u0075\u0073\u0065O\u006e\u0065";
|
|
var (_adc ,_eba ,_gbb ,_cgd float32 ;_fga int ;_deb ,_dcbb ,_fceg ,_gcb ,_eac *_bd .Bitmap ;_cdg ,_ccb bool ;);for _abdc :=0;_abdc < len (_efg .Values );_abdc ++{_dcbb =_aga .Values [_abdc ];_fceg =_fba .Values [_abdc ];_adc ,_eba ,_dgd =_aab .GetGeometry (_abdc );
|
|
if _dgd !=nil {return _e .Wrapf (_dgd ,_cag ,"\u0066\u0069\u0072\u0073\u0074\u0020\u0067\u0065\u006fm\u0065\u0074\u0072\u0079");};_deeb :=len (_aecb .UndilatedTemplates .Values );_cdg =false ;_gdf :=_cff (_aecb ,_dcbb );for _fga =_gdf .Next ();_fga > -1;
|
|
{_gcb ,_dgd =_aecb .UndilatedTemplates .GetBitmap (_fga );if _dgd !=nil {return _e .Wrap (_dgd ,_cag ,"\u0062\u006d\u0033");};_eac ,_dgd =_aecb .DilatedTemplates .GetBitmap (_fga );if _dgd !=nil {return _e .Wrap (_dgd ,_cag ,"\u0062\u006d\u0034");};_gbb ,_cgd ,_dgd =_aecb .CentroidPointsTemplates .GetGeometry (_fga );
|
|
if _dgd !=nil {return _e .Wrap (_dgd ,_cag ,"\u0043\u0065\u006e\u0074\u0072\u006f\u0069\u0064\u0054\u0065\u006d\u0070l\u0061\u0074\u0065\u0073");};_ccb ,_dgd =_bd .HausTest (_dcbb ,_fceg ,_gcb ,_eac ,_adc -_gbb ,_eba -_cgd ,MaxDiffWidth ,MaxDiffHeight );
|
|
if _dgd !=nil {return _e .Wrap (_dgd ,_cag ,"");};if _ccb {_cdg =true ;if _dgd =_aecb .ClassIDs .Add (_fga );_dgd !=nil {return _e .Wrap (_dgd ,_cag ,"");};if _dgd =_aecb .ComponentPageNumbers .Add (_bddg );_dgd !=nil {return _e .Wrap (_dgd ,_cag ,"");
|
|
};if _aecb .Settings .KeepClassInstances {_eee ,_cdc :=_aecb .ClassInstances .GetBitmaps (_fga );if _cdc !=nil {return _e .Wrap (_cdc ,_cag ,"\u004be\u0065\u0070\u0050\u0069\u0078\u0061a");};_deb ,_cdc =_efg .GetBitmap (_abdc );if _cdc !=nil {return _e .Wrap (_cdc ,_cag ,"\u004be\u0065\u0070\u0050\u0069\u0078\u0061a");
|
|
};_eee .AddBitmap (_deb );_cbd ,_cdc :=_abd .Get (_abdc );if _cdc !=nil {return _e .Wrap (_cdc ,_cag ,"\u004be\u0065\u0070\u0050\u0069\u0078\u0061a");};_eee .AddBox (_cbd );};break ;};};if !_cdg {if _dgd =_aecb .ClassIDs .Add (_deeb );_dgd !=nil {return _e .Wrap (_dgd ,_cag ,"");
|
|
};if _dgd =_aecb .ComponentPageNumbers .Add (_bddg );_dgd !=nil {return _e .Wrap (_dgd ,_cag ,"");};_ddg :=&_bd .Bitmaps {};_deb ,_dgd =_efg .GetBitmap (_abdc );if _dgd !=nil {return _e .Wrap (_dgd ,_cag ,"\u0021\u0066\u006f\u0075\u006e\u0064");};_ddg .Values =append (_ddg .Values ,_deb );
|
|
_ecf ,_caa :=_deb .Width ,_deb .Height ;_aecb .TemplatesSize .Add (uint64 (_caa )*uint64 (_ecf ),_deeb );_fgf ,_bed :=_abd .Get (_abdc );if _bed !=nil {return _e .Wrap (_bed ,_cag ,"\u0021\u0066\u006f\u0075\u006e\u0064");};_ddg .AddBox (_fgf );_aecb .ClassInstances .AddBitmaps (_ddg );
|
|
_aecb .CentroidPointsTemplates .AddPoint (_adc ,_eba );_aecb .UndilatedTemplates .AddBitmap (_dcbb );_aecb .DilatedTemplates .AddBitmap (_fceg );};};return nil ;};type Classer struct{BaseIndex int ;Settings Settings ;ComponentsNumber *_bb .IntSlice ;TemplateAreas *_bb .IntSlice ;
|
|
Widths map[int ]int ;Heights map[int ]int ;NumberOfClasses int ;ClassInstances *_bd .BitmapsArray ;UndilatedTemplates *_bd .Bitmaps ;DilatedTemplates *_bd .Bitmaps ;TemplatesSize _bb .IntsMap ;FgTemplates *_bb .NumSlice ;CentroidPoints *_bd .Points ;CentroidPointsTemplates *_bd .Points ;
|
|
ClassIDs *_bb .IntSlice ;ComponentPageNumbers *_bb .IntSlice ;PtaUL *_bd .Points ;PtaLL *_bd .Points ;};func (_ee *Classer )AddPage (inputPage *_bd .Bitmap ,pageNumber int ,method Method )(_gbf error ){const _ae ="\u0043l\u0061s\u0073\u0065\u0072\u002e\u0041\u0064\u0064\u0050\u0061\u0067\u0065";
|
|
_ee .Widths [pageNumber ]=inputPage .Width ;_ee .Heights [pageNumber ]=inputPage .Height ;if _gbf =_ee .verifyMethod (method );_gbf !=nil {return _e .Wrap (_gbf ,_ae ,"");};_af ,_ef ,_gbf :=inputPage .GetComponents (_ee .Settings .Components ,_ee .Settings .MaxCompWidth ,_ee .Settings .MaxCompHeight );
|
|
if _gbf !=nil {return _e .Wrap (_gbf ,_ae ,"");};_f .Log .Debug ("\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074s\u003a\u0020\u0025\u0076",_af );if _gbf =_ee .addPageComponents (inputPage ,_ef ,_af ,pageNumber ,method );_gbf !=nil {return _e .Wrap (_gbf ,_ae ,"");
|
|
};return nil ;};func (_efbe *Classer )classifyRankHouseNonOne (_acd *_bd .Boxes ,_ccg ,_bfg ,_cdga *_bd .Bitmaps ,_edf *_bd .Points ,_dec *_bb .NumSlice ,_gdc int )(_dae error ){const _abff ="\u0043\u006c\u0061\u0073s\u0065\u0072\u002e\u0063\u006c\u0061\u0073\u0073\u0069\u0066y\u0052a\u006e\u006b\u0048\u006f\u0075\u0073\u0065O\u006e\u0065";
|
|
var (_gae ,_cgc ,_aggbc ,_feg float32 ;_gce ,_faea ,_gdca int ;_ggb ,_ge ,_gafc ,_dcf ,_dcagb *_bd .Bitmap ;_fac ,_dbdd bool ;);_ggd :=_bd .MakePixelSumTab8 ();for _fefb :=0;_fefb < len (_ccg .Values );_fefb ++{if _ge ,_dae =_bfg .GetBitmap (_fefb );_dae !=nil {return _e .Wrap (_dae ,_abff ,"b\u006d\u0073\u0031\u002e\u0047\u0065\u0074\u0028\u0069\u0029");
|
|
};if _gce ,_dae =_dec .GetInt (_fefb );_dae !=nil {_f .Log .Trace ("\u0047\u0065t\u0074\u0069\u006e\u0067 \u0046\u0047T\u0065\u006d\u0070\u006c\u0061\u0074\u0065\u0073 \u0061\u0074\u003a\u0020\u0025\u0064\u0020\u0066\u0061\u0069\u006c\u0065d\u003a\u0020\u0025\u0076",_fefb ,_dae );
|
|
};if _gafc ,_dae =_cdga .GetBitmap (_fefb );_dae !=nil {return _e .Wrap (_dae ,_abff ,"b\u006d\u0073\u0032\u002e\u0047\u0065\u0074\u0028\u0069\u0029");};if _gae ,_cgc ,_dae =_edf .GetGeometry (_fefb );_dae !=nil {return _e .Wrapf (_dae ,_abff ,"\u0070t\u0061[\u0069\u005d\u002e\u0047\u0065\u006f\u006d\u0065\u0074\u0072\u0079");
|
|
};_ddfa :=len (_efbe .UndilatedTemplates .Values );_fac =false ;_bda :=_cff (_efbe ,_ge );for _gdca =_bda .Next ();_gdca > -1;{if _dcf ,_dae =_efbe .UndilatedTemplates .GetBitmap (_gdca );_dae !=nil {return _e .Wrap (_dae ,_abff ,"\u0070\u0069\u0078\u0061\u0074\u002e\u005b\u0069\u0043l\u0061\u0073\u0073\u005d");
|
|
};if _faea ,_dae =_efbe .FgTemplates .GetInt (_gdca );_dae !=nil {_f .Log .Trace ("\u0047\u0065\u0074\u0074\u0069\u006eg\u0020\u0046\u0047\u0054\u0065\u006d\u0070\u006c\u0061\u0074\u0065\u005b\u0025d\u005d\u0020\u0066\u0061\u0069\u006c\u0065d\u003a\u0020\u0025\u0076",_gdca ,_dae );
|
|
};if _dcagb ,_dae =_efbe .DilatedTemplates .GetBitmap (_gdca );_dae !=nil {return _e .Wrap (_dae ,_abff ,"\u0070\u0069\u0078\u0061\u0074\u0064\u005b\u0069\u0043l\u0061\u0073\u0073\u005d");};if _aggbc ,_feg ,_dae =_efbe .CentroidPointsTemplates .GetGeometry (_gdca );
|
|
_dae !=nil {return _e .Wrap (_dae ,_abff ,"\u0043\u0065\u006et\u0072\u006f\u0069\u0064P\u006f\u0069\u006e\u0074\u0073\u0054\u0065m\u0070\u006c\u0061\u0074\u0065\u0073\u005b\u0069\u0043\u006c\u0061\u0073\u0073\u005d");};_dbdd ,_dae =_bd .RankHausTest (_ge ,_gafc ,_dcf ,_dcagb ,_gae -_aggbc ,_cgc -_feg ,MaxDiffWidth ,MaxDiffHeight ,_gce ,_faea ,float32 (_efbe .Settings .RankHaus ),_ggd );
|
|
if _dae !=nil {return _e .Wrap (_dae ,_abff ,"");};if _dbdd {_fac =true ;if _dae =_efbe .ClassIDs .Add (_gdca );_dae !=nil {return _e .Wrap (_dae ,_abff ,"");};if _dae =_efbe .ComponentPageNumbers .Add (_gdc );_dae !=nil {return _e .Wrap (_dae ,_abff ,"");
|
|
};if _efbe .Settings .KeepClassInstances {_efbc ,_gcec :=_efbe .ClassInstances .GetBitmaps (_gdca );if _gcec !=nil {return _e .Wrap (_gcec ,_abff ,"\u0063\u002e\u0050\u0069\u0078\u0061\u0061\u002e\u0047\u0065\u0074B\u0069\u0074\u006d\u0061\u0070\u0073\u0028\u0069\u0043\u006ca\u0073\u0073\u0029");
|
|
};if _ggb ,_gcec =_ccg .GetBitmap (_fefb );_gcec !=nil {return _e .Wrap (_gcec ,_abff ,"\u0070i\u0078\u0061\u005b\u0069\u005d");};_efbc .Values =append (_efbc .Values ,_ggb );_afc ,_gcec :=_acd .Get (_fefb );if _gcec !=nil {return _e .Wrap (_gcec ,_abff ,"b\u006f\u0078\u0061\u002e\u0047\u0065\u0074\u0028\u0069\u0029");
|
|
};_efbc .Boxes =append (_efbc .Boxes ,_afc );};break ;};};if !_fac {if _dae =_efbe .ClassIDs .Add (_ddfa );_dae !=nil {return _e .Wrap (_dae ,_abff ,"\u0021\u0066\u006f\u0075\u006e\u0064");};if _dae =_efbe .ComponentPageNumbers .Add (_gdc );_dae !=nil {return _e .Wrap (_dae ,_abff ,"\u0021\u0066\u006f\u0075\u006e\u0064");
|
|
};_dge :=&_bd .Bitmaps {};_ggb =_ccg .Values [_fefb ];_dge .AddBitmap (_ggb );_gfae ,_bfa :=_ggb .Width ,_ggb .Height ;_efbe .TemplatesSize .Add (uint64 (_gfae )*uint64 (_bfa ),_ddfa );_dce ,_bbg :=_acd .Get (_fefb );if _bbg !=nil {return _e .Wrap (_bbg ,_abff ,"\u0021\u0066\u006f\u0075\u006e\u0064");
|
|
};_dge .AddBox (_dce );_efbe .ClassInstances .AddBitmaps (_dge );_efbe .CentroidPointsTemplates .AddPoint (_gae ,_cgc );_efbe .UndilatedTemplates .AddBitmap (_ge );_efbe .DilatedTemplates .AddBitmap (_gafc );_efbe .FgTemplates .AddInt (_gce );};};_efbe .NumberOfClasses =len (_efbe .UndilatedTemplates .Values );
|
|
return nil ;};const (MaxDiffWidth =2;MaxDiffHeight =2;);func (_ec *Classer )getULCorners (_db *_bd .Bitmap ,_eg *_bd .Boxes )error {const _gbaa ="\u0067\u0065\u0074U\u004c\u0043\u006f\u0072\u006e\u0065\u0072\u0073";if _db ==nil {return _e .Error (_gbaa ,"\u006e\u0069l\u0020\u0069\u006da\u0067\u0065\u0020\u0062\u0069\u0074\u006d\u0061\u0070");
|
|
};if _eg ==nil {return _e .Error (_gbaa ,"\u006e\u0069\u006c\u0020\u0062\u006f\u0075\u006e\u0064\u0073");};if _ec .PtaUL ==nil {_ec .PtaUL =&_bd .Points {};};_ega :=len (*_eg );var (_dcb ,_fd ,_fe ,_bea int ;_de ,_eb ,_ecd ,_bbb float32 ;_efb error ;_ace *_d .Rectangle ;
|
|
_deg *_bd .Bitmap ;_gad _d .Point ;);for _gd :=0;_gd < _ega ;_gd ++{_dcb =_ec .BaseIndex +_gd ;if _de ,_eb ,_efb =_ec .CentroidPoints .GetGeometry (_dcb );_efb !=nil {return _e .Wrap (_efb ,_gbaa ,"\u0043\u0065\u006e\u0074\u0072\u006f\u0069\u0064\u0050o\u0069\u006e\u0074\u0073");
|
|
};if _fd ,_efb =_ec .ClassIDs .Get (_dcb );_efb !=nil {return _e .Wrap (_efb ,_gbaa ,"\u0043\u006c\u0061s\u0073\u0049\u0044\u0073\u002e\u0047\u0065\u0074");};if _ecd ,_bbb ,_efb =_ec .CentroidPointsTemplates .GetGeometry (_fd );_efb !=nil {return _e .Wrap (_efb ,_gbaa ,"\u0043\u0065\u006etr\u006f\u0069\u0064\u0050\u006f\u0069\u006e\u0074\u0073\u0054\u0065\u006d\u0070\u006c\u0061\u0074\u0065\u0073");
|
|
};_bee :=_ecd -_de ;_dcbf :=_bbb -_eb ;if _bee >=0{_fe =int (_bee +0.5);}else {_fe =int (_bee -0.5);};if _dcbf >=0{_bea =int (_dcbf +0.5);}else {_bea =int (_dcbf -0.5);};if _ace ,_efb =_eg .Get (_gd );_efb !=nil {return _e .Wrap (_efb ,_gbaa ,"");};_gbg ,_beaa :=_ace .Min .X ,_ace .Min .Y ;
|
|
_deg ,_efb =_ec .UndilatedTemplates .GetBitmap (_fd );if _efb !=nil {return _e .Wrap (_efb ,_gbaa ,"\u0055\u006e\u0064\u0069\u006c\u0061\u0074\u0065\u0064\u0054e\u006d\u0070\u006c\u0061\u0074\u0065\u0073.\u0047\u0065\u0074\u0028\u0069\u0043\u006c\u0061\u0073\u0073\u0029");
|
|
};_gad ,_efb =_fcf (_db ,_gbg ,_beaa ,_fe ,_bea ,_deg );if _efb !=nil {return _e .Wrap (_efb ,_gbaa ,"");};_ec .PtaUL .AddPoint (float32 (_gbg -_fe +_gad .X ),float32 (_beaa -_bea +_gad .Y ));};return nil ;};func (_bcg *similarTemplatesFinder )Next ()int {var (_edg ,_ebf ,_ade ,_aff int ;
|
|
_gbc bool ;_cfd *_bd .Bitmap ;_gde error ;);for {if _bcg .Index >=25{return -1;};_ebf =_bcg .Width +TwoByTwoWalk [2*_bcg .Index ];_edg =_bcg .Height +TwoByTwoWalk [2*_bcg .Index +1];if _edg < 1||_ebf < 1{_bcg .Index ++;continue ;};if len (_bcg .CurrentNumbers )==0{_bcg .CurrentNumbers ,_gbc =_bcg .Classer .TemplatesSize .GetSlice (uint64 (_ebf )*uint64 (_edg ));
|
|
if !_gbc {_bcg .Index ++;continue ;};_bcg .N =0;};_ade =len (_bcg .CurrentNumbers );for ;_bcg .N < _ade ;_bcg .N ++{_aff =_bcg .CurrentNumbers [_bcg .N ];_cfd ,_gde =_bcg .Classer .DilatedTemplates .GetBitmap (_aff );if _gde !=nil {_f .Log .Debug ("\u0046\u0069\u006e\u0064\u004e\u0065\u0078\u0074\u0054\u0065\u006d\u0070\u006c\u0061\u0074\u0065\u003a\u0020\u0074\u0065\u006d\u0070\u006c\u0061t\u0065\u0020\u006e\u006f\u0074 \u0066\u006fu\u006e\u0064\u003a\u0020");
|
|
return 0;};if _cfd .Width -2*JbAddedPixels ==_ebf &&_cfd .Height -2*JbAddedPixels ==_edg {return _aff ;};};_bcg .Index ++;_bcg .CurrentNumbers =nil ;};};type similarTemplatesFinder struct{Classer *Classer ;Width int ;Height int ;Index int ;CurrentNumbers []int ;
|
|
N int ;}; |