תכנות וזיהוי/קובץ אופייני הפונקציות

מתוך ויקיספר, אוסף הספרים והמדריכים החופשי

הקובץ MyProcs.h[עריכה]

/*  ב"ה
תוכנה לזיהוי גראפי של אותיות
מאת הלל הלפרין
מאפשרת זיהוי אותיות
או סימנים אחרים
מתוך חלון ןידאו
מאפשרת גלילת מסך
לשם זיהוי עשרות אותיות
מאפשרת כתיבת אותיות
בשפות משונות
מאפשרת עיבוד תמונה
מאפשרת ויכוח עם
המחשב על הזיהוי הנכון
לומדת את שלוש התכונות הטובות ביותר
מתוך מאות תכונות
מאפשרת עיבוד הקבצים בעזרת הישומים
של מערכת ההפעלה כדוגמת
הצייר או מעבד התמלילים
או בעזרת מעבד תמלילים
שומרת את האות כמפת תמונת סיביות
סביבת העבודה
Winapi , Dev - cpp , Bitmaps , paint95.exe
אם אין לך צייר חלוני במחשב
מומלץ להוריד את התוכנית מהאתר
ftp://ftp.microsoft.com/softlib/mslfiles
כדי להבין את תפקידי משתני הפונקציות המיובאות
www.pinvoke.net
הקובץ הבא
MyProcs.h
מכיל קבועים
האופינים והסברים */
#include <Stdio.h>
/* מספר האוביקטים המכסימלי  */
#define ObjectsMax              38
/* בררת מחדל מספר האותיות בעברית */
#define HebrewLetters           22
/* מספר האפשרויות לנוע בין שתי משבצות
   שאינן על אותו קו
  657 :  על מסגרת של מלבן 8 על 8
   2588 :  16X16
X    1  2  3  4    5    6   7    8    9    10
f(X) 0  9  47 113  207  329 479  657  863  1097
X    11    12    13   14    15    16    17
f(X) 1359  1649  1967 2313  2687  2588  3529
X    18    19    20   21    22    23    24
f(X) 3999  4501  5035 5601  6199  6829  7491
*/
/* קבוצות סוגי התכונות  */
#define RecComps   2588
#define MaxComps   2
#define SumComps   8
#define AllComps   2598

/* מספר המופעים לכל עצם */
#define NumVariants             10
/*   0  , השונות המותרת בין הציונים של התכונה
  פירושו לא יותר מ - 1  */
#define MaxVariance             0
/* הפרש הציונים המשמעותי המינימלי */
#define MinDelta                2
/* מספר הספרות העשרוניות */
#define DeciDigits              10
/* סינון הצבע לשלושת מרכיביו  */
#define RedMask                 0x000000FF
#define GreenMask               0x0000FF00
#define BlueMask                0x00FF0000
/* לבדיקה אם נקודת הצבע קיימת בחלון  */
#define InMask                  0xFF000000
#define DuBites                 0xFF
#define QuBites                 0xFFFF
#define SeBites                 0xFFFFFF
/* מספר הפעמים שהעכבר דוגם  */
#define MaxPointsPerLetter      10000
#define MaxPointsPerArray       1000
/* לקבוע קנה מידה לדגימת אזור  */
#define ColsPerPic             16
#define RowsPerPic             16
#define fXSections             16.0
#define fYSections             16.0
/* דגום בשמונה גוונים
0  : שחור
7  : לבן  */
#define BrightLevels            8

/*  רוחב וגובה של תמונה מספיק גדולה לדגימה */
#define PicW  256
#define PicL  256
/* קבצים  */
/* כל שורה מופעים שונים של אות
   בתור מקור המידע של המחשב */
