Mercurial > mercurial > hgweb_mover2.cgi
comparison include/marksheet.h @ 0:7bf900d47e9e
start mover2
| author | pyon@macmini |
|---|---|
| date | Sat, 15 Oct 2011 13:24:27 +0900 |
| parents | |
| children | b47bd4618c16 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:7bf900d47e9e |
|---|---|
| 1 // Filename : marksheet.h | |
| 2 // Last Change: 06-Oct-2011. | |
| 3 // | |
| 4 #ifndef __MARKSHEET__ | |
| 5 #define __MARKSHEET__ | |
| 6 | |
| 7 | |
| 8 #include "wx/utils.h" | |
| 9 #include "wx/file.h" | |
| 10 #include "wx/string.h" | |
| 11 #include "wx/image.h" | |
| 12 | |
| 13 bool IsBlack( int r, int g, int b ) | |
| 14 { | |
| 15 if ( r == 0 && g == 0 && b == 0 ) { | |
| 16 return true; | |
| 17 } | |
| 18 return false; | |
| 19 }; | |
| 20 | |
| 21 wxString GuessHhs( wxString& file ) | |
| 22 { | |
| 23 wxString hhs; | |
| 24 wxImage img( file, wxBITMAP_TYPE_JPEG ); | |
| 25 int sx = 1800; // start x | |
| 26 int sy = 315;; // start y | |
| 27 int bw = 60; // block width | |
| 28 int bh = 50; // block height | |
| 29 int area = bw * bh; | |
| 30 int black = 0; | |
| 31 int x, y; | |
| 32 unsigned char r, g, b; | |
| 33 | |
| 34 int max_n; | |
| 35 float max; | |
| 36 float bk; | |
| 37 for ( int c=0; c<10; c++ ) { | |
| 38 max = 0.0; | |
| 39 max_n = -1; | |
| 40 for ( int n=0; n<10; n++ ) { | |
| 41 | |
| 42 for ( x=sx+bw*c; x<sx+bw*(c+1); x++ ) { | |
| 43 for ( y=sy+bh*n; y<sy+bh*(n+1); y++ ) { | |
| 44 r = img.GetRed( x, y ); | |
| 45 g = img.GetGreen( x, y ); | |
| 46 b = img.GetBlue( x, y ); | |
| 47 if( IsBlack( (int)r, (int)g, (int)b ) ) black++; | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 bk = (float)black / area; | |
| 52 if ( max < bk ) { | |
| 53 max = bk; | |
| 54 max_n = n; | |
| 55 } | |
| 56 //wxPuts(wxString::Format(wxT("%d %f"),n,bk)); | |
| 57 black = 0; | |
| 58 } | |
| 59 hhs.Append( wxString::Format( wxT("%d"), max_n ) ); | |
| 60 } | |
| 61 | |
| 62 return hhs; | |
| 63 }; | |
| 64 | |
| 65 bool IsMarksheet( wxString& file ) | |
| 66 { | |
| 67 wxImage img( file, wxBITMAP_TYPE_JPEG ); | |
| 68 int black = 0; | |
| 69 int x = 2465; | |
| 70 int h = 3500; | |
| 71 unsigned char r, g, b; | |
| 72 | |
| 73 for ( int y=0; y<h; y++ ) { | |
| 74 r = img.GetRed( x, y ); | |
| 75 g = img.GetGreen( x, y ); | |
| 76 b = img.GetBlue( x, y ); | |
| 77 if( IsBlack( (int)r, (int)g, (int)b ) ) black++; | |
| 78 } | |
| 79 float z = (float)black / h; | |
| 80 float zmin = 0.095713; | |
| 81 float zmax = 0.108600; | |
| 82 | |
| 83 wxFile f( file ); | |
| 84 long l = f.Length(); | |
| 85 float lmin = 2072393; | |
| 86 float lmax = 2346082; | |
| 87 | |
| 88 //wxPuts(wxString::Format(wxT("z = %f, len = %d"),z,len)); | |
| 89 if ( zmin < z && z < zmax | |
| 90 && lmin < l && l < lmax ) { | |
| 91 return true; | |
| 92 } | |
| 93 return false; | |
| 94 }; | |
| 95 | |
| 96 #endif // __MARKSHEET__ | |
| 97 |
