Mercurial > mercurial > hgweb_searcher03.cgi
annotate src/marksheet.cpp @ 12:52958cd4a073
Implement Force Mask button in Batch Print Mode.
| author | pyon@macmini |
|---|---|
| date | Sun, 18 May 2014 19:49:15 +0900 |
| parents | fdba695b99f1 |
| children |
| rev | line source |
|---|---|
| 2 | 1 // Filename : marksheet.cpp |
|
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
2 // Last Change: 13-May-2014. |
| 2 | 3 // |
| 4 | |
| 5 #include "common.h" | |
| 6 #include "marksheet.h" | |
| 7 | |
| 8 bool IsBlack( int r, int g, int b ) | |
| 9 { | |
| 10 if ( r == 0 && g == 0 && b == 0 ) { | |
| 11 return true; | |
| 12 } | |
| 13 return false; | |
| 14 } | |
| 15 | |
| 16 wxString GuessHhs( wxString& file ) | |
| 17 { | |
| 18 wxString hhs; | |
| 19 wxImage img( file, wxBITMAP_TYPE_JPEG ); | |
| 20 int sx = 1800; // start x | |
| 21 int sy = 315;; // start y | |
| 22 int bw = 60; // block width | |
| 23 int bh = 50; // block height | |
| 24 int area = bw * bh; | |
| 25 int black = 0; | |
| 26 int x, y; | |
| 27 unsigned char r, g, b; | |
| 28 | |
| 29 int max_n; | |
| 30 float max; | |
| 31 float bk; | |
| 32 for ( int c=0; c<10; c++ ) { | |
| 33 max = 0.0; | |
| 34 max_n = -1; | |
| 35 for ( int n=0; n<10; n++ ) { | |
| 36 | |
| 37 for ( x=sx+bw*c; x<sx+bw*(c+1); x++ ) { | |
| 38 for ( y=sy+bh*n; y<sy+bh*(n+1); y++ ) { | |
| 39 r = img.GetRed( x, y ); | |
| 40 g = img.GetGreen( x, y ); | |
| 41 b = img.GetBlue( x, y ); | |
| 42 if( IsBlack( (int)r, (int)g, (int)b ) ) black++; | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 bk = (float)black / area; | |
| 47 if ( max < bk ) { | |
| 48 max = bk; | |
| 49 max_n = n; | |
| 50 } | |
| 51 //wxPuts(wxString::Format(wxT("%d %f"),n,bk)); | |
| 52 black = 0; | |
| 53 } | |
| 54 hhs.Append( wxString::Format( wxT("%d"), max_n ) ); | |
| 55 } | |
| 56 | |
| 57 return hhs; | |
| 58 } | |
| 59 | |
| 4 | 60 bool IsMarksheet( wxString& file, double zmin, double zmax, long lmin, long lmax ) |
| 2 | 61 { |
|
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
62 float z; |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
63 long l; |
| 2 | 64 |
|
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
65 GetScore( &z, &l, file ); |
| 4 | 66 //wxPuts(wxString::Format(wxT("z = %f, len = %d"),z,l)); |
| 2 | 67 if ( zmin < z && z < zmax |
| 68 && lmin < l && l < lmax ) { | |
| 69 return true; | |
| 70 } | |
| 71 return false; | |
| 72 } | |
| 73 | |
|
12
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
74 void GetScore( float* z, long* l, wxString file ) |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
75 { |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
76 wxImage img( file, wxBITMAP_TYPE_JPEG ); |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
77 int black = 0; |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
78 int x = 2465; |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
79 int h = 3500; |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
80 unsigned char r, g, b; |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
81 |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
82 for ( int y = 0; y < h; y++ ) { |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
83 r = img.GetRed( x, y ); |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
84 g = img.GetGreen( x, y ); |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
85 b = img.GetBlue( x, y ); |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
86 if( IsBlack( (int)r, (int)g, (int)b ) ) black++; |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
87 } |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
88 *z = (float)black / h; |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
89 |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
90 wxFile f( file ); |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
91 *l = f.Length(); |
|
52958cd4a073
Implement Force Mask button in Batch Print Mode.
pyon@macmini
parents:
4
diff
changeset
|
92 } |
| 2 | 93 |
| 94 wxString GetHhsName( wxString& hhsno ) | |
| 95 { | |
| 96 wxString name; | |
| 97 | |
| 98 wxString gszFile = wxGetCwd() + wxFILE_SEP_PATH + wxT("db") + wxFILE_SEP_PATH + wxT("hhs.db"); | |
| 99 wxSQLite3Database hhsdb; | |
| 100 hhsdb.Open( gszFile ); | |
| 101 | |
| 102 wxSQLite3Statement stmt = hhsdb.PrepareStatement("SELECT name FROM hhs_master WHERE hhsno = ?"); | |
| 103 stmt.Bind( 1, hhsno ); | |
| 104 wxSQLite3ResultSet q = stmt.ExecuteQuery(); | |
| 105 if ( !q.IsNull(0) ) { | |
| 106 while ( q.NextRow() ) { | |
| 107 name = q.GetString(0); | |
| 108 } | |
| 109 } | |
| 110 stmt.Finalize(); | |
| 111 hhsdb.Close(); | |
| 112 | |
| 113 return name; | |
| 114 } | |
| 115 | |
| 116 int IsHhsno( wxString& hhsno, wxString& name ) | |
| 117 { | |
| 118 wxRegEx reHhs(wxT("^0[1238][0-9]{8}$")); // 被保番チェック | |
| 119 | |
| 120 if ( reHhs.Matches( hhsno) ) { | |
| 121 name = GetHhsName( hhsno ); | |
| 122 if ( name.IsEmpty() ) { // DBにない | |
| 123 return 1; | |
| 124 } | |
| 125 return 2; | |
| 126 } | |
| 127 else { | |
| 128 return 0; | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 int GetMarksheetVersion( wxString file ) | |
| 133 { | |
| 134 wxImage img( file, wxBITMAP_TYPE_JPEG ); | |
| 135 int black = 0; | |
| 136 int x = 2465; | |
| 137 int h = 3500; | |
| 138 unsigned char r, g, b; | |
| 139 | |
| 140 for ( int y=0; y<h; y++ ) { | |
| 141 r = img.GetRed( x, y ); | |
| 142 g = img.GetGreen( x, y ); | |
| 143 b = img.GetBlue( x, y ); | |
| 144 if( IsBlack( (int)r, (int)g, (int)b ) ) black++; | |
| 145 } | |
| 146 float z = (float)black / h; | |
| 147 | |
| 148 if ( z > 0.120 ) { | |
| 149 return 2; // 0.130 - 0.140 | |
| 150 } | |
| 151 else { | |
| 152 return 1; // 0.099 - 0.110 | |
| 153 } | |
| 154 } | |
| 155 |