#define BmpRectsFile            "Rects.bmp"
/* תעודות הזהות של האותיות  */
#define ReportFile              "Report.txt"
/* תשובת החשב לשאלה לאיזה אוביקט הציור הכי דומה  */
#define OutFile                 "Out.txt"
/* שמירת תמונת האוביקט שצריך לזהות  */
#define SaveBMF                 "SaveBMP.bmp"
/* קובץ עזר לשמירת התמונה  */
#define BakeBMF                 "BakeBMP.bmp"
/* Rects.bmp תבנית מלבנים ממנה יוצרים את  */
#define BMapPlomba              "Mold.bmp"
/* קובץ העזרה */
#define TheHelp                 "helpme.bmp"
/* המיספר הסידורי של מרכיבי התכונות שניבחרו */
#define ElementsInSerial        "SortAtts.txt"
/* ויכוח בין המשתמש למחשב */
#define ArgueReport             "Argue.txt"
/* מספר האוביקטים */
#define MyConstants             "Consts.txt"

/* כלי כתיבה לציור האוביקט
אפשר להעתיק אחד מהספריה
.. \WINDOWS\CURSERS
ולשנות את שמו*/
#define ThePen                  "MyPen.cur"
/* קובץ המפעיל תוכנית שהופכת את
  הקבצים למצב קריאה כתיבה */
#define EnableRW                "rwfiles.bat"
/* כמה ורינטים לכל אוביקט שיניתי בזמן ריצה */
#define VarsAdd                 "VarsAdd.txt"
/* התמונה שתפסתי כמטריצת מספרים שלמים קטנים */
#define CatchMat  "CaMat.txt"
/* מספר השורות המגדירות עצם */
#define NumLinesPerObject       10
/* מספר השורות המגדירות תכונה - מפתח */
#define LinesPerKey             3
/* מספר המפתחות המגדירים אוביקט - עצם */
#define KeysPerObject           3
/* פונקצית הערך המוחלט
 c היוצרת את הערך
(a,b)  בעזרת זוג המספרים
: בצורה זו
 c = a - b אזי  a > b אם
 c = b - a אזי  a < b אם
 c = 0     אזי  a = b אם
  */
#define AbsDelta(a,b) (((a)<(b)) ? (b-a):(a-b))

/*  כמות המספרים המגדירים מרכיב תכונה */
#define ComponDefSet              4
/* צבע צהוב העוזר בציור מסגרת על רקע כהה */
#define MyYellow           3010000
/* XP לא מצליח בחלונות
 מתאים לחלונות 98
#define MyYellow 255000255*/

/* קבועים לשמירת קובץ מפת סיביות */
#define BytesPerColor           3
#define BytesPerDWORD           4
#define BM                      0x4d42
/* הקבוע הזה מתאים את רזולוצית התמונה
24 לרזולוציה נמוכה מספיק */
#define BitsPerRGBmode          24
/* מספר הביטים בשורת ההתחלה של קובץ מפת סיביות */
#define BitsPerBMPFileHeader    0x36
/* קבועים לגלילת מסך */
#define LongStepSize            25
#define ShortStepSize           1
#define ScrollBarWidth          14

/* כדי לבדוק את נכונות התוצאה
משתמשים במערך
אם קיבלנו אותה תוצאה בדיוק
אנו מניחים ב 90% שהתמונה מיצגת את האות
70% אם יש הבדל של יחידה אחת ההסתברות היא  */
#define FailArrayLength 100
static int ProbIfFail[FailArrayLength]=
                     {90,70,50,30,10,10,10,10,0,0,
                      0,0,0,0,0,0,0,0,0,0,
                      0,0,0,0,0,0,0,0,0,0,
                      0,0,0,0,0,0,0,0,0,0,
                      0,0,0,0,0,0,0,0,0,0,
                      0,0,0,0,0,0,0,0,0,0,
                      0,0,0,0,0,0,0,0,0,0,
                      0,0,0,0,0,0,0,0,0,0,
                      0,0,0,0,0,0,0,0,0,0,
                      0,0,0,0,0,0,0,0,0,0
                      };
/* Recs.bmp המערך בהמשך עוזר למצוא את המלבנים בתמונה
  :על פי השרטוט הזה
  |-----------------------------------
  |                        }14.0
  |    |-----|      |-----|
  |    |     |      |     |}33.5
  |    |     |      |     |
  |    |-----|      |-----|
  |<--> <---> <---->       }8.0
  |10.0  33.8  19.0
  |    |-----|      |-----|
  |    |     |      |     |
  |    |     |      |     |
  |    |-----|      |-----|
 */
static float DataRecs[]={10.0,14.0,33.8,33.5,19.0,8.0};
/* טיפוס בר מניה העוזר לקבוע מה המשתמש בחר */
typedef enum tagMyShow {Nothing,OnlyLetters,
         TheLimits,AComponent,ObjectsSerial,
         AFile,PasteImage,PasteScreen};
/* טיפוס נתונים הקובע אם התמונה נגללת או מוזזת */
typedef enum tagMyScroll {Moving,Scrolling,
         Stretching};
/* מבנה נתונים לתמונה המוזזת בתוך חלון
  (X,Y)  התמונה מוזזת ביחס לחלון על פי הקורדינטות
 */
typedef struct tagDragImage
{int X;
 int Y;
 int Width; /* רוחב התמונה */
 int Height; /* גובה */
 HBITMAP Image; /* מצביע לתמונה */
};
/* שמות פינות המלבן */
enum CupDefine{Point1,Point2,Point3,Point4};
/*צבעי  פינות המלבן */
typedef struct tag4Points{
     /*צבע לכל פינה*/
    int Color1,Color2,Color3,Color4;
    /*פינות נגדיות המגדירות את המלבן */
    int X1,Y1,X4,Y4 ;
    };
/* מסנן לקביעת  בהירות האות לעומת הרקע */
enum LineBrightness{AnyChange,AboveNum};



/* פונקציות בקבצי מקור מסוימים
שבכל קבצי המור מותר להשתמש בהם
כלומר שהם גלויים לכל התוכנה */
/* AtDialog.cpp */
void DrawFrameInD(HDC hdcM,
  int X1,int Y1,int X2,int Y2);
bool DidNotDrawInD(HWND MyHwnd);
bool IsDialogEmptyInD(int Dialog_Serial);

/* AtLearn.cpp */
void FollowMat();
void FollowAtt(int Attri,
   int MatIm[ColsPerPic][RowsPerPic]);
int AddCenterP (int MyCompi,
           int Mat[ColsPerPic][RowsPerPic]);
int AddMaxVecsInL(int MyCompi,
             int Mat[ColsPerPic][RowsPerPic]);
int AddSumVecsInL(int MyCompi,
             int Mat[ColsPerPic][RowsPerPic]);
int FindBarInL(POINT  Start, POINT  End ,
       int Mat[ColsPerPic][RowsPerPic]) ;
int MainInitInL(HDC hdc,int Objects_Num);
int GetCupAttsInL(
  int TempRects[RecComps][ComponDefSet]);

/* Conclude.cpp */
int MyPixelColorInC(HDC Myhdc, int ScreenLocateX,
                           int ScreenLocateY);
void NewLinesInC(FILE *TheFilePointer,
           int NumLines ,int Objects);
int CkeckNumKeysInC(int TheSign);
bool LoadArrayWithKeyInC(int TheSign,int Numkey,
      int Key3Line[][ObjectsMax]);
int PerformenceInC(HDC TheHdc,int X1,int Y1,
           int X2,int Y2,int Numb_Objects,
           LineBrightness FilterKind,int FilterNum);
void SelectPicInC(HDC hdcMe,
     float X1,float Y1,float X2,float Y2,
     int TheImage1[RowsPerPic][ColsPerPic],
     LineBrightness FilterType,int FilterN );
     

/* File.cpp */

HBITMAP LoadBMPFileInF(LPSTR pszFileName);
bool  IsFileNotExistInF(FILE *TheFile);
void Win2HBFileInF(HDC HDCSaved,
               long MyDeskWidth,
               long MyDeskHeight,
               LPSTR FileName);
