2021-05-31 17:17:31 +00:00

109 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 (_fa "github.com/unidoc/unipdf/v3/common";_bf "github.com/unidoc/unipdf/v3/internal/jbig2/basic";_fb "github.com/unidoc/unipdf/v3/internal/jbig2/bitmap";_c "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_d "image";_b "math";
);type Settings struct{MaxCompWidth int ;MaxCompHeight int ;SizeHaus int ;RankHaus float64 ;Thresh float64 ;WeightFactor float64 ;KeepClassInstances bool ;Components _fb .Component ;Method Method ;};func (_bfb *Classer )ComputeLLCorners ()(_eg error ){const _ba ="\u0043l\u0061\u0073\u0073\u0065\u0072\u002e\u0043\u006f\u006d\u0070\u0075t\u0065\u004c\u004c\u0043\u006f\u0072\u006e\u0065\u0072\u0073";
if _bfb .PtaUL ==nil {return _c .Error (_ba ,"\u0055\u004c\u0020\u0043or\u006e\u0065\u0072\u0073\u0020\u006e\u006f\u0074\u0020\u0064\u0065\u0066\u0069\u006ee\u0064");};_fg :=len (*_bfb .PtaUL );_bfb .PtaLL =&_fb .Points {};var (_cg ,_gf float32 ;_fe ,_db int ;
_ce *_fb .Bitmap ;);for _ff :=0;_ff < _fg ;_ff ++{_cg ,_gf ,_eg =_bfb .PtaUL .GetGeometry (_ff );if _eg !=nil {_fa .Log .Debug ("\u0047e\u0074\u0074\u0069\u006e\u0067\u0020\u0050\u0074\u0061\u0055\u004c \u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0076",_eg );
return _c .Wrap (_eg ,_ba ,"\u0050\u0074\u0061\u0055\u004c\u0020\u0047\u0065\u006fm\u0065\u0074\u0072\u0079");};_fe ,_eg =_bfb .ClassIDs .Get (_ff );if _eg !=nil {_fa .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",_eg );
return _c .Wrap (_eg ,_ba ,"\u0043l\u0061\u0073\u0073\u0049\u0044");};_ce ,_eg =_bfb .UndilatedTemplates .GetBitmap (_fe );if _eg !=nil {_fa .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",_eg );
return _c .Wrap (_eg ,_ba ,"\u0055\u006e\u0064\u0069la\u0074\u0065\u0064\u0020\u0054\u0065\u006d\u0070\u006c\u0061\u0074\u0065\u0073");};_db =_ce .Height ;_bfb .PtaLL .AddPoint (_cg ,_gf +float32 (_db ));};return nil ;};const (RankHaus Method =iota ;Correlation ;
);type Classer struct{BaseIndex int ;Settings Settings ;ComponentsNumber *_bf .IntSlice ;TemplateAreas *_bf .IntSlice ;Widths map[int ]int ;Heights map[int ]int ;NumberOfClasses int ;ClassInstances *_fb .BitmapsArray ;UndilatedTemplates *_fb .Bitmaps ;
DilatedTemplates *_fb .Bitmaps ;TemplatesSize _bf .IntsMap ;FgTemplates *_bf .NumSlice ;CentroidPoints *_fb .Points ;CentroidPointsTemplates *_fb .Points ;ClassIDs *_bf .IntSlice ;ComponentPageNumbers *_bf .IntSlice ;PtaUL *_fb .Points ;PtaLL *_fb .Points ;
};func DefaultSettings ()Settings {_abb :=&Settings {};_abb .SetDefault ();return *_abb };func (_ebf Settings )Validate ()error {const _cacc ="\u0053\u0065\u0074\u0074\u0069\u006e\u0067\u0073\u002e\u0056\u0061\u006ci\u0064\u0061\u0074\u0065";if _ebf .Thresh < 0.4||_ebf .Thresh > 0.98{return _c .Error (_cacc ,"\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 _ebf .WeightFactor < 0.0||_ebf .WeightFactor > 1.0{return _c .Error (_cacc ,"\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 _ebf .RankHaus < 0.5||_ebf .RankHaus > 1.0{return _c .Error (_cacc ,"\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 _ebf .SizeHaus < 1||_ebf .SizeHaus > 10{return _c .Error (_cacc ,"\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 _ebf .Components {case _fb .ComponentConn ,_fb .ComponentCharacters ,_fb .ComponentWords :default:return _c .Error (_cacc ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0063\u006c\u0061\u0073s\u0065r\u0020c\u006f\u006d\u0070\u006f\u006e\u0065\u006et");
};return nil ;};func (_gcf *Classer )classifyRankHouseNonOne (_cgeb *_fb .Boxes ,_bcdd ,_gae ,_eebb *_fb .Bitmaps ,_fge *_fb .Points ,_cee *_bf .NumSlice ,_cbb int )(_bed error ){const _efb ="\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 (_bcc ,_cbf ,_ccgd ,_fbad float32 ;_agda ,_geff ,_agc int ;_bebe ,_ccf ,_gcgfd ,_fed ,_ege *_fb .Bitmap ;_adda ,_acdb bool ;);_cac :=_fb .MakePixelSumTab8 ();for _ebacd :=0;_ebacd < len (_bcdd .Values );_ebacd ++{if _ccf ,_bed =_gae .GetBitmap (_ebacd );
_bed !=nil {return _c .Wrap (_bed ,_efb ,"b\u006d\u0073\u0031\u002e\u0047\u0065\u0074\u0028\u0069\u0029");};if _agda ,_bed =_cee .GetInt (_ebacd );_bed !=nil {_fa .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",_ebacd ,_bed );
};if _gcgfd ,_bed =_eebb .GetBitmap (_ebacd );_bed !=nil {return _c .Wrap (_bed ,_efb ,"b\u006d\u0073\u0032\u002e\u0047\u0065\u0074\u0028\u0069\u0029");};if _bcc ,_cbf ,_bed =_fge .GetGeometry (_ebacd );_bed !=nil {return _c .Wrapf (_bed ,_efb ,"\u0070t\u0061[\u0069\u005d\u002e\u0047\u0065\u006f\u006d\u0065\u0074\u0072\u0079");
};_dbdg :=len (_gcf .UndilatedTemplates .Values );_adda =false ;_aef :=_facg (_gcf ,_ccf );for _agc =_aef .Next ();_agc > -1;{if _fed ,_bed =_gcf .UndilatedTemplates .GetBitmap (_agc );_bed !=nil {return _c .Wrap (_bed ,_efb ,"\u0070\u0069\u0078\u0061\u0074\u002e\u005b\u0069\u0043l\u0061\u0073\u0073\u005d");
};if _geff ,_bed =_gcf .FgTemplates .GetInt (_agc );_bed !=nil {_fa .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",_agc ,_bed );
};if _ege ,_bed =_gcf .DilatedTemplates .GetBitmap (_agc );_bed !=nil {return _c .Wrap (_bed ,_efb ,"\u0070\u0069\u0078\u0061\u0074\u0064\u005b\u0069\u0043l\u0061\u0073\u0073\u005d");};if _ccgd ,_fbad ,_bed =_gcf .CentroidPointsTemplates .GetGeometry (_agc );
_bed !=nil {return _c .Wrap (_bed ,_efb ,"\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");};_acdb ,_bed =_fb .RankHausTest (_ccf ,_gcgfd ,_fed ,_ege ,_bcc -_ccgd ,_cbf -_fbad ,MaxDiffWidth ,MaxDiffHeight ,_agda ,_geff ,float32 (_gcf .Settings .RankHaus ),_cac );
if _bed !=nil {return _c .Wrap (_bed ,_efb ,"");};if _acdb {_adda =true ;if _bed =_gcf .ClassIDs .Add (_agc );_bed !=nil {return _c .Wrap (_bed ,_efb ,"");};if _bed =_gcf .ComponentPageNumbers .Add (_cbb );_bed !=nil {return _c .Wrap (_bed ,_efb ,"");};
if _gcf .Settings .KeepClassInstances {_bcb ,_gdbf :=_gcf .ClassInstances .GetBitmaps (_agc );if _gdbf !=nil {return _c .Wrap (_gdbf ,_efb ,"\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 _bebe ,_gdbf =_bcdd .GetBitmap (_ebacd );_gdbf !=nil {return _c .Wrap (_gdbf ,_efb ,"\u0070i\u0078\u0061\u005b\u0069\u005d");};_bcb .Values =append (_bcb .Values ,_bebe );_cba ,_gdbf :=_cgeb .Get (_ebacd );if _gdbf !=nil {return _c .Wrap (_gdbf ,_efb ,"b\u006f\u0078\u0061\u002e\u0047\u0065\u0074\u0028\u0069\u0029");
};_bcb .Boxes =append (_bcb .Boxes ,_cba );};break ;};};if !_adda {if _bed =_gcf .ClassIDs .Add (_dbdg );_bed !=nil {return _c .Wrap (_bed ,_efb ,"\u0021\u0066\u006f\u0075\u006e\u0064");};if _bed =_gcf .ComponentPageNumbers .Add (_cbb );_bed !=nil {return _c .Wrap (_bed ,_efb ,"\u0021\u0066\u006f\u0075\u006e\u0064");
};_ffba :=&_fb .Bitmaps {};_bebe =_bcdd .Values [_ebacd ];_ffba .AddBitmap (_bebe );_bfbf ,_degg :=_bebe .Width ,_bebe .Height ;_gcf .TemplatesSize .Add (uint64 (_bfbf )*uint64 (_degg ),_dbdg );_cbbc ,_gad :=_cgeb .Get (_ebacd );if _gad !=nil {return _c .Wrap (_gad ,_efb ,"\u0021\u0066\u006f\u0075\u006e\u0064");
};_ffba .AddBox (_cbbc );_gcf .ClassInstances .AddBitmaps (_ffba );_gcf .CentroidPointsTemplates .AddPoint (_bcc ,_cbf );_gcf .UndilatedTemplates .AddBitmap (_ccf );_gcf .DilatedTemplates .AddBitmap (_gcgfd );_gcf .FgTemplates .AddInt (_agda );};};_gcf .NumberOfClasses =len (_gcf .UndilatedTemplates .Values );
return nil ;};var _gbb bool ;func (_bgce *Classer )classifyRankHaus (_gacd *_fb .Boxes ,_ddcde *_fb .Bitmaps ,_fba int )error {const _cbg ="\u0063\u006ca\u0073\u0073\u0069f\u0079\u0052\u0061\u006e\u006b\u0048\u0061\u0075\u0073";if _gacd ==nil {return _c .Error (_cbg ,"\u0062\u006fx\u0061\u0020\u006eo\u0074\u0020\u0064\u0065\u0066\u0069\u006e\u0065\u0064");
};if _ddcde ==nil {return _c .Error (_cbg ,"\u0070\u0069x\u0061\u0020\u006eo\u0074\u0020\u0064\u0065\u0066\u0069\u006e\u0065\u0064");};_cegc :=len (_ddcde .Values );if _cegc ==0{return _c .Error (_cbg ,"e\u006dp\u0074\u0079\u0020\u006e\u0065\u0077\u0020\u0063o\u006d\u0070\u006f\u006een\u0074\u0073");
};_deb :=_ddcde .CountPixels ();_fdd :=_bgce .Settings .SizeHaus ;_gcg :=_fb .SelCreateBrick (_fdd ,_fdd ,_fdd /2,_fdd /2,_fb .SelHit );_fgg :=&_fb .Bitmaps {Values :make ([]*_fb .Bitmap ,_cegc )};_bdc :=&_fb .Bitmaps {Values :make ([]*_fb .Bitmap ,_cegc )};
var (_aegc ,_degd ,_add *_fb .Bitmap ;_fc error ;);for _gaf :=0;_gaf < _cegc ;_gaf ++{_aegc ,_fc =_ddcde .GetBitmap (_gaf );if _fc !=nil {return _c .Wrap (_fc ,_cbg ,"");};_degd ,_fc =_aegc .AddBorderGeneral (JbAddedPixels ,JbAddedPixels ,JbAddedPixels ,JbAddedPixels ,0);
if _fc !=nil {return _c .Wrap (_fc ,_cbg ,"");};_add ,_fc =_fb .Dilate (nil ,_degd ,_gcg );if _fc !=nil {return _c .Wrap (_fc ,_cbg ,"");};_fgg .Values [_cegc ]=_degd ;_bdc .Values [_cegc ]=_add ;};_fbd ,_fc :=_fb .Centroids (_fgg .Values );if _fc !=nil {return _c .Wrap (_fc ,_cbg ,"");
};if _fc =_fbd .Add (_bgce .CentroidPoints );_fc !=nil {_fa .Log .Trace ("\u004e\u006f\u0020\u0063en\u0074\u0072\u006f\u0069\u0064\u0073\u0020\u0074\u006f\u0020\u0061\u0064\u0064");};if _bgce .Settings .RankHaus ==1.0{_fc =_bgce .classifyRankHouseOne (_gacd ,_ddcde ,_fgg ,_bdc ,_fbd ,_fba );
}else {_fc =_bgce .classifyRankHouseNonOne (_gacd ,_ddcde ,_fgg ,_bdc ,_fbd ,_deb ,_fba );};if _fc !=nil {return _c .Wrap (_fc ,_cbg ,"");};return nil ;};func (_cceb *Settings )SetDefault (){if _cceb .MaxCompWidth ==0{switch _cceb .Components {case _fb .ComponentConn :_cceb .MaxCompWidth =MaxConnCompWidth ;
case _fb .ComponentCharacters :_cceb .MaxCompWidth =MaxCharCompWidth ;case _fb .ComponentWords :_cceb .MaxCompWidth =MaxWordCompWidth ;};};if _cceb .MaxCompHeight ==0{_cceb .MaxCompHeight =MaxCompHeight ;};if _cceb .Thresh ==0.0{_cceb .Thresh =0.9;};if _cceb .WeightFactor ==0.0{_cceb .WeightFactor =0.75;
};if _cceb .RankHaus ==0.0{_cceb .RankHaus =0.97;};if _cceb .SizeHaus ==0{_cceb .SizeHaus =2;};};func (_fdc *Classer )classifyRankHouseOne (_dc *_fb .Boxes ,_bec ,_cbgd ,_dfe *_fb .Bitmaps ,_ebac *_fb .Points ,_fee int )(_aaa error ){const _dddf ="\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 (_dfea ,_bda ,_fbc ,_egd float32 ;_ece int ;_ecb ,_gcgf ,_egdd ,_eac ,_bga *_fb .Bitmap ;_gbe ,_faef bool ;);for _ecf :=0;_ecf < len (_bec .Values );_ecf ++{_gcgf =_cbgd .Values [_ecf ];_egdd =_dfe .Values [_ecf ];_dfea ,_bda ,_aaa =_ebac .GetGeometry (_ecf );
if _aaa !=nil {return _c .Wrapf (_aaa ,_dddf ,"\u0066\u0069\u0072\u0073\u0074\u0020\u0067\u0065\u006fm\u0065\u0074\u0072\u0079");};_bebf :=len (_fdc .UndilatedTemplates .Values );_gbe =false ;_fgb :=_facg (_fdc ,_gcgf );for _ece =_fgb .Next ();_ece > -1;
{_eac ,_aaa =_fdc .UndilatedTemplates .GetBitmap (_ece );if _aaa !=nil {return _c .Wrap (_aaa ,_dddf ,"\u0062\u006d\u0033");};_bga ,_aaa =_fdc .DilatedTemplates .GetBitmap (_ece );if _aaa !=nil {return _c .Wrap (_aaa ,_dddf ,"\u0062\u006d\u0034");};_fbc ,_egd ,_aaa =_fdc .CentroidPointsTemplates .GetGeometry (_ece );
if _aaa !=nil {return _c .Wrap (_aaa ,_dddf ,"\u0043\u0065\u006e\u0074\u0072\u006f\u0069\u0064\u0054\u0065\u006d\u0070l\u0061\u0074\u0065\u0073");};_faef ,_aaa =_fb .HausTest (_gcgf ,_egdd ,_eac ,_bga ,_dfea -_fbc ,_bda -_egd ,MaxDiffWidth ,MaxDiffHeight );
if _aaa !=nil {return _c .Wrap (_aaa ,_dddf ,"");};if _faef {_gbe =true ;if _aaa =_fdc .ClassIDs .Add (_ece );_aaa !=nil {return _c .Wrap (_aaa ,_dddf ,"");};if _aaa =_fdc .ComponentPageNumbers .Add (_fee );_aaa !=nil {return _c .Wrap (_aaa ,_dddf ,"");
};if _fdc .Settings .KeepClassInstances {_ggf ,_eeb :=_fdc .ClassInstances .GetBitmaps (_ece );if _eeb !=nil {return _c .Wrap (_eeb ,_dddf ,"\u004be\u0065\u0070\u0050\u0069\u0078\u0061a");};_ecb ,_eeb =_bec .GetBitmap (_ecf );if _eeb !=nil {return _c .Wrap (_eeb ,_dddf ,"\u004be\u0065\u0070\u0050\u0069\u0078\u0061a");
};_ggf .AddBitmap (_ecb );_gfgd ,_eeb :=_dc .Get (_ecf );if _eeb !=nil {return _c .Wrap (_eeb ,_dddf ,"\u004be\u0065\u0070\u0050\u0069\u0078\u0061a");};_ggf .AddBox (_gfgd );};break ;};};if !_gbe {if _aaa =_fdc .ClassIDs .Add (_bebf );_aaa !=nil {return _c .Wrap (_aaa ,_dddf ,"");
};if _aaa =_fdc .ComponentPageNumbers .Add (_fee );_aaa !=nil {return _c .Wrap (_aaa ,_dddf ,"");};_ebd :=&_fb .Bitmaps {};_ecb ,_aaa =_bec .GetBitmap (_ecf );if _aaa !=nil {return _c .Wrap (_aaa ,_dddf ,"\u0021\u0066\u006f\u0075\u006e\u0064");};_ebd .Values =append (_ebd .Values ,_ecb );
_dbd ,_aae :=_ecb .Width ,_ecb .Height ;_fdc .TemplatesSize .Add (uint64 (_aae )*uint64 (_dbd ),_bebf );_bbc ,_ecc :=_dc .Get (_ecf );if _ecc !=nil {return _c .Wrap (_ecc ,_dddf ,"\u0021\u0066\u006f\u0075\u006e\u0064");};_ebd .AddBox (_bbc );_fdc .ClassInstances .AddBitmaps (_ebd );
_fdc .CentroidPointsTemplates .AddPoint (_dfea ,_bda );_fdc .UndilatedTemplates .AddBitmap (_gcgf );_fdc .DilatedTemplates .AddBitmap (_egdd );};};return nil ;};type similarTemplatesFinder struct{Classer *Classer ;Width int ;Height int ;Index int ;CurrentNumbers []int ;
N int ;};func (_ffb *Classer )getULCorners (_ddc *_fb .Bitmap ,_eb *_fb .Boxes )error {const _adc ="\u0067\u0065\u0074U\u004c\u0043\u006f\u0072\u006e\u0065\u0072\u0073";if _ddc ==nil {return _c .Error (_adc ,"\u006e\u0069l\u0020\u0069\u006da\u0067\u0065\u0020\u0062\u0069\u0074\u006d\u0061\u0070");
};if _eb ==nil {return _c .Error (_adc ,"\u006e\u0069\u006c\u0020\u0062\u006f\u0075\u006e\u0064\u0073");};if _ffb .PtaUL ==nil {_ffb .PtaUL =&_fb .Points {};};_gfb :=len (*_eb );var (_cc ,_ag ,_df ,_ef int ;_gef ,_bgc ,_fd ,_cd float32 ;_agd error ;_dff *_d .Rectangle ;
_bd *_fb .Bitmap ;_cgb _d .Point ;);for _ddd :=0;_ddd < _gfb ;_ddd ++{_cc =_ffb .BaseIndex +_ddd ;if _gef ,_bgc ,_agd =_ffb .CentroidPoints .GetGeometry (_cc );_agd !=nil {return _c .Wrap (_agd ,_adc ,"\u0043\u0065\u006e\u0074\u0072\u006f\u0069\u0064\u0050o\u0069\u006e\u0074\u0073");
};if _ag ,_agd =_ffb .ClassIDs .Get (_cc );_agd !=nil {return _c .Wrap (_agd ,_adc ,"\u0043\u006c\u0061s\u0073\u0049\u0044\u0073\u002e\u0047\u0065\u0074");};if _fd ,_cd ,_agd =_ffb .CentroidPointsTemplates .GetGeometry (_ag );_agd !=nil {return _c .Wrap (_agd ,_adc ,"\u0043\u0065\u006etr\u006f\u0069\u0064\u0050\u006f\u0069\u006e\u0074\u0073\u0054\u0065\u006d\u0070\u006c\u0061\u0074\u0065\u0073");
};_aab :=_fd -_gef ;_agde :=_cd -_bgc ;if _aab >=0{_df =int (_aab +0.5);}else {_df =int (_aab -0.5);};if _agde >=0{_ef =int (_agde +0.5);}else {_ef =int (_agde -0.5);};if _dff ,_agd =_eb .Get (_ddd );_agd !=nil {return _c .Wrap (_agd ,_adc ,"");};_bgcb ,_gec :=_dff .Min .X ,_dff .Min .Y ;
_bd ,_agd =_ffb .UndilatedTemplates .GetBitmap (_ag );if _agd !=nil {return _c .Wrap (_agd ,_adc ,"\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");
};_cgb ,_agd =_da (_ddc ,_bgcb ,_gec ,_df ,_ef ,_bd );if _agd !=nil {return _c .Wrap (_agd ,_adc ,"");};_ffb .PtaUL .AddPoint (float32 (_bgcb -_df +_cgb .X ),float32 (_gec -_ef +_cgb .Y ));};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};
const (MaxDiffWidth =2;MaxDiffHeight =2;);func _facg (_eff *Classer ,_bggc *_fb .Bitmap )*similarTemplatesFinder {return &similarTemplatesFinder {Width :_bggc .Width ,Height :_bggc .Height ,Classer :_eff };};func (_ebdd *similarTemplatesFinder )Next ()int {var (_bdb ,_dbf ,_aegd ,_eebc int ;
_cfge bool ;_dbe *_fb .Bitmap ;_effa error ;);for {if _ebdd .Index >=25{return -1;};_dbf =_ebdd .Width +TwoByTwoWalk [2*_ebdd .Index ];_bdb =_ebdd .Height +TwoByTwoWalk [2*_ebdd .Index +1];if _bdb < 1||_dbf < 1{_ebdd .Index ++;continue ;};if len (_ebdd .CurrentNumbers )==0{_ebdd .CurrentNumbers ,_cfge =_ebdd .Classer .TemplatesSize .GetSlice (uint64 (_dbf )*uint64 (_bdb ));
if !_cfge {_ebdd .Index ++;continue ;};_ebdd .N =0;};_aegd =len (_ebdd .CurrentNumbers );for ;_ebdd .N < _aegd ;_ebdd .N ++{_eebc =_ebdd .CurrentNumbers [_ebdd .N ];_dbe ,_effa =_ebdd .Classer .DilatedTemplates .GetBitmap (_eebc );if _effa !=nil {_fa .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 _dbe .Width -2*JbAddedPixels ==_dbf &&_dbe .Height -2*JbAddedPixels ==_bdb {return _eebc ;};};_ebdd .Index ++;_ebdd .CurrentNumbers =nil ;};};func (_de *Classer )addPageComponents (_cfg *_fb .Bitmap ,_be *_fb .Boxes ,_aa *_fb .Bitmaps ,_gfg int ,_gb Method )error {const _bfe ="\u0043l\u0061\u0073\u0073\u0065r\u002e\u0041\u0064\u0064\u0050a\u0067e\u0043o\u006d\u0070\u006f\u006e\u0065\u006e\u0074s";
if _cfg ==nil {return _c .Error (_bfe ,"\u006e\u0069\u006c\u0020\u0069\u006e\u0070\u0075\u0074 \u0070\u0061\u0067\u0065");};if _be ==nil ||_aa ==nil ||len (*_be )==0{_fa .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",_cfg );
return nil ;};var _ad error ;switch _gb {case RankHaus :_ad =_de .classifyRankHaus (_be ,_aa ,_gfg );case Correlation :_ad =_de .classifyCorrelation (_be ,_aa ,_gfg );default:_fa .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",_gb );
return _c .Error (_bfe ,"\u0075\u006e\u006bno\u0077\u006e\u0020\u0063\u006c\u0061\u0073\u0073\u0069\u0066\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0064");};if _ad !=nil {return _c .Wrap (_ad ,_bfe ,"");};if _ad =_de .getULCorners (_cfg ,_be );_ad !=nil {return _c .Wrap (_ad ,_bfe ,"");
};_dd :=len (*_be );_de .BaseIndex +=_dd ;if _ad =_de .ComponentsNumber .Add (_dd );_ad !=nil {return _c .Wrap (_ad ,_bfe ,"");};return nil ;};func (_fac *Classer )verifyMethod (_fae Method )error {if _fae !=RankHaus &&_fae !=Correlation {return _c .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 ;};type Method int ;func (_a *Classer )AddPage (inputPage *_fb .Bitmap ,pageNumber int ,method Method )(_ac error ){const _ge ="\u0043l\u0061s\u0073\u0065\u0072\u002e\u0041\u0064\u0064\u0050\u0061\u0067\u0065";_a .Widths [pageNumber ]=inputPage .Width ;
_a .Heights [pageNumber ]=inputPage .Height ;if _ac =_a .verifyMethod (method );_ac !=nil {return _c .Wrap (_ac ,_ge ,"");};_cf ,_bfc ,_ac :=inputPage .GetComponents (_a .Settings .Components ,_a .Settings .MaxCompWidth ,_a .Settings .MaxCompHeight );if _ac !=nil {return _c .Wrap (_ac ,_ge ,"");
};_fa .Log .Debug ("\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074s\u003a\u0020\u0025\u0076",_cf );if _ac =_a .addPageComponents (inputPage ,_bfc ,_cf ,pageNumber ,method );_ac !=nil {return _c .Wrap (_ac ,_ge ,"");};return nil ;};const JbAddedPixels =6;
func (_ebb *Classer )classifyCorrelation (_fda *_fb .Boxes ,_ccge *_fb .Bitmaps ,_aabb int )error {const _fbb ="\u0063\u006c\u0061\u0073si\u0066\u0079\u0043\u006f\u0072\u0072\u0065\u006c\u0061\u0074\u0069\u006f\u006e";if _fda ==nil {return _c .Error (_fbb ,"\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 _ccge ==nil {return _c .Error (_fbb ,"\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");};_beg :=len (_ccge .Values );if _beg ==0{_fa .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 (_ga ,_eba *_fb .Bitmap ;_bfg error ;);_aad :=&_fb .Bitmaps {Values :make ([]*_fb .Bitmap ,_beg )};for _cgf ,_egf :=range _ccge .Values {_eba ,_bfg =_egf .AddBorderGeneral (JbAddedPixels ,JbAddedPixels ,JbAddedPixels ,JbAddedPixels ,0);
if _bfg !=nil {return _c .Wrap (_bfg ,_fbb ,"");};_aad .Values [_cgf ]=_eba ;};_gac :=_ebb .FgTemplates ;_aee :=_fb .MakePixelSumTab8 ();_ceg :=_fb .MakePixelCentroidTab8 ();_cge :=make ([]int ,_beg );_bfd :=make ([][]int ,_beg );_cce :=_fb .Points (make ([]_fb .Point ,_beg ));
_beb :=&_cce ;var (_dfb ,_deec int ;_cef ,_gee ,_bgg int ;_ebg ,_aeg int ;_gg byte ;);for _dac ,_dfg :=range _aad .Values {_bfd [_dac ]=make ([]int ,_dfg .Height );_dfb =0;_deec =0;_gee =(_dfg .Height -1)*_dfg .RowStride ;_cef =0;for _aeg =_dfg .Height -1;
_aeg >=0;_aeg ,_gee =_aeg -1,_gee -_dfg .RowStride {_bfd [_dac ][_aeg ]=_cef ;_bgg =0;for _ebg =0;_ebg < _dfg .RowStride ;_ebg ++{_gg =_dfg .Data [_gee +_ebg ];_bgg +=_aee [_gg ];_dfb +=_ceg [_gg ]+_ebg *8*_aee [_gg ];};_cef +=_bgg ;_deec +=_bgg *_aeg ;
};_cge [_dac ]=_cef ;if _cef > 0{(*_beb )[_dac ]=_fb .Point {X :float32 (_dfb )/float32 (_cef ),Y :float32 (_deec )/float32 (_cef )};}else {(*_beb )[_dac ]=_fb .Point {X :float32 (_dfg .Width )/float32 (2),Y :float32 (_dfg .Height )/float32 (2)};};};if _bfg =_ebb .CentroidPoints .Add (_beb );
_bfg !=nil {return _c .Wrap (_bfg ,_fbb ,"\u0063\u0065\u006et\u0072\u006f\u0069\u0064\u0020\u0061\u0064\u0064");};var (_gdb ,_adf ,_gff int ;_bc float64 ;_ab ,_cfa ,_bba ,_dae float32 ;_acg ,_bcd _fb .Point ;_gc bool ;_agf *similarTemplatesFinder ;_ddcd int ;
_dga *_fb .Bitmap ;_ca *_d .Rectangle ;_gbg *_fb .Bitmaps ;);for _ddcd ,_eba =range _aad .Values {_adf =_cge [_ddcd ];if _ab ,_cfa ,_bfg =_beb .GetGeometry (_ddcd );_bfg !=nil {return _c .Wrap (_bfg ,_fbb ,"\u0070t\u0061\u0020\u002d\u0020\u0069");};_gc =false ;
_acd :=len (_ebb .UndilatedTemplates .Values );_agf =_facg (_ebb ,_eba );for _ea :=_agf .Next ();_ea > -1;{if _dga ,_bfg =_ebb .UndilatedTemplates .GetBitmap (_ea );_bfg !=nil {return _c .Wrap (_bfg ,_fbb ,"\u0075\u006e\u0069dl\u0061\u0074\u0065\u0064\u005b\u0069\u0063\u006c\u0061\u0073\u0073\u005d\u0020\u003d\u0020\u0062\u006d\u0032");
};if _gff ,_bfg =_gac .GetInt (_ea );_bfg !=nil {_fa .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",_bfg );};if _bba ,_dae ,_bfg =_ebb .CentroidPointsTemplates .GetGeometry (_ea );
_bfg !=nil {return _c .Wrap (_bfg ,_fbb ,"\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 _ebb .Settings .WeightFactor > 0.0{if _gdb ,_bfg =_ebb .TemplateAreas .Get (_ea );_bfg !=nil {_fa .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",_bfg );
};_bc =_ebb .Settings .Thresh +(1.0-_ebb .Settings .Thresh )*_ebb .Settings .WeightFactor *float64 (_gff )/float64 (_gdb );}else {_bc =_ebb .Settings .Thresh ;};_daed ,_dde :=_fb .CorrelationScoreThresholded (_eba ,_dga ,_adf ,_gff ,_acg .X -_bcd .X ,_acg .Y -_bcd .Y ,MaxDiffWidth ,MaxDiffHeight ,_aee ,_bfd [_ddcd ],float32 (_bc ));
if _dde !=nil {return _c .Wrap (_dde ,_fbb ,"");};if _gbb {var (_ggc ,_edf float64 ;_cgef ,_adff int ;);_ggc ,_dde =_fb .CorrelationScore (_eba ,_dga ,_adf ,_gff ,_ab -_bba ,_cfa -_dae ,MaxDiffWidth ,MaxDiffHeight ,_aee );if _dde !=nil {return _c .Wrap (_dde ,_fbb ,"d\u0065\u0062\u0075\u0067Co\u0072r\u0065\u006c\u0061\u0074\u0069o\u006e\u0053\u0063\u006f\u0072\u0065");
};_edf ,_dde =_fb .CorrelationScoreSimple (_eba ,_dga ,_adf ,_gff ,_ab -_bba ,_cfa -_dae ,MaxDiffWidth ,MaxDiffHeight ,_aee );if _dde !=nil {return _c .Wrap (_dde ,_fbb ,"d\u0065\u0062\u0075\u0067Co\u0072r\u0065\u006c\u0061\u0074\u0069o\u006e\u0053\u0063\u006f\u0072\u0065");
};_cgef =int (_b .Sqrt (_ggc *float64 (_adf )*float64 (_gff )));_adff =int (_b .Sqrt (_edf *float64 (_adf )*float64 (_gff )));if (_ggc >=_bc )!=(_edf >=_bc ){return _c .Errorf (_fbb ,"\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",_cgef ,_ggc ,_ggc >=_bc ,_adff ,_edf ,_edf >=_bc ,_ggc -_edf );
};if _ggc >=_bc !=_daed {return _c .Errorf (_fbb ,"\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",_ggc ,_ggc *float64 (_adf )*float64 (_gff ),_cgef ,_bc ,float32 (_bc )*float32 (_adf )*float32 (_gff ),_daed );
};};if _daed {_gc =true ;if _dde =_ebb .ClassIDs .Add (_ea );_dde !=nil {return _c .Wrap (_dde ,_fbb ,"\u006f\u0076\u0065\u0072\u0054\u0068\u0072\u0065\u0073\u0068\u006f\u006c\u0064");};if _dde =_ebb .ComponentPageNumbers .Add (_aabb );_dde !=nil {return _c .Wrap (_dde ,_fbb ,"\u006f\u0076\u0065\u0072\u0054\u0068\u0072\u0065\u0073\u0068\u006f\u006c\u0064");
};if _ebb .Settings .KeepClassInstances {if _ga ,_dde =_ccge .GetBitmap (_ddcd );_dde !=nil {return _c .Wrap (_dde ,_fbb ,"\u004b\u0065\u0065\u0070Cl\u0061\u0073\u0073\u0049\u006e\u0073\u0074\u0061\u006e\u0063\u0065\u0073\u0020\u002d \u0069");};if _gbg ,_dde =_ebb .ClassInstances .GetBitmaps (_ea );
_dde !=nil {return _c .Wrap (_dde ,_fbb ,"K\u0065\u0065\u0070\u0043\u006c\u0061s\u0073\u0049\u006e\u0073\u0074\u0061\u006e\u0063\u0065s\u0020\u002d\u0020i\u0043l\u0061\u0073\u0073");};_gbg .AddBitmap (_ga );if _ca ,_dde =_fda .Get (_ddcd );_dde !=nil {return _c .Wrap (_dde ,_fbb ,"\u004be\u0065p\u0043\u006c\u0061\u0073\u0073I\u006e\u0073t\u0061\u006e\u0063\u0065\u0073");
};_gbg .AddBox (_ca );};break ;};};if !_gc {if _bfg =_ebb .ClassIDs .Add (_acd );_bfg !=nil {return _c .Wrap (_bfg ,_fbb ,"\u0021\u0066\u006f\u0075\u006e\u0064");};if _bfg =_ebb .ComponentPageNumbers .Add (_aabb );_bfg !=nil {return _c .Wrap (_bfg ,_fbb ,"\u0021\u0066\u006f\u0075\u006e\u0064");
};_gbg =&_fb .Bitmaps {};if _ga ,_bfg =_ccge .GetBitmap (_ddcd );_bfg !=nil {return _c .Wrap (_bfg ,_fbb ,"\u0021\u0066\u006f\u0075\u006e\u0064");};_gbg .AddBitmap (_ga );_cfgc ,_dddd :=_ga .Width ,_ga .Height ;_gda :=uint64 (_dddd )*uint64 (_cfgc );_ebb .TemplatesSize .Add (_gda ,_acd );
if _ca ,_bfg =_fda .Get (_ddcd );_bfg !=nil {return _c .Wrap (_bfg ,_fbb ,"\u0021\u0066\u006f\u0075\u006e\u0064");};_gbg .AddBox (_ca );_ebb .ClassInstances .AddBitmaps (_gbg );_ebb .CentroidPointsTemplates .AddPoint (_ab ,_cfa );_ebb .FgTemplates .AddInt (_adf );
_ebb .UndilatedTemplates .AddBitmap (_ga );_gdb =(_eba .Width -2*JbAddedPixels )*(_eba .Height -2*JbAddedPixels );if _bfg =_ebb .TemplateAreas .Add (_gdb );_bfg !=nil {return _c .Wrap (_bfg ,_fbb ,"\u0021\u0066\u006f\u0075\u006e\u0064");};};};_ebb .NumberOfClasses =len (_ebb .UndilatedTemplates .Values );
return nil ;};const (MaxConnCompWidth =350;MaxCharCompWidth =350;MaxWordCompWidth =1000;MaxCompHeight =120;);func _da (_dg *_fb .Bitmap ,_bde ,_cb ,_faed ,_deg int ,_ec *_fb .Bitmap )(_faf _d .Point ,_dgd error ){const _dee ="\u0066i\u006e\u0061\u006c\u0041l\u0069\u0067\u006e\u006d\u0065n\u0074P\u006fs\u0069\u0074\u0069\u006f\u006e\u0069\u006eg";
if _dg ==nil {return _faf ,_c .Error (_dee ,"\u0073\u006f\u0075\u0072ce\u0020\u006e\u006f\u0074\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};if _ec ==nil {return _faf ,_c .Error (_dee ,"t\u0065\u006d\u0070\u006cat\u0065 \u006e\u006f\u0074\u0020\u0070r\u006f\u0076\u0069\u0064\u0065\u0064");
};_bb ,_ccg :=_ec .Width ,_ec .Height ;_ee ,_ccgb :=_bde -_faed -JbAddedPixels ,_cb -_deg -JbAddedPixels ;_fa .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",_bde ,_cb ,_bb ,_ccg ,_ee ,_ccgb );
_ccgc ,_dgd :=_fb .Rect (_ee ,_ccgb ,_bb ,_ccg );if _dgd !=nil {return _faf ,_c .Wrap (_dgd ,_dee ,"");};_acf ,_ ,_dgd :=_dg .ClipRectangle (_ccgc );if _dgd !=nil {_fa .Log .Error ("\u0043a\u006e\u0027\u0074\u0020\u0063\u006c\u0069\u0070\u0020\u0072\u0065c\u0074\u0061\u006e\u0067\u006c\u0065\u003a\u0020\u0025\u0076",_ccgc );
return _faf ,_c .Wrap (_dgd ,_dee ,"");};_cga :=_fb .New (_acf .Width ,_acf .Height );_bbb :=_b .MaxInt32 ;var _ae ,_dfc ,_ecd ,_gd ,_eda int ;for _ae =-1;_ae <=1;_ae ++{for _dfc =-1;_dfc <=1;_dfc ++{if _ ,_dgd =_fb .Copy (_cga ,_acf );_dgd !=nil {return _faf ,_c .Wrap (_dgd ,_dee ,"");
};if _dgd =_cga .RasterOperation (_dfc ,_ae ,_bb ,_ccg ,_fb .PixSrcXorDst ,_ec ,0,0);_dgd !=nil {return _faf ,_c .Wrap (_dgd ,_dee ,"");};_ecd =_cga .CountPixels ();if _ecd < _bbb {_gd =_dfc ;_eda =_ae ;_bbb =_ecd ;};};};_faf .X =_gd ;_faf .Y =_eda ;return _faf ,nil ;
};func Init (settings Settings )(*Classer ,error ){const _bg ="\u0063\u006c\u0061s\u0073\u0065\u0072\u002e\u0049\u006e\u0069\u0074";_g :=&Classer {Settings :settings ,Widths :map[int ]int {},Heights :map[int ]int {},TemplatesSize :_bf .IntsMap {},TemplateAreas :&_bf .IntSlice {},ComponentPageNumbers :&_bf .IntSlice {},ClassIDs :&_bf .IntSlice {},ComponentsNumber :&_bf .IntSlice {},CentroidPoints :&_fb .Points {},CentroidPointsTemplates :&_fb .Points {},UndilatedTemplates :&_fb .Bitmaps {},DilatedTemplates :&_fb .Bitmaps {},ClassInstances :&_fb .BitmapsArray {},FgTemplates :&_bf .NumSlice {}};
if _e :=_g .Settings .Validate ();_e !=nil {return nil ,_c .Wrap (_e ,_bg ,"");};return _g ,nil ;};