⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tstruct.cpp

📁 一OCR的相关资料。.希望对研究OCR的朋友有所帮助.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                         LIST list,                 //list from tess                         BLOB_CHOICE_LIST &ratings  //list of results                        ) {  LIST result;                   //tess output  BLOB_CHOICE_IT it = &ratings;  //iterator  BLOB_CHOICE *choice;           //created choice  A_CHOICE *tesschoice;          //choice to convert  for (result = list; result != NULL; result = result->next) {  //traverse list    tesschoice = (A_CHOICE *) result->node;                                 //make one    choice = new BLOB_CHOICE (tesschoice->string[0], tesschoice->rating, tesschoice->certainty, tesschoice->config);    it.add_after_then_move (choice);  }  destroy_nodes (list, (void (*)(void *)) free_choice);  //get rid of it}/********************************************************************** * make_tess_row * * Make a fake row structure to pass to the tesseract matchers. **********************************************************************/void make_tess_row(                  //make fake row                   DENORM *denorm,   //row info                   TEXTROW *tessrow  //output row                  ) {  tessrow->baseline.segments = 1;  tessrow->baseline.xstarts[0] = -32767;  tessrow->baseline.xstarts[1] = 32767;  tessrow->baseline.quads[0].a = 0;  tessrow->baseline.quads[0].b = 0;  tessrow->baseline.quads[0].c = bln_baseline_offset;  tessrow->xheight.segments = 1;  tessrow->xheight.xstarts[0] = -32767;  tessrow->xheight.xstarts[1] = 32767;  tessrow->xheight.quads[0].a = 0;  tessrow->xheight.quads[0].b = 0;  tessrow->xheight.quads[0].c = bln_x_height + bln_baseline_offset;  tessrow->lineheight = bln_x_height;  tessrow->ascrise = denorm->row ()->ascenders () * denorm->scale ();  tessrow->descdrop = denorm->row ()->descenders () * denorm->scale ();}/********************************************************************** * make_tess_word * * Convert the word to Tess format. **********************************************************************/TWERD *make_tess_word(              //convert owrd                      WERD *word,   //word to do                      TEXTROW *row  //fake row                     ) {  TWERD *tessword;               //tess format  tessword = newword ();         //use old allocator  tessword->row = row;           //give them something                                 //copy string  tessword->correct = strsave (word->text ());  tessword->guess = NULL;  tessword->blobs = make_tess_blobs (word->blob_list ());  tessword->blanks = 1;  tessword->blobcount = word->blob_list ()->length ();  tessword->next = NULL;  return tessword;}/********************************************************************** * make_tess_blobs * * Make Tess style blobs from a list of BLOBs. **********************************************************************/TBLOB *make_tess_blobs(                      //make tess blobs                       PBLOB_LIST *bloblist  //list to convert                      ) {  PBLOB_IT it = bloblist;        //iterator  PBLOB *blob;                   //current blob  TBLOB *head;                   //output list  TBLOB *tail;                   //end of list  TBLOB *tessblob;  head = NULL;  tail = NULL;  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {    blob = it.data ();    tessblob = make_tess_blob (blob, TRUE);    if (head)      tail->next = tessblob;    else      head = tessblob;    tail = tessblob;  }  return head;}/********************************************************************** * make_tess_blob * * Make a single Tess style blob **********************************************************************/TBLOB *make_tess_blob(               //make tess blob                      PBLOB *blob,   //blob to convert                      BOOL8 flatten  //flatten outline structure                     ) {  INT32 index;  TBLOB *tessblob;  tessblob = newblob ();  tessblob->outlines = (struct olinestruct *)    make_tess_outlines (blob->out_list (), flatten);  for (index = 0; index < TBLOBFLAGS; index++)    tessblob->flags[index] = 0;  //!!  tessblob->correct = 0;  tessblob->guess = 0;  for (index = 0; index < MAX_WO_CLASSES; index++) {    tessblob->classes[index] = 0;    tessblob->values[index] = 0;  }  tessblob->next = NULL;  return tessblob;}/********************************************************************** * make_tess_outlines * * Make Tess style outlines from a list of OUTLINEs. **********************************************************************/TESSLINE *make_tess_outlines(                            //make tess outlines                             OUTLINE_LIST *outlinelist,  //list to convert                             BOOL8 flatten               //flatten outline structure                            ) {  OUTLINE_IT it = outlinelist;   //iterator  OUTLINE *outline;              //current outline  TESSLINE *head;                //output list  TESSLINE *tail;                //end of list  TESSLINE *tessoutline;  head = NULL;  tail = NULL;  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {    outline = it.data ();    tessoutline = newoutline ();    tessoutline->compactloop = NULL;    tessoutline->loop = make_tess_edgepts (outline->polypts (),      tessoutline->topleft,      tessoutline->botright);    if (tessoutline->loop == NULL) {      oldoutline(tessoutline);      continue;    }    tessoutline->start = tessoutline->loop->pos;    tessoutline->node = NULL;    tessoutline->next = NULL;    tessoutline->child = NULL;    if (!outline->child ()->empty ()) {      if (flatten)        tessoutline->next = (struct olinestruct *)          make_tess_outlines (outline->child (), flatten);      else {        tessoutline->next = NULL;        tessoutline->child = (struct olinestruct *)          make_tess_outlines (outline->child (), flatten);      }    }    else      tessoutline->next = NULL;    if (head)      tail->next = tessoutline;    else      head = tessoutline;    while (tessoutline->next != NULL)      tessoutline = tessoutline->next;    tail = tessoutline;  }  return head;}/********************************************************************** * make_tess_edgepts * * Make Tess style edgepts from a list of POLYPTs. **********************************************************************/EDGEPT *make_tess_edgepts(                          //make tess edgepts                          POLYPT_LIST *edgeptlist,  //list to convert                          TPOINT &tl,               //bounding box                          TPOINT &br) {  INT32 index;  POLYPT_IT it = edgeptlist;     //iterator  POLYPT *edgept;                //current edgept  EDGEPT *head;                  //output list  EDGEPT *tail;                  //end of list  EDGEPT *tessedgept;  head = NULL;  tail = NULL;  tl.x = MAX_INT16;  tl.y = -MAX_INT16;  br.x = -MAX_INT16;  br.y = MAX_INT16;  for (it.mark_cycle_pt (); !it.cycled_list ();) {    edgept = it.data ();    tessedgept = newedgept ();    tessedgept->pos.x = (INT16) edgept->pos.x ();    tessedgept->pos.y = (INT16) edgept->pos.y ();    if (tessedgept->pos.x < tl.x)      tl.x = tessedgept->pos.x;    if (tessedgept->pos.x > br.x)      br.x = tessedgept->pos.x;    if (tessedgept->pos.y > tl.y)      tl.y = tessedgept->pos.y;    if (tessedgept->pos.y < br.y)      br.y = tessedgept->pos.y;    if (head != NULL && tessedgept->pos.x == tail->pos.x    && tessedgept->pos.y == tail->pos.y) {      oldedgept(tessedgept);    }    else {      for (index = 0; index < EDGEPTFLAGS; index++)        tessedgept->flags[index] = 0;      if (head != NULL) {        tail->vec.x = tessedgept->pos.x - tail->pos.x;        tail->vec.y = tessedgept->pos.y - tail->pos.y;        tessedgept->prev = tail;      }      tessedgept->next = head;      if (head)        tail->next = tessedgept;      else        head = tessedgept;      tail = tessedgept;    }    it.forward ();  }  head->prev = tail;  tail->vec.x = head->pos.x - tail->pos.x;  tail->vec.y = head->pos.y - tail->pos.y;  if (head == tail) {    oldedgept(head);    return NULL;                 //empty  }  return head;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -