mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-27 13:48:51 +08:00
110 lines
32 KiB
Go
110 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 (_de "github.com/unidoc/unipdf/v3/common";_cad "github.com/unidoc/unipdf/v3/internal/jbig2/basic";_e "github.com/unidoc/unipdf/v3/internal/jbig2/bitmap";_b "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_c "image";_ca "math";
|
|
);func (_deg *Classer )ComputeLLCorners ()(_f error ){const _fc ="\u0043l\u0061\u0073\u0073\u0065\u0072\u002e\u0043\u006f\u006d\u0070\u0075t\u0065\u004c\u004c\u0043\u006f\u0072\u006e\u0065\u0072\u0073";if _deg .PtaUL ==nil {return _b .Error (_fc ,"\u0055\u004c\u0020\u0043or\u006e\u0065\u0072\u0073\u0020\u006e\u006f\u0074\u0020\u0064\u0065\u0066\u0069\u006ee\u0064");
|
|
};_a :=len (*_deg .PtaUL );_deg .PtaLL =&_e .Points {};var (_dc ,_gg float32 ;_bge ,_fg int ;_ec *_e .Bitmap ;);for _cae :=0;_cae < _a ;_cae ++{_dc ,_gg ,_f =_deg .PtaUL .GetGeometry (_cae );if _f !=nil {_de .Log .Debug ("\u0047e\u0074\u0074\u0069\u006e\u0067\u0020\u0050\u0074\u0061\u0055\u004c \u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0076",_f );
|
|
return _b .Wrap (_f ,_fc ,"\u0050\u0074\u0061\u0055\u004c\u0020\u0047\u0065\u006fm\u0065\u0074\u0072\u0079");};_bge ,_f =_deg .ClassIDs .Get (_cae );if _f !=nil {_de .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",_f );
|
|
return _b .Wrap (_f ,_fc ,"\u0043l\u0061\u0073\u0073\u0049\u0044");};_ec ,_f =_deg .UndilatedTemplates .GetBitmap (_bge );if _f !=nil {_de .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",_f );
|
|
return _b .Wrap (_f ,_fc ,"\u0055\u006e\u0064\u0069la\u0074\u0065\u0064\u0020\u0054\u0065\u006d\u0070\u006c\u0061\u0074\u0065\u0073");};_fg =_ec .Height ;_deg .PtaLL .AddPoint (_dc ,_gg +float32 (_fg ));};return nil ;};func (_edb *Classer )classifyRankHaus (_bca *_e .Boxes ,_daf *_e .Bitmaps ,_gaea int )error {const _gdfb ="\u0063\u006ca\u0073\u0073\u0069f\u0079\u0052\u0061\u006e\u006b\u0048\u0061\u0075\u0073";
|
|
if _bca ==nil {return _b .Error (_gdfb ,"\u0062\u006fx\u0061\u0020\u006eo\u0074\u0020\u0064\u0065\u0066\u0069\u006e\u0065\u0064");};if _daf ==nil {return _b .Error (_gdfb ,"\u0070\u0069x\u0061\u0020\u006eo\u0074\u0020\u0064\u0065\u0066\u0069\u006e\u0065\u0064");
|
|
};_cedg :=len (_daf .Values );if _cedg ==0{return _b .Error (_gdfb ,"e\u006dp\u0074\u0079\u0020\u006e\u0065\u0077\u0020\u0063o\u006d\u0070\u006f\u006een\u0074\u0073");};_bbd :=_daf .CountPixels ();_aad :=_edb .Settings .SizeHaus ;_gec :=_e .SelCreateBrick (_aad ,_aad ,_aad /2,_aad /2,_e .SelHit );
|
|
_edcg :=&_e .Bitmaps {Values :make ([]*_e .Bitmap ,_cedg )};_gcgg :=&_e .Bitmaps {Values :make ([]*_e .Bitmap ,_cedg )};var (_cfc ,_efd ,_aef *_e .Bitmap ;_cbg error ;);for _dag :=0;_dag < _cedg ;_dag ++{_cfc ,_cbg =_daf .GetBitmap (_dag );if _cbg !=nil {return _b .Wrap (_cbg ,_gdfb ,"");
|
|
};_efd ,_cbg =_cfc .AddBorderGeneral (JbAddedPixels ,JbAddedPixels ,JbAddedPixels ,JbAddedPixels ,0);if _cbg !=nil {return _b .Wrap (_cbg ,_gdfb ,"");};_aef ,_cbg =_e .Dilate (nil ,_efd ,_gec );if _cbg !=nil {return _b .Wrap (_cbg ,_gdfb ,"");};_edcg .Values [_cedg ]=_efd ;
|
|
_gcgg .Values [_cedg ]=_aef ;};_gbf ,_cbg :=_e .Centroids (_edcg .Values );if _cbg !=nil {return _b .Wrap (_cbg ,_gdfb ,"");};if _cbg =_gbf .Add (_edb .CentroidPoints );_cbg !=nil {_de .Log .Trace ("\u004e\u006f\u0020\u0063en\u0074\u0072\u006f\u0069\u0064\u0073\u0020\u0074\u006f\u0020\u0061\u0064\u0064");
|
|
};if _edb .Settings .RankHaus ==1.0{_cbg =_edb .classifyRankHouseOne (_bca ,_daf ,_edcg ,_gcgg ,_gbf ,_gaea );}else {_cbg =_edb .classifyRankHouseNonOne (_bca ,_daf ,_edcg ,_gcgg ,_gbf ,_bbd ,_gaea );};if _cbg !=nil {return _b .Wrap (_cbg ,_gdfb ,"");};
|
|
return nil ;};func (_dcd Settings )Validate ()error {const _cdb ="\u0053\u0065\u0074\u0074\u0069\u006e\u0067\u0073\u002e\u0056\u0061\u006ci\u0064\u0061\u0074\u0065";if _dcd .Thresh < 0.4||_dcd .Thresh > 0.98{return _b .Error (_cdb ,"\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 _dcd .WeightFactor < 0.0||_dcd .WeightFactor > 1.0{return _b .Error (_cdb ,"\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 _dcd .RankHaus < 0.5||_dcd .RankHaus > 1.0{return _b .Error (_cdb ,"\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 _dcd .SizeHaus < 1||_dcd .SizeHaus > 10{return _b .Error (_cdb ,"\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 _dcd .Components {case _e .ComponentConn ,_e .ComponentCharacters ,_e .ComponentWords :default:return _b .Error (_cdb ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0063\u006c\u0061\u0073s\u0065r\u0020c\u006f\u006d\u0070\u006f\u006e\u0065\u006et");
|
|
};return nil ;};var _eab bool ;func (_cbf *Classer )classifyCorrelation (_dcg *_e .Boxes ,_dff *_e .Bitmaps ,_deed int )error {const _ebe ="\u0063\u006c\u0061\u0073si\u0066\u0079\u0043\u006f\u0072\u0072\u0065\u006c\u0061\u0074\u0069\u006f\u006e";if _dcg ==nil {return _b .Error (_ebe ,"\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 _dff ==nil {return _b .Error (_ebe ,"\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");};_aged :=len (_dff .Values );if _aged ==0{_de .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 (_dgf ,_cg *_e .Bitmap ;_fae error ;);_edc :=&_e .Bitmaps {Values :make ([]*_e .Bitmap ,_aged )};for _adb ,_aa :=range _dff .Values {_cg ,_fae =_aa .AddBorderGeneral (JbAddedPixels ,JbAddedPixels ,JbAddedPixels ,JbAddedPixels ,0);if _fae !=nil {return _b .Wrap (_fae ,_ebe ,"");
|
|
};_edc .Values [_adb ]=_cg ;};_bb :=_cbf .FgTemplates ;_ebc :=_e .MakePixelSumTab8 ();_cd :=_e .MakePixelCentroidTab8 ();_agec :=make ([]int ,_aged );_eda :=make ([][]int ,_aged );_fgc :=_e .Points (make ([]_e .Point ,_aged ));_bged :=&_fgc ;var (_bc ,_dfg int ;
|
|
_aag ,_ee ,_bfbd int ;_dea ,_ef int ;_gcad byte ;);for _ffd ,_bdf :=range _edc .Values {_eda [_ffd ]=make ([]int ,_bdf .Height );_bc =0;_dfg =0;_ee =(_bdf .Height -1)*_bdf .RowStride ;_aag =0;for _ef =_bdf .Height -1;_ef >=0;_ef ,_ee =_ef -1,_ee -_bdf .RowStride {_eda [_ffd ][_ef ]=_aag ;
|
|
_bfbd =0;for _dea =0;_dea < _bdf .RowStride ;_dea ++{_gcad =_bdf .Data [_ee +_dea ];_bfbd +=_ebc [_gcad ];_bc +=_cd [_gcad ]+_dea *8*_ebc [_gcad ];};_aag +=_bfbd ;_dfg +=_bfbd *_ef ;};_agec [_ffd ]=_aag ;if _aag > 0{(*_bged )[_ffd ]=_e .Point {X :float32 (_bc )/float32 (_aag ),Y :float32 (_dfg )/float32 (_aag )};
|
|
}else {(*_bged )[_ffd ]=_e .Point {X :float32 (_bdf .Width )/float32 (2),Y :float32 (_bdf .Height )/float32 (2)};};};if _fae =_cbf .CentroidPoints .Add (_bged );_fae !=nil {return _b .Wrap (_fae ,_ebe ,"\u0063\u0065\u006et\u0072\u006f\u0069\u0064\u0020\u0061\u0064\u0064");
|
|
};var (_ceg ,_edag ,_fda int ;_dfbe float64 ;_adbf ,_eeg ,_ab ,_bcd float32 ;_gfa ,_eff _e .Point ;_gbe bool ;_gcff *similarTemplatesFinder ;_cfd int ;_eba *_e .Bitmap ;_gbb *_c .Rectangle ;_bcdc *_e .Bitmaps ;);for _cfd ,_cg =range _edc .Values {_edag =_agec [_cfd ];
|
|
if _adbf ,_eeg ,_fae =_bged .GetGeometry (_cfd );_fae !=nil {return _b .Wrap (_fae ,_ebe ,"\u0070t\u0061\u0020\u002d\u0020\u0069");};_gbe =false ;_afe :=len (_cbf .UndilatedTemplates .Values );_gcff =_agbb (_cbf ,_cg );for _cadb :=_gcff .Next ();_cadb > -1;
|
|
{if _eba ,_fae =_cbf .UndilatedTemplates .GetBitmap (_cadb );_fae !=nil {return _b .Wrap (_fae ,_ebe ,"\u0075\u006e\u0069dl\u0061\u0074\u0065\u0064\u005b\u0069\u0063\u006c\u0061\u0073\u0073\u005d\u0020\u003d\u0020\u0062\u006d\u0032");};if _fda ,_fae =_bb .GetInt (_cadb );
|
|
_fae !=nil {_de .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",_fae );};if _ab ,_bcd ,_fae =_cbf .CentroidPointsTemplates .GetGeometry (_cadb );
|
|
_fae !=nil {return _b .Wrap (_fae ,_ebe ,"\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 _cbf .Settings .WeightFactor > 0.0{if _ceg ,_fae =_cbf .TemplateAreas .Get (_cadb );_fae !=nil {_de .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",_fae );
|
|
};_dfbe =_cbf .Settings .Thresh +(1.0-_cbf .Settings .Thresh )*_cbf .Settings .WeightFactor *float64 (_fda )/float64 (_ceg );}else {_dfbe =_cbf .Settings .Thresh ;};_fac ,_bdb :=_e .CorrelationScoreThresholded (_cg ,_eba ,_edag ,_fda ,_gfa .X -_eff .X ,_gfa .Y -_eff .Y ,MaxDiffWidth ,MaxDiffHeight ,_ebc ,_eda [_cfd ],float32 (_dfbe ));
|
|
if _bdb !=nil {return _b .Wrap (_bdb ,_ebe ,"");};if _eab {var (_ebg ,_cbd float64 ;_dab ,_gbbd int ;);_ebg ,_bdb =_e .CorrelationScore (_cg ,_eba ,_edag ,_fda ,_adbf -_ab ,_eeg -_bcd ,MaxDiffWidth ,MaxDiffHeight ,_ebc );if _bdb !=nil {return _b .Wrap (_bdb ,_ebe ,"d\u0065\u0062\u0075\u0067Co\u0072r\u0065\u006c\u0061\u0074\u0069o\u006e\u0053\u0063\u006f\u0072\u0065");
|
|
};_cbd ,_bdb =_e .CorrelationScoreSimple (_cg ,_eba ,_edag ,_fda ,_adbf -_ab ,_eeg -_bcd ,MaxDiffWidth ,MaxDiffHeight ,_ebc );if _bdb !=nil {return _b .Wrap (_bdb ,_ebe ,"d\u0065\u0062\u0075\u0067Co\u0072r\u0065\u006c\u0061\u0074\u0069o\u006e\u0053\u0063\u006f\u0072\u0065");
|
|
};_dab =int (_ca .Sqrt (_ebg *float64 (_edag )*float64 (_fda )));_gbbd =int (_ca .Sqrt (_cbd *float64 (_edag )*float64 (_fda )));if (_ebg >=_dfbe )!=(_cbd >=_dfbe ){return _b .Errorf (_ebe ,"\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",_dab ,_ebg ,_ebg >=_dfbe ,_gbbd ,_cbd ,_cbd >=_dfbe ,_ebg -_cbd );
|
|
};if _ebg >=_dfbe !=_fac {return _b .Errorf (_ebe ,"\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",_ebg ,_ebg *float64 (_edag )*float64 (_fda ),_dab ,_dfbe ,float32 (_dfbe )*float32 (_edag )*float32 (_fda ),_fac );
|
|
};};if _fac {_gbe =true ;if _bdb =_cbf .ClassIDs .Add (_cadb );_bdb !=nil {return _b .Wrap (_bdb ,_ebe ,"\u006f\u0076\u0065\u0072\u0054\u0068\u0072\u0065\u0073\u0068\u006f\u006c\u0064");};if _bdb =_cbf .ComponentPageNumbers .Add (_deed );_bdb !=nil {return _b .Wrap (_bdb ,_ebe ,"\u006f\u0076\u0065\u0072\u0054\u0068\u0072\u0065\u0073\u0068\u006f\u006c\u0064");
|
|
};if _cbf .Settings .KeepClassInstances {if _dgf ,_bdb =_dff .GetBitmap (_cfd );_bdb !=nil {return _b .Wrap (_bdb ,_ebe ,"\u004b\u0065\u0065\u0070Cl\u0061\u0073\u0073\u0049\u006e\u0073\u0074\u0061\u006e\u0063\u0065\u0073\u0020\u002d \u0069");};if _bcdc ,_bdb =_cbf .ClassInstances .GetBitmaps (_cadb );
|
|
_bdb !=nil {return _b .Wrap (_bdb ,_ebe ,"K\u0065\u0065\u0070\u0043\u006c\u0061s\u0073\u0049\u006e\u0073\u0074\u0061\u006e\u0063\u0065s\u0020\u002d\u0020i\u0043l\u0061\u0073\u0073");};_bcdc .AddBitmap (_dgf );if _gbb ,_bdb =_dcg .Get (_cfd );_bdb !=nil {return _b .Wrap (_bdb ,_ebe ,"\u004be\u0065p\u0043\u006c\u0061\u0073\u0073I\u006e\u0073t\u0061\u006e\u0063\u0065\u0073");
|
|
};_bcdc .AddBox (_gbb );};break ;};};if !_gbe {if _fae =_cbf .ClassIDs .Add (_afe );_fae !=nil {return _b .Wrap (_fae ,_ebe ,"\u0021\u0066\u006f\u0075\u006e\u0064");};if _fae =_cbf .ComponentPageNumbers .Add (_deed );_fae !=nil {return _b .Wrap (_fae ,_ebe ,"\u0021\u0066\u006f\u0075\u006e\u0064");
|
|
};_bcdc =&_e .Bitmaps {};if _dgf ,_fae =_dff .GetBitmap (_cfd );_fae !=nil {return _b .Wrap (_fae ,_ebe ,"\u0021\u0066\u006f\u0075\u006e\u0064");};_bcdc .AddBitmap (_dgf );_bfa ,_fb :=_dgf .Width ,_dgf .Height ;_ffb :=uint64 (_fb )*uint64 (_bfa );_cbf .TemplatesSize .Add (_ffb ,_afe );
|
|
if _gbb ,_fae =_dcg .Get (_cfd );_fae !=nil {return _b .Wrap (_fae ,_ebe ,"\u0021\u0066\u006f\u0075\u006e\u0064");};_bcdc .AddBox (_gbb );_cbf .ClassInstances .AddBitmaps (_bcdc );_cbf .CentroidPointsTemplates .AddPoint (_adbf ,_eeg );_cbf .FgTemplates .AddInt (_edag );
|
|
_cbf .UndilatedTemplates .AddBitmap (_dgf );_ceg =(_cg .Width -2*JbAddedPixels )*(_cg .Height -2*JbAddedPixels );if _fae =_cbf .TemplateAreas .Add (_ceg );_fae !=nil {return _b .Wrap (_fae ,_ebe ,"\u0021\u0066\u006f\u0075\u006e\u0064");};};};_cbf .NumberOfClasses =len (_cbf .UndilatedTemplates .Values );
|
|
return nil ;};type similarTemplatesFinder struct{Classer *Classer ;Width int ;Height int ;Index int ;CurrentNumbers []int ;N int ;};func (_fd *Classer )addPageComponents (_ff *_e .Bitmap ,_ae *_e .Boxes ,_bf *_e .Bitmaps ,_ce int ,_ed Method )error {const _gd ="\u0043l\u0061\u0073\u0073\u0065r\u002e\u0041\u0064\u0064\u0050a\u0067e\u0043o\u006d\u0070\u006f\u006e\u0065\u006e\u0074s";
|
|
if _ff ==nil {return _b .Error (_gd ,"\u006e\u0069\u006c\u0020\u0069\u006e\u0070\u0075\u0074 \u0070\u0061\u0067\u0065");};if _ae ==nil ||_bf ==nil ||len (*_ae )==0{_de .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",_ff );
|
|
return nil ;};var _bfb error ;switch _ed {case RankHaus :_bfb =_fd .classifyRankHaus (_ae ,_bf ,_ce );case Correlation :_bfb =_fd .classifyCorrelation (_ae ,_bf ,_ce );default:_de .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",_ed );
|
|
return _b .Error (_gd ,"\u0075\u006e\u006bno\u0077\u006e\u0020\u0063\u006c\u0061\u0073\u0073\u0069\u0066\u0079\u0020\u006d\u0065\u0074\u0068\u006f\u0064");};if _bfb !=nil {return _b .Wrap (_bfb ,_gd ,"");};if _bfb =_fd .getULCorners (_ff ,_ae );_bfb !=nil {return _b .Wrap (_bfb ,_gd ,"");
|
|
};_fa :=len (*_ae );_fd .BaseIndex +=_fa ;if _bfb =_fd .ComponentsNumber .Add (_fa );_bfb !=nil {return _b .Wrap (_bfb ,_gd ,"");};return nil ;};const (MaxDiffWidth =2;MaxDiffHeight =2;);func _da (_cba *_e .Bitmap ,_ad ,_ea ,_gcf ,_fde int ,_be *_e .Bitmap )(_dba _c .Point ,_cf error ){const _ebf ="\u0066i\u006e\u0061\u006c\u0041l\u0069\u0067\u006e\u006d\u0065n\u0074P\u006fs\u0069\u0074\u0069\u006f\u006e\u0069\u006eg";
|
|
if _cba ==nil {return _dba ,_b .Error (_ebf ,"\u0073\u006f\u0075\u0072ce\u0020\u006e\u006f\u0074\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065\u0064");};if _be ==nil {return _dba ,_b .Error (_ebf ,"t\u0065\u006d\u0070\u006cat\u0065 \u006e\u006f\u0074\u0020\u0070r\u006f\u0076\u0069\u0064\u0065\u0064");
|
|
};_beg ,_ag :=_be .Width ,_be .Height ;_cfe ,_dg :=_ad -_gcf -JbAddedPixels ,_ea -_fde -JbAddedPixels ;_de .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",_ad ,_ea ,_beg ,_ag ,_cfe ,_dg );
|
|
_geea ,_cf :=_e .Rect (_cfe ,_dg ,_beg ,_ag );if _cf !=nil {return _dba ,_b .Wrap (_cf ,_ebf ,"");};_add ,_ ,_cf :=_cba .ClipRectangle (_geea );if _cf !=nil {_de .Log .Error ("\u0043a\u006e\u0027\u0074\u0020\u0063\u006c\u0069\u0070\u0020\u0072\u0065c\u0074\u0061\u006e\u0067\u006c\u0065\u003a\u0020\u0025\u0076",_geea );
|
|
return _dba ,_b .Wrap (_cf ,_ebf ,"");};_aff :=_e .New (_add .Width ,_add .Height );_age :=_ca .MaxInt32 ;var _beb ,_bfc ,_gae ,_fdd ,_ece int ;for _beb =-1;_beb <=1;_beb ++{for _bfc =-1;_bfc <=1;_bfc ++{if _ ,_cf =_e .Copy (_aff ,_add );_cf !=nil {return _dba ,_b .Wrap (_cf ,_ebf ,"");
|
|
};if _cf =_aff .RasterOperation (_bfc ,_beb ,_beg ,_ag ,_e .PixSrcXorDst ,_be ,0,0);_cf !=nil {return _dba ,_b .Wrap (_cf ,_ebf ,"");};_gae =_aff .CountPixels ();if _gae < _age {_fdd =_bfc ;_ece =_beb ;_age =_gae ;};};};_dba .X =_fdd ;_dba .Y =_ece ;return _dba ,nil ;
|
|
};type Settings struct{MaxCompWidth int ;MaxCompHeight int ;SizeHaus int ;RankHaus float64 ;Thresh float64 ;WeightFactor float64 ;KeepClassInstances bool ;Components _e .Component ;Method Method ;};func (_bgf *Classer )getULCorners (_ge *_e .Bitmap ,_gc *_e .Boxes )error {const _gdb ="\u0067\u0065\u0074U\u004c\u0043\u006f\u0072\u006e\u0065\u0072\u0073";
|
|
if _ge ==nil {return _b .Error (_gdb ,"\u006e\u0069l\u0020\u0069\u006da\u0067\u0065\u0020\u0062\u0069\u0074\u006d\u0061\u0070");};if _gc ==nil {return _b .Error (_gdb ,"\u006e\u0069\u006c\u0020\u0062\u006f\u0075\u006e\u0064\u0073");};if _bgf .PtaUL ==nil {_bgf .PtaUL =&_e .Points {};
|
|
};_ac :=len (*_gc );var (_ga ,_aec ,_gdf ,_eb int ;_db ,_bd ,_ced ,_af float32 ;_gca error ;_gf *_c .Rectangle ;_gb *_e .Bitmap ;_fe _c .Point ;);for _fag :=0;_fag < _ac ;_fag ++{_ga =_bgf .BaseIndex +_fag ;if _db ,_bd ,_gca =_bgf .CentroidPoints .GetGeometry (_ga );
|
|
_gca !=nil {return _b .Wrap (_gca ,_gdb ,"\u0043\u0065\u006e\u0074\u0072\u006f\u0069\u0064\u0050o\u0069\u006e\u0074\u0073");};if _aec ,_gca =_bgf .ClassIDs .Get (_ga );_gca !=nil {return _b .Wrap (_gca ,_gdb ,"\u0043\u006c\u0061s\u0073\u0049\u0044\u0073\u002e\u0047\u0065\u0074");
|
|
};if _ced ,_af ,_gca =_bgf .CentroidPointsTemplates .GetGeometry (_aec );_gca !=nil {return _b .Wrap (_gca ,_gdb ,"\u0043\u0065\u006etr\u006f\u0069\u0064\u0050\u006f\u0069\u006e\u0074\u0073\u0054\u0065\u006d\u0070\u006c\u0061\u0074\u0065\u0073");};_gee :=_ced -_db ;
|
|
_feb :=_af -_bd ;if _gee >=0{_gdf =int (_gee +0.5);}else {_gdf =int (_gee -0.5);};if _feb >=0{_eb =int (_feb +0.5);}else {_eb =int (_feb -0.5);};if _gf ,_gca =_gc .Get (_fag );_gca !=nil {return _b .Wrap (_gca ,_gdb ,"");};_ddc ,_afc :=_gf .Min .X ,_gf .Min .Y ;
|
|
_gb ,_gca =_bgf .UndilatedTemplates .GetBitmap (_aec );if _gca !=nil {return _b .Wrap (_gca ,_gdb ,"\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");
|
|
};_fe ,_gca =_da (_ge ,_ddc ,_afc ,_gdf ,_eb ,_gb );if _gca !=nil {return _b .Wrap (_gca ,_gdb ,"");};_bgf .PtaUL .AddPoint (float32 (_ddc -_gdf +_fe .X ),float32 (_afc -_eb +_fe .Y ));};return nil ;};func Init (settings Settings )(*Classer ,error ){const _dee ="\u0063\u006c\u0061s\u0073\u0065\u0072\u002e\u0049\u006e\u0069\u0074";
|
|
_df :=&Classer {Settings :settings ,Widths :map[int ]int {},Heights :map[int ]int {},TemplatesSize :_cad .IntsMap {},TemplateAreas :&_cad .IntSlice {},ComponentPageNumbers :&_cad .IntSlice {},ClassIDs :&_cad .IntSlice {},ComponentsNumber :&_cad .IntSlice {},CentroidPoints :&_e .Points {},CentroidPointsTemplates :&_e .Points {},UndilatedTemplates :&_e .Bitmaps {},DilatedTemplates :&_e .Bitmaps {},ClassInstances :&_e .BitmapsArray {},FgTemplates :&_cad .NumSlice {}};
|
|
if _bg :=_df .Settings .Validate ();_bg !=nil {return nil ,_b .Wrap (_bg ,_dee ,"");};return _df ,nil ;};func _agbb (_bgb *Classer ,_febg *_e .Bitmap )*similarTemplatesFinder {return &similarTemplatesFinder {Width :_febg .Width ,Height :_febg .Height ,Classer :_bgb };
|
|
};const (MaxConnCompWidth =350;MaxCharCompWidth =350;MaxWordCompWidth =1000;MaxCompHeight =120;);const (RankHaus Method =iota ;Correlation ;);type Method int ;const JbAddedPixels =6;func (_cab *Classer )AddPage (inputPage *_e .Bitmap ,pageNumber int ,method Method )(_dfb error ){const _dd ="\u0043l\u0061s\u0073\u0065\u0072\u002e\u0041\u0064\u0064\u0050\u0061\u0067\u0065";
|
|
_cab .Widths [pageNumber ]=inputPage .Width ;_cab .Heights [pageNumber ]=inputPage .Height ;if _dfb =_cab .verifyMethod (method );_dfb !=nil {return _b .Wrap (_dfb ,_dd ,"");};_ba ,_g ,_dfb :=inputPage .GetComponents (_cab .Settings .Components ,_cab .Settings .MaxCompWidth ,_cab .Settings .MaxCompHeight );
|
|
if _dfb !=nil {return _b .Wrap (_dfb ,_dd ,"");};_de .Log .Debug ("\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074s\u003a\u0020\u0025\u0076",_ba );if _dfb =_cab .addPageComponents (inputPage ,_g ,_ba ,pageNumber ,method );_dfb !=nil {return _b .Wrap (_dfb ,_dd ,"");
|
|
};return nil ;};func (_ebb *Classer )verifyMethod (_cb Method )error {if _cb !=RankHaus &&_cb !=Correlation {return _b .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 (_dbb *Settings )SetDefault (){if _dbb .MaxCompWidth ==0{switch _dbb .Components {case _e .ComponentConn :_dbb .MaxCompWidth =MaxConnCompWidth ;case _e .ComponentCharacters :_dbb .MaxCompWidth =MaxCharCompWidth ;case _e .ComponentWords :_dbb .MaxCompWidth =MaxWordCompWidth ;
|
|
};};if _dbb .MaxCompHeight ==0{_dbb .MaxCompHeight =MaxCompHeight ;};if _dbb .Thresh ==0.0{_dbb .Thresh =0.9;};if _dbb .WeightFactor ==0.0{_dbb .WeightFactor =0.75;};if _dbb .RankHaus ==0.0{_dbb .RankHaus =0.97;};if _dbb .SizeHaus ==0{_dbb .SizeHaus =2;
|
|
};};func (_agc *Classer )classifyRankHouseNonOne (_aaga *_e .Boxes ,_caa ,_gea ,_aed *_e .Bitmaps ,_cabc *_e .Points ,_cgd *_cad .NumSlice ,_gdbg int )(_ggd error ){const _adg ="\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 (_agb ,_degg ,_bcf ,_dgb float32 ;_edf ,_efb ,_dged int ;_ede ,_dcae ,_cdgd ,_bab ,_efa *_e .Bitmap ;_dfcd ,_cdd bool ;);_aeda :=_e .MakePixelSumTab8 ();for _fcb :=0;_fcb < len (_caa .Values );_fcb ++{if _dcae ,_ggd =_gea .GetBitmap (_fcb );_ggd !=nil {return _b .Wrap (_ggd ,_adg ,"b\u006d\u0073\u0031\u002e\u0047\u0065\u0074\u0028\u0069\u0029");
|
|
};if _edf ,_ggd =_cgd .GetInt (_fcb );_ggd !=nil {_de .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",_fcb ,_ggd );
|
|
};if _cdgd ,_ggd =_aed .GetBitmap (_fcb );_ggd !=nil {return _b .Wrap (_ggd ,_adg ,"b\u006d\u0073\u0032\u002e\u0047\u0065\u0074\u0028\u0069\u0029");};if _agb ,_degg ,_ggd =_cabc .GetGeometry (_fcb );_ggd !=nil {return _b .Wrapf (_ggd ,_adg ,"\u0070t\u0061[\u0069\u005d\u002e\u0047\u0065\u006f\u006d\u0065\u0074\u0072\u0079");
|
|
};_cfee :=len (_agc .UndilatedTemplates .Values );_dfcd =false ;_fgcbg :=_agbb (_agc ,_dcae );for _dged =_fgcbg .Next ();_dged > -1;{if _bab ,_ggd =_agc .UndilatedTemplates .GetBitmap (_dged );_ggd !=nil {return _b .Wrap (_ggd ,_adg ,"\u0070\u0069\u0078\u0061\u0074\u002e\u005b\u0069\u0043l\u0061\u0073\u0073\u005d");
|
|
};if _efb ,_ggd =_agc .FgTemplates .GetInt (_dged );_ggd !=nil {_de .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",_dged ,_ggd );
|
|
};if _efa ,_ggd =_agc .DilatedTemplates .GetBitmap (_dged );_ggd !=nil {return _b .Wrap (_ggd ,_adg ,"\u0070\u0069\u0078\u0061\u0074\u0064\u005b\u0069\u0043l\u0061\u0073\u0073\u005d");};if _bcf ,_dgb ,_ggd =_agc .CentroidPointsTemplates .GetGeometry (_dged );
|
|
_ggd !=nil {return _b .Wrap (_ggd ,_adg ,"\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");};_cdd ,_ggd =_e .RankHausTest (_dcae ,_cdgd ,_bab ,_efa ,_agb -_bcf ,_degg -_dgb ,MaxDiffWidth ,MaxDiffHeight ,_edf ,_efb ,float32 (_agc .Settings .RankHaus ),_aeda );
|
|
if _ggd !=nil {return _b .Wrap (_ggd ,_adg ,"");};if _cdd {_dfcd =true ;if _ggd =_agc .ClassIDs .Add (_dged );_ggd !=nil {return _b .Wrap (_ggd ,_adg ,"");};if _ggd =_agc .ComponentPageNumbers .Add (_gdbg );_ggd !=nil {return _b .Wrap (_ggd ,_adg ,"");
|
|
};if _agc .Settings .KeepClassInstances {_eced ,_bgfc :=_agc .ClassInstances .GetBitmaps (_dged );if _bgfc !=nil {return _b .Wrap (_bgfc ,_adg ,"\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 _ede ,_bgfc =_caa .GetBitmap (_fcb );_bgfc !=nil {return _b .Wrap (_bgfc ,_adg ,"\u0070i\u0078\u0061\u005b\u0069\u005d");};_eced .Values =append (_eced .Values ,_ede );_bgd ,_bgfc :=_aaga .Get (_fcb );if _bgfc !=nil {return _b .Wrap (_bgfc ,_adg ,"b\u006f\u0078\u0061\u002e\u0047\u0065\u0074\u0028\u0069\u0029");
|
|
};_eced .Boxes =append (_eced .Boxes ,_bgd );};break ;};};if !_dfcd {if _ggd =_agc .ClassIDs .Add (_cfee );_ggd !=nil {return _b .Wrap (_ggd ,_adg ,"\u0021\u0066\u006f\u0075\u006e\u0064");};if _ggd =_agc .ComponentPageNumbers .Add (_gdbg );_ggd !=nil {return _b .Wrap (_ggd ,_adg ,"\u0021\u0066\u006f\u0075\u006e\u0064");
|
|
};_ebbb :=&_e .Bitmaps {};_ede =_caa .Values [_fcb ];_ebbb .AddBitmap (_ede );_agcd ,_gega :=_ede .Width ,_ede .Height ;_agc .TemplatesSize .Add (uint64 (_agcd )*uint64 (_gega ),_cfee );_gaa ,_ffbc :=_aaga .Get (_fcb );if _ffbc !=nil {return _b .Wrap (_ffbc ,_adg ,"\u0021\u0066\u006f\u0075\u006e\u0064");
|
|
};_ebbb .AddBox (_gaa );_agc .ClassInstances .AddBitmaps (_ebbb );_agc .CentroidPointsTemplates .AddPoint (_agb ,_degg );_agc .UndilatedTemplates .AddBitmap (_dcae );_agc .DilatedTemplates .AddBitmap (_cdgd );_agc .FgTemplates .AddInt (_edf );};};_agc .NumberOfClasses =len (_agc .UndilatedTemplates .Values );
|
|
return nil ;};type Classer struct{BaseIndex int ;Settings Settings ;ComponentsNumber *_cad .IntSlice ;TemplateAreas *_cad .IntSlice ;Widths map[int ]int ;Heights map[int ]int ;NumberOfClasses int ;ClassInstances *_e .BitmapsArray ;UndilatedTemplates *_e .Bitmaps ;
|
|
DilatedTemplates *_e .Bitmaps ;TemplatesSize _cad .IntsMap ;FgTemplates *_cad .NumSlice ;CentroidPoints *_e .Points ;CentroidPointsTemplates *_e .Points ;ClassIDs *_cad .IntSlice ;ComponentPageNumbers *_cad .IntSlice ;PtaUL *_e .Points ;PtaLL *_e .Points ;
|
|
};func DefaultSettings ()Settings {_cgf :=&Settings {};_cgf .SetDefault ();return *_cgf };func (_dfc *Classer )classifyRankHouseOne (_dca *_e .Boxes ,_ebgc ,_gfb ,_ddd *_e .Bitmaps ,_dge *_e .Points ,_abe int )(_gfbg error ){const _fdec ="\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 (_ebd ,_ebac ,_dgd ,_fge float32 ;_baa int ;_aca ,_afa ,_ffa ,_gdg ,_geg *_e .Bitmap ;_eee ,_dde bool ;);for _eegf :=0;_eegf < len (_ebgc .Values );_eegf ++{_afa =_gfb .Values [_eegf ];_ffa =_ddd .Values [_eegf ];_ebd ,_ebac ,_gfbg =_dge .GetGeometry (_eegf );
|
|
if _gfbg !=nil {return _b .Wrapf (_gfbg ,_fdec ,"\u0066\u0069\u0072\u0073\u0074\u0020\u0067\u0065\u006fm\u0065\u0074\u0072\u0079");};_eg :=len (_dfc .UndilatedTemplates .Values );_eee =false ;_fdaf :=_agbb (_dfc ,_afa );for _baa =_fdaf .Next ();_baa > -1;
|
|
{_gdg ,_gfbg =_dfc .UndilatedTemplates .GetBitmap (_baa );if _gfbg !=nil {return _b .Wrap (_gfbg ,_fdec ,"\u0062\u006d\u0033");};_geg ,_gfbg =_dfc .DilatedTemplates .GetBitmap (_baa );if _gfbg !=nil {return _b .Wrap (_gfbg ,_fdec ,"\u0062\u006d\u0034");
|
|
};_dgd ,_fge ,_gfbg =_dfc .CentroidPointsTemplates .GetGeometry (_baa );if _gfbg !=nil {return _b .Wrap (_gfbg ,_fdec ,"\u0043\u0065\u006e\u0074\u0072\u006f\u0069\u0064\u0054\u0065\u006d\u0070l\u0061\u0074\u0065\u0073");};_dde ,_gfbg =_e .HausTest (_afa ,_ffa ,_gdg ,_geg ,_ebd -_dgd ,_ebac -_fge ,MaxDiffWidth ,MaxDiffHeight );
|
|
if _gfbg !=nil {return _b .Wrap (_gfbg ,_fdec ,"");};if _dde {_eee =true ;if _gfbg =_dfc .ClassIDs .Add (_baa );_gfbg !=nil {return _b .Wrap (_gfbg ,_fdec ,"");};if _gfbg =_dfc .ComponentPageNumbers .Add (_abe );_gfbg !=nil {return _b .Wrap (_gfbg ,_fdec ,"");
|
|
};if _dfc .Settings .KeepClassInstances {_cdg ,_bcde :=_dfc .ClassInstances .GetBitmaps (_baa );if _bcde !=nil {return _b .Wrap (_bcde ,_fdec ,"\u004be\u0065\u0070\u0050\u0069\u0078\u0061a");};_aca ,_bcde =_ebgc .GetBitmap (_eegf );if _bcde !=nil {return _b .Wrap (_bcde ,_fdec ,"\u004be\u0065\u0070\u0050\u0069\u0078\u0061a");
|
|
};_cdg .AddBitmap (_aca );_dbd ,_bcde :=_dca .Get (_eegf );if _bcde !=nil {return _b .Wrap (_bcde ,_fdec ,"\u004be\u0065\u0070\u0050\u0069\u0078\u0061a");};_cdg .AddBox (_dbd );};break ;};};if !_eee {if _gfbg =_dfc .ClassIDs .Add (_eg );_gfbg !=nil {return _b .Wrap (_gfbg ,_fdec ,"");
|
|
};if _gfbg =_dfc .ComponentPageNumbers .Add (_abe );_gfbg !=nil {return _b .Wrap (_gfbg ,_fdec ,"");};_fgcb :=&_e .Bitmaps {};_aca ,_gfbg =_ebgc .GetBitmap (_eegf );if _gfbg !=nil {return _b .Wrap (_gfbg ,_fdec ,"\u0021\u0066\u006f\u0075\u006e\u0064");
|
|
};_fgcb .Values =append (_fgcb .Values ,_aca );_dbf ,_eac :=_aca .Width ,_aca .Height ;_dfc .TemplatesSize .Add (uint64 (_eac )*uint64 (_dbf ),_eg );_dgfe ,_egd :=_dca .Get (_eegf );if _egd !=nil {return _b .Wrap (_egd ,_fdec ,"\u0021\u0066\u006f\u0075\u006e\u0064");
|
|
};_fgcb .AddBox (_dgfe );_dfc .ClassInstances .AddBitmaps (_fgcb );_dfc .CentroidPointsTemplates .AddPoint (_ebd ,_ebac );_dfc .UndilatedTemplates .AddBitmap (_afa );_dfc .DilatedTemplates .AddBitmap (_ffa );};};return nil ;};func (_agg *similarTemplatesFinder )Next ()int {var (_ace ,_feg ,_cbb ,_edfg int ;
|
|
_aac bool ;_addg *_e .Bitmap ;_cfeec error ;);for {if _agg .Index >=25{return -1;};_feg =_agg .Width +TwoByTwoWalk [2*_agg .Index ];_ace =_agg .Height +TwoByTwoWalk [2*_agg .Index +1];if _ace < 1||_feg < 1{_agg .Index ++;continue ;};if len (_agg .CurrentNumbers )==0{_agg .CurrentNumbers ,_aac =_agg .Classer .TemplatesSize .GetSlice (uint64 (_feg )*uint64 (_ace ));
|
|
if !_aac {_agg .Index ++;continue ;};_agg .N =0;};_cbb =len (_agg .CurrentNumbers );for ;_agg .N < _cbb ;_agg .N ++{_edfg =_agg .CurrentNumbers [_agg .N ];_addg ,_cfeec =_agg .Classer .DilatedTemplates .GetBitmap (_edfg );if _cfeec !=nil {_de .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 _addg .Width -2*JbAddedPixels ==_feg &&_addg .Height -2*JbAddedPixels ==_ace {return _edfg ;};};_agg .Index ++;_agg .CurrentNumbers =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};
|