Mercurial > mercurial > hgweb_searcher03.cgi
view src/marksheet.cpp @ 22:92188f60323d default tip
Implement Masking function on Preview Dialog.
author | pyon@macmini |
---|---|
date | Sat, 04 Apr 2015 17:23:46 +0900 |
parents | 52958cd4a073 |
children |
line wrap: on
line source
// Filename : marksheet.cpp // Last Change: 13-May-2014. // #include "common.h" #include "marksheet.h" bool IsBlack( int r, int g, int b ) { if ( r == 0 && g == 0 && b == 0 ) { return true; } return false; } wxString GuessHhs( wxString& file ) { wxString hhs; wxImage img( file, wxBITMAP_TYPE_JPEG ); int sx = 1800; // start x int sy = 315;; // start y int bw = 60; // block width int bh = 50; // block height int area = bw * bh; int black = 0; int x, y; unsigned char r, g, b; int max_n; float max; float bk; for ( int c=0; c<10; c++ ) { max = 0.0; max_n = -1; for ( int n=0; n<10; n++ ) { for ( x=sx+bw*c; x<sx+bw*(c+1); x++ ) { for ( y=sy+bh*n; y<sy+bh*(n+1); y++ ) { r = img.GetRed( x, y ); g = img.GetGreen( x, y ); b = img.GetBlue( x, y ); if( IsBlack( (int)r, (int)g, (int)b ) ) black++; } } bk = (float)black / area; if ( max < bk ) { max = bk; max_n = n; } //wxPuts(wxString::Format(wxT("%d %f"),n,bk)); black = 0; } hhs.Append( wxString::Format( wxT("%d"), max_n ) ); } return hhs; } bool IsMarksheet( wxString& file, double zmin, double zmax, long lmin, long lmax ) { float z; long l; GetScore( &z, &l, file ); //wxPuts(wxString::Format(wxT("z = %f, len = %d"),z,l)); if ( zmin < z && z < zmax && lmin < l && l < lmax ) { return true; } return false; } void GetScore( float* z, long* l, wxString file ) { wxImage img( file, wxBITMAP_TYPE_JPEG ); int black = 0; int x = 2465; int h = 3500; unsigned char r, g, b; for ( int y = 0; y < h; y++ ) { r = img.GetRed( x, y ); g = img.GetGreen( x, y ); b = img.GetBlue( x, y ); if( IsBlack( (int)r, (int)g, (int)b ) ) black++; } *z = (float)black / h; wxFile f( file ); *l = f.Length(); } wxString GetHhsName( wxString& hhsno ) { wxString name; wxString gszFile = wxGetCwd() + wxFILE_SEP_PATH + wxT("db") + wxFILE_SEP_PATH + wxT("hhs.db"); wxSQLite3Database hhsdb; hhsdb.Open( gszFile ); wxSQLite3Statement stmt = hhsdb.PrepareStatement("SELECT name FROM hhs_master WHERE hhsno = ?"); stmt.Bind( 1, hhsno ); wxSQLite3ResultSet q = stmt.ExecuteQuery(); if ( !q.IsNull(0) ) { while ( q.NextRow() ) { name = q.GetString(0); } } stmt.Finalize(); hhsdb.Close(); return name; } int IsHhsno( wxString& hhsno, wxString& name ) { wxRegEx reHhs(wxT("^0[1238][0-9]{8}$")); // 被保番チェック if ( reHhs.Matches( hhsno) ) { name = GetHhsName( hhsno ); if ( name.IsEmpty() ) { // DBにない return 1; } return 2; } else { return 0; } } int GetMarksheetVersion( wxString file ) { wxImage img( file, wxBITMAP_TYPE_JPEG ); int black = 0; int x = 2465; int h = 3500; unsigned char r, g, b; for ( int y=0; y<h; y++ ) { r = img.GetRed( x, y ); g = img.GetGreen( x, y ); b = img.GetBlue( x, y ); if( IsBlack( (int)r, (int)g, (int)b ) ) black++; } float z = (float)black / h; if ( z > 0.120 ) { return 2; // 0.130 - 0.140 } else { return 1; // 0.099 - 0.110 } }