int  GetNObjectsInF();
void UpdateNObFileInF(int N);
void EmptyFileInF(LPSTR pszFileName);
BOOL LoadFileInF(LPSTR pszFileName, HWND NextHwnd);
LPSTR GetBMPFileNAMEInF(HWND hwnd);
BOOL MainFileOpenInF(HWND hwnd,LPSTR TheFilter,
                  LPSTR TheExtension);
BOOL DoFileOpenInF(HWND hwnd);
void CatchAsMat(HWND TheWin,
    LineBrightness FilterType,int FilterN);
void ArgueAccountInF(HWND hwnd,int UserObject,
       int ComputerObject,int nObjects,
       LineBrightness FilterType,int FilterN);
BYTE* RGB2BMPBufferInF(BYTE* buffer,int width,
           int height, long* newsize);
bool SaveBMPfileInF(BYTE* Buffer, int width,
  int height, long paddedsize, char* bmpfile);
BYTE* SaveDC2BufferInF(HDC Myhdc,
  int ScreenLocateX,
  int ScreenLocateY,
  int Xlength, int Ylength);
char *SearchSInF(FILE *SearchF,
       const char * find );


/* GoSee.cpp       */
BYTE * ScreenRGBCapInG(HWND TheWin);
bool MakePgmInG(HWND TheWin);
void ListCharTextInG(HWND hwnd);
void MakeReferenceInG(HWND hwnd);
bool GoMainInG(HWND Ghwnd);

/* ImageOut.cpp */
int GetComputerObjectInI();
void ShowArgueRectInI(HDC Myhdc,int AnElement,
         int X1,int Y1,int X2,int Y2);
HBITMAP VisualArgumentInI(
   HWND TheWin,
   bool IsUserClaimed,
   int UserSerialNum,
   int TheElement);
char GetSerialInI(int TheN);
HBITMAP ShowSerialInI(HWND TheWin, int The_Elements);
void InvertColorInI(HWND hwnd);
HBITMAP AddVar2PicInI(HWND hwnd,
             int NumElements,
             int ObjectNumbe
              );
HBITMAP AddVarsLineInI(HWND hwnd,
             int NumElements,
             int ObjectNumbe 
              );              
HBITMAP CaptureOneWindowInI(HWND hwnd,HWND hwnd2);
HBITMAP MyStretchInI(HWND WinBase,HDC InHdc,
                 SIZE RateX,SIZE RateY  );
void ListCharTextInF(HWND hwnd);
                 
/* LoadRects.cpp */
void NeutralizeAndBltInL(int dx, int dy,
      HWND hWnd,
      tagDragImage *BmPre,
      tagDragImage *BmpS,
      int ToX, int ToY);
int BmHeightInL( HBITMAP hbm);
int BmWidthInL ( HBITMAP hbm);
void SynchronisedDCsInL(HDC FromA, HDC ToB);
int GetWinWidthInL (HWND hwnd);
int GetWinHeightInL(HWND hwnd);
void WhitenDCInL(HWND hwin, HBITMAP hbit, HDC TargetDC);
void DrawHBMPInL(HDC hdc, HBITMAP hbm,
              int Xstart, int Ystart);
void InitDragInfoInL ( HBITMAP hbm0,
                    tagDragImage *SBit);
void DoScrollInL( HWND hWnd, UINT message,
           WPARAM wParam, LPARAM lParam,
           int StepLength,
           tagMyScroll *ScrollWhat, bool Is_Reverse,
           tagDragImage *BmpS,
           tagDragImage *PrevBmpStruct);
void  InitCupAttsInL();

void DrawFrameRectInL(HDC hdcM,RECT Rc);
void DrawAimFrameInL (HDC hdcM,RECT Rect);
RECT PicLocationInL(int TheVariant,
                      int TheObject);
RECT VectLocationInL(int TheElem,RECT PicQuad);
HBITMAP MainPaintInL(HWND TheWin, int Component,
              tagMyShow * AShow,
              int NumElements);
HBITMAP CreateMoldInL(HWND hwnd,int NumElements);
HBITMAP LinesMoldInL(HWND hwnd);
HBITMAP EndLocateOnLinesInL(HWND hwnd);
void ApdateInL(HWND hwnd);