feats_test0.cc (ocrad-0.24) | : | feats_test0.cc (ocrad-0.25) | ||
---|---|---|---|---|
/* GNU Ocrad - Optical Character Recognition program | /* GNU Ocrad - Optical Character Recognition program | |||
Copyright (C) 2003-2014 Antonio Diaz Diaz. | Copyright (C) 2003-2015 Antonio Diaz Diaz. | |||
This program is free software: you can redistribute it and/or modify | This program is free software: you can redistribute it and/or modify | |||
it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | |||
the Free Software Foundation, either version 2 of the License, or | the Free Software Foundation, either version 2 of the License, or | |||
(at your option) any later version. | (at your option) any later version. | |||
This program is distributed in the hope that it will be useful, | This program is distributed in the hope that it will be useful, | |||
but WITHOUT ANY WARRANTY; without even the implied warranty of | but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
GNU General Public License for more details. | GNU General Public License for more details. | |||
skipping to change at line 104 | skipping to change at line 104 | |||
return '3'; | return '3'; | |||
} | } | |||
} | } | |||
else if( b.escape_right( urow2, ucol2 ) ) | else if( b.escape_right( urow2, ucol2 ) ) | |||
{ | { | |||
if( tbopen ) return ascode; | if( tbopen ) return ascode; | |||
if( rp[lrow1 + 1 - b.top()] >= lcol1 - b.left() && | if( rp[lrow1 + 1 - b.top()] >= lcol1 - b.left() && | |||
( lp[lrow2 + 1 - b.top()] < lcol2 - b.left() || | ( lp[lrow2 + 1 - b.top()] < lcol2 - b.left() || | |||
lp[urow3 - 1 - b.top()] < ucol3 - b.left() ) ) | lp[urow3 - 1 - b.top()] < ucol3 - b.left() ) ) | |||
{ | { | |||
for( int i = lp.pos( 40 ); i <= lp.pos( 70 ); ++i ) | ||||
if( 5 * lp[i] < b.width() && 2 * lp[i+1] > b.width() ) return '5'; | ||||
int c = 0, hdiff; | int c = 0, hdiff; | |||
if( !b.top_hook( &hdiff ) || 5 * hdiff >= 4 * b.height() ) ++c; | if( !b.top_hook( &hdiff ) || 5 * hdiff >= 4 * b.height() ) ++c; | |||
if( 2 * lp[lrow2 - b.top()] < lcol2 - b.left() ) ++c; | if( 2 * lp[lrow2 - b.top()] < lcol2 - b.left() ) ++c; | |||
if( !tp.isconvex() || ( !tp.ispit() && bp.ispit() ) ) ++c; | if( !tp.isconvex() || ( !tp.ispit() && bp.ispit() ) ) ++c; | |||
if( c >= 2 ) return '5'; | if( c >= 2 ) return '5'; | |||
} | } | |||
if( charset.enabled( Charset::iso_8859_15 ) || | if( charset.enabled( Charset::iso_8859_15 ) || | |||
charset.enabled( Charset::iso_8859_9 ) ) | charset.enabled( Charset::iso_8859_9 ) ) | |||
if( urow2 > b.vpos( 55 ) && | if( urow2 > b.vpos( 55 ) && | |||
b.seek_right( urow2 - 1, ucol2 ) < b.right() ) | b.seek_right( urow2 - 1, ucol2 ) < b.right() ) | |||
skipping to change at line 145 | skipping to change at line 147 | |||
else return UCS::SCCEDI; } | else return UCS::SCCEDI; } | |||
return 'F'; | return 'F'; | |||
} | } | |||
else if( lrow1 < urow2 && urow2 + 2 < lrow2 && lrow2 < urow3 && | else if( lrow1 < urow2 && urow2 + 2 < lrow2 && lrow2 < urow3 && | |||
urow2 <= b.vcenter() && lrow2 >= b.vcenter() ) return 'E'; | urow2 <= b.vcenter() && lrow2 >= b.vcenter() ) return 'E'; | |||
} | } | |||
} | } | |||
else if( b.escape_left( urow2, ucol2 ) ) | else if( b.escape_left( urow2, ucol2 ) ) | |||
{ | { | |||
if( !tbopen && ( 2 * lp[lp.pos(50)] ) + 2 >= b.width() && | if( !tbopen && ( 2 * lp[lp.pos(50)] ) + 2 >= b.width() && | |||
( tp.isconvex() || ( tp.ispit() && !bp.ispit() ) ) ) | ( tp.isconvex() || ( (tp.ispit() || tp.isrtip()) && !bp.ispit() ) ) ) | |||
return '2'; | return '2'; | |||
if( 2 * b.height() <= 5 * wp.max() && bp[bp.pos(75)] <= b.height() / 10 && | if( 2 * b.height() <= 5 * wp.max() && bp[bp.pos(75)] <= b.height() / 10 && | |||
Ocrad::similar( wp.max( 0, wp.pos(30) ), wp.max( wp.pos(70) ), 20 ) ) | Ocrad::similar( wp.max( 0, wp.pos(30) ), wp.max( wp.pos(70) ), 20 ) ) | |||
return 'z'; | return 'z'; | |||
} | } | |||
} | } | |||
return 0; | return 0; | |||
} | } | |||
int Features::test_EFIJLlT( const Charset & charset, const Rectangle & charbox ) const | int Features::test_EFIJLlT( const Charset & charset, const Rectangle & charbox ) const | |||
skipping to change at line 192 | skipping to change at line 194 | |||
const int topmax = b.top() + vnoise; | const int topmax = b.top() + vnoise; | |||
const int botmin = b.bottom() - vnoise; | const int botmin = b.bottom() - vnoise; | |||
if( vbars() == 1 && vbar(0).width() >= 2 && 2 * vbar(0).width() <= b.width() ) | if( vbars() == 1 && vbar(0).width() >= 2 && 2 * vbar(0).width() <= b.width() ) | |||
{ | { | |||
if( std::abs( vbar(0).hcenter() - b.hcenter() ) <= noise && | if( std::abs( vbar(0).hcenter() - b.hcenter() ) <= noise && | |||
std::abs( (vbar(0).left() - b.left()) - (b.right() - vbar(0).right()) ) <= 2 * noise ) | std::abs( (vbar(0).left() - b.left()) - (b.right() - vbar(0).right()) ) <= 2 * noise ) | |||
{ | { | |||
if( hbars() == 1 && 4 * hbar(0).height() <= b.height() ) | if( hbars() == 1 && 4 * hbar(0).height() <= b.height() ) | |||
{ | { | |||
if( ( hbar(0).top() <= topmax || hbar(0).bottom() < b.vpos( 15 ) ) && | if( ( hbar(0).top() <= topmax || hbar(0).bottom() < b.vpos( 15 ) ) && | |||
hbar(0).width() >= wp[wp.pos(75)] + wp[wp.pos(80)] ) | hbar(0).width() >= wp[wp.pos(75)] + wp[wp.pos(80)] && | |||
4 * lp[lp.pos(50)] >= b.width() ) | ||||
return 'T'; | return 'T'; | |||
if( std::abs( hbar(0).vcenter() - b.vcenter() ) <= vnoise && | if( std::abs( hbar(0).vcenter() - b.vcenter() ) <= vnoise && | |||
hbar(0).width() >= b.width() && | hbar(0).width() >= b.width() && | |||
Ocrad::similar( b.height(), b.width(), 50 ) ) return '+'; | Ocrad::similar( b.height(), b.width(), 50 ) ) return '+'; | |||
} | } | |||
if( hbars() == 2 && | if( hbars() == 2 && | |||
hbar(0).top() <= topmax && 4 * hbar(0).height() <= b.height() && | hbar(0).top() <= topmax && 4 * hbar(0).height() <= b.height() && | |||
hbar(1).bottom() >= botmin && 4 * hbar(1).height() <= b.height() && | hbar(1).bottom() >= botmin && 4 * hbar(1).height() <= b.height() && | |||
3 * hbar(0).width() > 4 * hbar(1).width() ) | 3 * hbar(0).width() > 4 * hbar(1).width() ) | |||
return 'T'; | return 'T'; | |||
} | } | |||
} | } | |||
if( vbars() == 1 && vbar(0).width() >= 2 && | if( vbars() == 1 && vbar(0).width() >= 2 ) | |||
2 * vbar(0).width() <= b.width() ) | ||||
{ | { | |||
if( vbar(0).right() <= b.hcenter() ) | if( 2 * vbar(0).width() <= b.width() && vbar(0).right() <= b.hcenter() ) | |||
{ | { | |||
if( ( hbars() == 2 || hbars() == 3 ) && hbar(0).top() <= topmax && | if( ( hbars() == 2 || hbars() == 3 ) && hbar(0).top() <= topmax && | |||
hbar(0).width() + 1 >= hbar(1).width() && | hbar(0).width() + 1 >= hbar(1).width() && | |||
2 * hbar(1).width() >= 3 * vbar(0).width() && | 2 * hbar(1).width() >= 3 * vbar(0).width() && | |||
vbar(0).h_overlaps( hbar(1) ) ) | vbar(0).h_overlaps( hbar(1) ) ) | |||
{ | { | |||
if( hbars() == 3 && | if( hbars() == 3 && | |||
Ocrad::similar( hbar(0).width(), hbar(2).width(), 10, 2 ) && | Ocrad::similar( hbar(0).width(), hbar(2).width(), 10, 2 ) && | |||
10 * hbar(2).width() >= 9 * hbar(1).width() && | 10 * hbar(2).width() >= 9 * hbar(1).width() && | |||
hbar(0).left() <= hbar(1).left() + 1 ) | hbar(0).left() <= hbar(1).left() + 1 ) | |||
skipping to change at line 246 | skipping to change at line 248 | |||
if( hbar(0).bottom() >= botmin && | if( hbar(0).bottom() >= botmin && | |||
b.escape_top( b.vcenter(), b.hpos( 75 ) ) ) | b.escape_top( b.vcenter(), b.hpos( 75 ) ) ) | |||
return 'L'; | return 'L'; | |||
if( hbar(0).top() <= topmax && 2 * wp[wp.pos(50)] >= b.width() && | if( hbar(0).top() <= topmax && 2 * wp[wp.pos(50)] >= b.width() && | |||
4 * wp[wp.pos(75)] < b.width() && | 4 * wp[wp.pos(75)] < b.width() && | |||
b.escape_right( b.vpos( 25 ), b.hcenter() ) ) | b.escape_right( b.vpos( 25 ), b.hcenter() ) ) | |||
return 'F'; | return 'F'; | |||
} | } | |||
} | } | |||
if( vbar(0).left() > b.hcenter() && hbars() == 1 ) | if( 3 * vbar(0).width() < 2 * b.width() && vbar(0).left() > b.hpos( 33 ) && | |||
hbars() == 1 ) | ||||
{ | { | |||
if( vbar(0).right() >= b.hpos( 90 ) && hbar(0).bottom() >= botmin && | if( vbar(0).right() >= b.hpos( 90 ) && hbar(0).bottom() >= botmin && | |||
Ocrad::similar( hbar(0).width(), b.width(), 10 ) && | hbar(0).left() == b.left() && | |||
b.bottom() > charbox.vpos( 90 ) && | b.bottom() > charbox.vpos( 90 ) && | |||
b.escape_top( b.vcenter(), b.hpos( 25 ) ) ) | b.escape_top( b.vcenter(), b.hpos( 25 ) ) ) | |||
{ if( b.height() > b.width() ) return 'J'; else return 0; } | { if( b.height() > b.width() ) return 'J'; else return 0; } | |||
if( hbar(0).top() <= topmax && hbar(0).width() + 1 >= b.width() ) | if( hbar(0).top() <= topmax && hbar(0).width() + 1 >= b.width() && | |||
b.width() > b.height() ) | ||||
{ | { | |||
if( charset.enabled( Charset::iso_8859_15 ) || | if( charset.enabled( Charset::iso_8859_15 ) || | |||
charset.enabled( Charset::iso_8859_9 ) ) | charset.enabled( Charset::iso_8859_9 ) ) return UCS::NOT; | |||
if( b.width() > b.height() ) return UCS::NOT; | ||||
return 0; | return 0; | |||
} | } | |||
} | } | |||
} | } | |||
if( vbars() == 1 && vbar(0).width() >= 2 && | if( vbars() == 1 && vbar(0).width() >= 2 && | |||
tp.minima() == 1 && bp.minima() == 1 ) | tp.minima() == 1 && bp.minima() == 1 ) | |||
{ | { | |||
if( 3 * b.height() > 4 * b.width() && | if( 3 * b.height() > 4 * b.width() && | |||
Ocrad::similar( vbar(0).left() - b.left(), | Ocrad::similar( vbar(0).left() - b.left(), | |||
skipping to change at line 415 | skipping to change at line 418 | |||
{ | { | |||
if( lp.isconvex() && ( col > b.hpos( 60 ) || row < b.bottom() ) ) | if( lp.isconvex() && ( col > b.hpos( 60 ) || row < b.bottom() ) ) | |||
return 0; | return 0; | |||
if( ( hbars() == 1 || | if( ( hbars() == 1 || | |||
( hbars() == 2 && hbar(1).bottom() >= b.bottom() - 1 && | ( hbars() == 2 && hbar(1).bottom() >= b.bottom() - 1 && | |||
2 * hbar(0).width() > 3 * hbar(1).width() ) ) && | 2 * hbar(0).width() > 3 * hbar(1).width() ) ) && | |||
hbar(0).top() <= b.top() + 1 && | hbar(0).top() <= b.top() + 1 && | |||
4 * hbar(0).height() <= b.height() && | 4 * hbar(0).height() <= b.height() && | |||
4 * lp[lp.pos(50)] >= b.width() ) | 4 * lp[lp.pos(50)] >= b.width() ) | |||
return 'T'; | return 'T'; | |||
return 'r'; | if( 3 * rp[rp.pos(50)] > b.width() ) return 'r'; | |||
return 0; | ||||
} | } | |||
} | } | |||
} | } | |||
if( Ocrad::similar( b.height(), b.width(), 40 ) && | if( Ocrad::similar( b.height(), b.width(), 40 ) && | |||
segments_in_row( b.vpos( 15 ) ) == 3 && | segments_in_row( b.vpos( 15 ) ) == 3 && | |||
segments_in_row( b.vpos( 85 ) ) == 3 && | segments_in_row( b.vpos( 85 ) ) == 3 && | |||
b.seek_right( row - 1, col ) < b.right() && lp.isctip() ) | b.seek_right( row - 1, col ) < b.right() && lp.isctip() ) | |||
return 'x'; | return 'x'; | |||
} | } | |||
if( 3 * b.height() > 4 * b.width() && vbar(0).left() > b.left() && | if( 3 * b.height() > 4 * b.width() && vbar(0).left() > b.left() && | |||
skipping to change at line 585 | skipping to change at line 589 | |||
const int rg = rp[rp.pos(50)]; | const int rg = rp[rp.pos(50)]; | |||
if( Ocrad::similar( lg, rg, 80, 2 ) && | if( Ocrad::similar( lg, rg, 80, 2 ) && | |||
4 * lg < b.width() && 4 * rg < b.width() ) | 4 * lg < b.width() && 4 * rg < b.width() ) | |||
{ | { | |||
if( lg > 1 && rg > 1 && lp.increasing() && rp.increasing() && | if( lg > 1 && rg > 1 && lp.increasing() && rp.increasing() && | |||
5 * tp[tp.pos(50)] > b.height() ) | 5 * tp[tp.pos(50)] > b.height() ) | |||
return 'w'; | return 'w'; | |||
if( hbars() == 1 && 5 * ( hbar(0).height() - 1 ) < b.height() && | if( hbars() == 1 && 5 * ( hbar(0).height() - 1 ) < b.height() && | |||
hbar(0).top() >= b.vpos( 30 ) && hbar(0).bottom() <= b.vpos( 60 ) && | hbar(0).top() >= b.vpos( 30 ) && hbar(0).bottom() <= b.vpos( 60 ) && | |||
10 * hbar(0).width() > 9 * wp[hbar(0).vcenter()-b.top()] && | 10 * hbar(0).width() > 9 * wp[hbar(0).vcenter()-b.top()] && | |||
Ocrad::similar( col_segment( hbar(0).vcenter(), hbar(0).hcenter() ). size(), | Ocrad::similar( v_segment( hbar(0).vcenter(), hbar(0).hcenter() ).si ze(), | |||
hbar(0).height(), 30, 2 ) ) | hbar(0).height(), 30, 2 ) ) | |||
{ | { | |||
if( 9 * hbar(0).width() <= 10 * wp[wp.pos(50)] ) return 'H'; | if( 9 * hbar(0).width() <= 10 * wp[wp.pos(50)] ) return 'H'; | |||
return 0; | return 0; | |||
} | } | |||
if( segments_in_row( b.vpos( 60 ) ) == 4 || | if( segments_in_row( b.vpos( 60 ) ) == 4 || | |||
segments_in_row( b.vpos( 70 ) ) == 4 ) | segments_in_row( b.vpos( 70 ) ) == 4 ) | |||
{ | { | |||
if( 2 * tp[tp.pos(50)] > b.height() ) return 'M'; | if( 2 * tp[tp.pos(50)] > b.height() ) return 'M'; | |||
return 'w'; | return 'w'; | |||
End of changes. 12 change blocks. | ||||
13 lines changed or deleted | 17 lines changed or added |