ccmain/tstruct.h File Reference

#include "tessarray.h"
#include "werd.h"
#include "tessclas.h"
#include "ratngs.h"
#include "notdll.h"
#include "oldlist.h"

Go to the source code of this file.

Classes

Functions

Variables


Function Documentation

void convert_choice_list ( LIST  list,
BLOB_CHOICE_LIST &  ratings 
)

Convert the LIST of TESS_CHOICEs into a BLOB_CHOICE_LIST.

Definition at line 236 of file tstruct.cpp.

References choicestruct::certainty, choicestruct::config, destroy_nodes(), free_choice(), list_rec::next, list_rec::node, NULL, choicestruct::rating, and choicestruct::string.

Referenced by call_tester(), call_train_tester(), convert_choice_lists(), tess_bn_matcher(), tess_cn_matcher(), and tess_default_matcher().

00239                           {
00240   LIST result;                   //tess output
00241   BLOB_CHOICE_IT it = &ratings;  //iterator
00242   BLOB_CHOICE *choice;           //created choice
00243   A_CHOICE *tesschoice;          //choice to convert
00244 
00245   for (result = list; result != NULL; result = result->next) {
00246   //traverse list
00247     tesschoice = (A_CHOICE *) result->node;
00248                                  //make one
00249     choice = new BLOB_CHOICE (tesschoice->string[0], tesschoice->rating,
00250       tesschoice->certainty, tesschoice->config);
00251     it.add_after_then_move (choice);
00252   }
00253   destroy_nodes (list, (void (*)(void *)) free_choice);
00254   //get rid of it
00255 }

void convert_choice_lists ( ARRAY  tessarray,
BLOB_CHOICE_LIST_CLIST *  ratings 
)

Convert the ARRAY of TESS_LIST of TESS_CHOICEs into a BLOB_CHOICE_LIST.

Definition at line 206 of file tstruct.cpp.

References array_count, array_value, convert_choice_list(), free_mem(), and NULL.

Referenced by recog_word_recursive().

00209                            {
00210   INT32 length;                  //elements in array
00211   INT32 index;                   //index to array
00212   LIST result;                   //tess output
00213                                  //iterator
00214   BLOB_CHOICE_LIST_C_IT it = ratings;
00215   BLOB_CHOICE_LIST *choice;      //created choice
00216 
00217   if (tessarray != NULL) {
00218     length = array_count (tessarray);
00219     for (index = 0; index < length; index++) {
00220       result = (LIST) array_value (tessarray, index);
00221                                  //make one
00222       choice = new BLOB_CHOICE_LIST;
00223                                  //convert blob choices
00224       convert_choice_list(result, *choice);
00225                                  //add to super list
00226       it.add_after_then_move (choice);
00227     }
00228     free_mem(tessarray);  //lists already freed
00229   }
00230 }

ELISTIZEH ( FRAGMENT   ) 

PBLOB* make_ed_blob ( TBLOB tessblob  ) 

Make an editor format blob from the tess style blob.

Definition at line 71 of file tstruct.cpp.

References make_ed_outline(), olinestruct::next, NULL, blobstruct::outlines, and register_outline().

Referenced by call_matcher(), call_tester(), call_train_tester(), and make_ed_word().

00073                      {
00074   TESSLINE *tessol;              //tess outline
00075   FRAGMENT_LIST fragments;       //list of fragments
00076   OUTLINE *outline;              //current outline
00077   OUTLINE_LIST out_list;         //list of outlines
00078   OUTLINE_IT out_it = &out_list; //iterator
00079 
00080   for (tessol = tessblob->outlines; tessol != NULL; tessol = tessol->next) {
00081                                  //stick in list
00082     register_outline(tessol, &fragments);
00083   }
00084   while (!fragments.empty ()) {
00085     outline = make_ed_outline (&fragments);
00086     if (outline != NULL)
00087       out_it.add_after_then_move (outline);
00088   }
00089   if (out_it.empty())
00090     return NULL;                 //couldn't do it
00091   return new PBLOB (&out_list);  //turn to blob
00092 }

OUTLINE* make_ed_outline ( FRAGMENT_LIST *  list  ) 

Make an editor format outline from the list of fragments.

Definition at line 98 of file tstruct.cpp.

References FRAGMENT::headpt, edgeptstruct::next, NULL, edgeptstruct::pos, FRAGMENT::tailpt, edgeptstruct::vec, TPOINT::x, and TPOINT::y.

Referenced by make_ed_blob().

00100                           {
00101   FRAGMENT *fragment;            //current fragment
00102   EDGEPT *edgept;                //current point
00103   ICOORD headpos;                //coords of head
00104   ICOORD tailpos;                //coords of tail
00105   FCOORD pos;                    //coords of edgept
00106   FCOORD vec;                    //empty
00107   POLYPT *polypt;                //current point
00108   POLYPT_LIST poly_list;         //list of point
00109   POLYPT_IT poly_it = &poly_list;//iterator
00110   FRAGMENT_IT fragment_it = list;//fragment
00111 
00112   headpos = fragment_it.data ()->head;
00113   do {
00114     fragment = fragment_it.data ();
00115     edgept = fragment->headpt;   //start of segment
00116     do {
00117       pos = FCOORD (edgept->pos.x, edgept->pos.y);
00118       vec = FCOORD (edgept->vec.x, edgept->vec.y);
00119       polypt = new POLYPT (pos, vec);
00120                                  //add to list
00121       poly_it.add_after_then_move (polypt);
00122       edgept = edgept->next;
00123     }
00124     while (edgept != fragment->tailpt);
00125     tailpos = ICOORD (edgept->pos.x, edgept->pos.y);
00126                                  //get rid of it
00127     delete fragment_it.extract ();
00128     if (tailpos != headpos) {
00129       if (fragment_it.empty ()) {
00130         //  tprintf("Bad tailpos (%d,%d), Head=(%d,%d), no fragments.\n",
00131         //            fragment->head.x(),fragment->head.y(),
00132         //            headpos.x(),headpos.y());
00133         return NULL;
00134       }
00135       fragment_it.forward ();
00136                                  //find next segment
00137       for (fragment_it.mark_cycle_pt (); !fragment_it.cycled_list () && fragment_it.data ()->head != tailpos;
00138         fragment_it.forward ());
00139       if (fragment_it.data ()->head != tailpos) {
00140         //                              tprintf("Bad tailpos (%d,%d), Fragments are:\n",
00141         //                                      tailpos.x(),tailpos.y());
00142         for (fragment_it.mark_cycle_pt ();
00143         !fragment_it.cycled_list (); fragment_it.forward ()) {
00144           fragment = fragment_it.extract ();
00145           //  tprintf("Head=(%d,%d), tail=(%d,%d)\n",
00146           //  fragment->head.x(),fragment->head.y(),
00147           //  fragment->tail.x(),fragment->tail.y());
00148           delete fragment;
00149         }
00150         return NULL;             //can't do it
00151         //   BADFRAGMENTS.error("make_ed_blob",ABORT,NULL);
00152       }
00153     }
00154   }
00155   while (tailpos != headpos);
00156   return new OUTLINE (&poly_it); //turn to outline
00157 }

TBLOB* make_tess_blob ( PBLOB blob,
BOOL8  flatten 
)

Make a single Tess style blob.

!

Definition at line 335 of file tstruct.cpp.

References blobstruct::classes, blobstruct::correct, blobstruct::flags, blobstruct::guess, make_tess_outlines(), MAX_WO_CLASSES, newblob(), blobstruct::next, NULL, PBLOB::out_list(), blobstruct::outlines, TBLOBFLAGS, and blobstruct::values.

Referenced by compare_bln_blobs(), make_tess_blobs(), tess_bn_matcher(), tess_cn_matcher(), tess_default_matcher(), and tess_training_tester().

00338                        {
00339   INT32 index;
00340   TBLOB *tessblob;
00341 
00342   tessblob = newblob ();
00343   tessblob->outlines = (struct olinestruct *)
00344     make_tess_outlines (blob->out_list (), flatten);
00345   for (index = 0; index < TBLOBFLAGS; index++)
00346     tessblob->flags[index] = 0;  
00347   tessblob->correct = 0;
00348   tessblob->guess = 0;
00349   for (index = 0; index < MAX_WO_CLASSES; index++) {
00350     tessblob->classes[index] = 0;
00351     tessblob->values[index] = 0;
00352   }
00353   tessblob->next = NULL;
00354   return tessblob;
00355 }

TBLOB* make_tess_blobs ( PBLOB_LIST *  bloblist  ) 

Make Tess style blobs from a list of BLOBs.

Definition at line 308 of file tstruct.cpp.

References make_tess_blob(), blobstruct::next, NULL, and TRUE.

Referenced by make_tess_word().

00310                         {
00311   PBLOB_IT it = bloblist;        //iterator
00312   PBLOB *blob;                   //current blob
00313   TBLOB *head;                   //output list
00314   TBLOB *tail;                   //end of list
00315   TBLOB *tessblob;
00316 
00317   head = NULL;
00318   tail = NULL;
00319   for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00320     blob = it.data ();
00321     tessblob = make_tess_blob (blob, TRUE);
00322     if (head)
00323       tail->next = tessblob;
00324     else
00325       head = tessblob;
00326     tail = tessblob;
00327   }
00328   return head;
00329 }

EDGEPT* make_tess_edgepts ( POLYPT_LIST *  edgeptlist,
TPOINT tl,
TPOINT br 
)

Make Tess style edgepts from a list of POLYPTs.

Definition at line 415 of file tstruct.cpp.

References EDGEPTFLAGS, edgeptstruct::flags, MAX_INT16, newedgept(), edgeptstruct::next, NULL, oldedgept(), edgeptstruct::pos, edgeptstruct::prev, edgeptstruct::vec, TPOINT::x, and TPOINT::y.

Referenced by make_tess_outlines().

00418                                       {
00419   INT32 index;
00420   POLYPT_IT it = edgeptlist;     //iterator
00421   POLYPT *edgept;                //current edgept
00422   EDGEPT *head;                  //output list
00423   EDGEPT *tail;                  //end of list
00424   EDGEPT *tessedgept;
00425 
00426   head = NULL;
00427   tail = NULL;
00428   tl.x = MAX_INT16;
00429   tl.y = -MAX_INT16;
00430   br.x = -MAX_INT16;
00431   br.y = MAX_INT16;
00432   for (it.mark_cycle_pt (); !it.cycled_list ();) {
00433     edgept = it.data ();
00434     tessedgept = newedgept ();
00435     tessedgept->pos.x = (INT16) edgept->pos.x ();
00436     tessedgept->pos.y = (INT16) edgept->pos.y ();
00437     if (tessedgept->pos.x < tl.x)
00438       tl.x = tessedgept->pos.x;
00439     if (tessedgept->pos.x > br.x)
00440       br.x = tessedgept->pos.x;
00441     if (tessedgept->pos.y > tl.y)
00442       tl.y = tessedgept->pos.y;
00443     if (tessedgept->pos.y < br.y)
00444       br.y = tessedgept->pos.y;
00445     if (head != NULL && tessedgept->pos.x == tail->pos.x
00446     && tessedgept->pos.y == tail->pos.y) {
00447       oldedgept(tessedgept);
00448     }
00449     else {
00450       for (index = 0; index < EDGEPTFLAGS; index++)
00451         tessedgept->flags[index] = 0;
00452       if (head != NULL) {
00453         tail->vec.x = tessedgept->pos.x - tail->pos.x;
00454         tail->vec.y = tessedgept->pos.y - tail->pos.y;
00455         tessedgept->prev = tail;
00456       }
00457       tessedgept->next = head;
00458       if (head)
00459         tail->next = tessedgept;
00460       else
00461         head = tessedgept;
00462       tail = tessedgept;
00463     }
00464     it.forward ();
00465   }
00466   head->prev = tail;
00467   tail->vec.x = head->pos.x - tail->pos.x;
00468   tail->vec.y = head->pos.y - tail->pos.y;
00469   if (head == tail) {
00470     oldedgept(head);
00471     return NULL;                 //empty
00472   }
00473   return head;
00474 }

TESSLINE* make_tess_outlines ( OUTLINE_LIST *  outlinelist,
BOOL8  flatten 
)

Make Tess style outlines from a list of OUTLINEs.

Definition at line 361 of file tstruct.cpp.

References olinestruct::botright, olinestruct::child, olinestruct::compactloop, olinestruct::loop, make_tess_edgepts(), make_tess_outlines(), newoutline(), olinestruct::next, olinestruct::node, NULL, oldoutline, edgeptstruct::pos, olinestruct::start, and olinestruct::topleft.

Referenced by make_tess_blob(), and make_tess_outlines().

00364                               {
00365   OUTLINE_IT it = outlinelist;   //iterator
00366   OUTLINE *outline;              //current outline
00367   TESSLINE *head;                //output list
00368   TESSLINE *tail;                //end of list
00369   TESSLINE *tessoutline;
00370 
00371   head = NULL;
00372   tail = NULL;
00373   for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00374     outline = it.data ();
00375     tessoutline = newoutline ();
00376     tessoutline->compactloop = NULL;
00377     tessoutline->loop = make_tess_edgepts (outline->polypts (),
00378       tessoutline->topleft,
00379       tessoutline->botright);
00380     if (tessoutline->loop == NULL) {
00381       oldoutline(tessoutline);
00382       continue;
00383     }
00384     tessoutline->start = tessoutline->loop->pos;
00385     tessoutline->node = NULL;
00386     tessoutline->next = NULL;
00387     tessoutline->child = NULL;
00388     if (!outline->child ()->empty ()) {
00389       if (flatten)
00390         tessoutline->next = (struct olinestruct *)
00391           make_tess_outlines (outline->child (), flatten);
00392       else {
00393         tessoutline->next = NULL;
00394         tessoutline->child = (struct olinestruct *)
00395           make_tess_outlines (outline->child (), flatten);
00396       }
00397     }
00398     else
00399       tessoutline->next = NULL;
00400     if (head)
00401       tail->next = tessoutline;
00402     else
00403       head = tessoutline;
00404     while (tessoutline->next != NULL)
00405       tessoutline = tessoutline->next;
00406     tail = tessoutline;
00407   }
00408   return head;
00409 }

void make_tess_row ( DENORM denorm,
TEXTROW tessrow 
)

Make a fake row structure to pass to the tesseract matchers.

Definition at line 261 of file tstruct.cpp.

References QUAD_SPEC::a, ROW::ascenders(), textrowstruct::ascrise, QUAD_SPEC::b, textrowstruct::baseline, QUAD_SPEC::c, textrowstruct::descdrop, ROW::descenders(), textrowstruct::lineheight, SPLINE_SPEC::quads, DENORM::row(), DENORM::scale(), SPLINE_SPEC::segments, textrowstruct::xheight, and SPLINE_SPEC::xstarts.

Referenced by compare_bln_blobs(), tess_adapter(), tess_bn_matcher(), tess_cn_matcher(), tess_default_matcher(), and tess_training_tester().

00264                     {
00265   tessrow->baseline.segments = 1;
00266   tessrow->baseline.xstarts[0] = -32767;
00267   tessrow->baseline.xstarts[1] = 32767;
00268   tessrow->baseline.quads[0].a = 0;
00269   tessrow->baseline.quads[0].b = 0;
00270   tessrow->baseline.quads[0].c = bln_baseline_offset;
00271   tessrow->xheight.segments = 1;
00272   tessrow->xheight.xstarts[0] = -32767;
00273   tessrow->xheight.xstarts[1] = 32767;
00274   tessrow->xheight.quads[0].a = 0;
00275   tessrow->xheight.quads[0].b = 0;
00276   tessrow->xheight.quads[0].c = bln_x_height + bln_baseline_offset;
00277   tessrow->lineheight = bln_x_height;
00278   tessrow->ascrise = denorm->row ()->ascenders () * denorm->scale ();
00279   tessrow->descdrop = denorm->row ()->descenders () * denorm->scale ();
00280 }

TWERD* make_tess_word ( WERD word,
TEXTROW row 
)

Convert the word to Tess format.

Definition at line 286 of file tstruct.cpp.

References wordstruct::blanks, WERD::blob_list(), wordstruct::blobcount, wordstruct::blobs, wordstruct::correct, wordstruct::guess, make_tess_blobs(), newword(), wordstruct::next, NULL, wordstruct::row, strsave, and WERD::text().

Referenced by recog_word_recursive(), tess_adaptable_word(), tess_adapter(), unrej_good_chs(), word_blob_quality(), and word_char_quality().

00289                        {
00290   TWERD *tessword;               //tess format
00291 
00292   tessword = newword ();         //use old allocator
00293   tessword->row = row;           //give them something
00294                                  //copy string
00295   tessword->correct = strsave (word->text ());
00296   tessword->guess = NULL;
00297   tessword->blobs = make_tess_blobs (word->blob_list ());
00298   tessword->blanks = 1;
00299   tessword->blobcount = word->blob_list ()->length ();
00300   tessword->next = NULL;
00301   return tessword;
00302 }

void register_outline ( TESSLINE outline,
FRAGMENT_LIST *  list 
)

Add the fragments in the given outline to the list.

Definition at line 163 of file tstruct.cpp.

References edgeptstruct::flags, olinestruct::loop, edgeptstruct::next, and NULL.

Referenced by make_ed_blob().

00166                        {
00167   EDGEPT *startpt;               //start of outline
00168   EDGEPT *headpt;                //start of fragment
00169   EDGEPT *tailpt;                //end of fragment
00170   FRAGMENT *fragment;            //new fragment
00171   FRAGMENT_IT it = list;         //iterator
00172 
00173   startpt = outline->loop;
00174   do {
00175     startpt = startpt->next;
00176     if (startpt == NULL)
00177       return;                    //illegal!
00178   }
00179   while (startpt->flags[0] == 0 && startpt != outline->loop);
00180   headpt = startpt;
00181   do
00182   startpt = startpt->next;
00183   while (startpt->flags[0] != 0 && startpt != headpt);
00184   if (startpt->flags[0] != 0)
00185     return;                      //all hidden!
00186 
00187   headpt = startpt;
00188   do {
00189     tailpt = headpt;
00190     do
00191     tailpt = tailpt->next;
00192     while (tailpt->flags[0] == 0 && tailpt != startpt);
00193     fragment = new FRAGMENT (headpt, tailpt);
00194     it.add_after_then_move (fragment);
00195     while (tailpt->flags[0] != 0)
00196       tailpt = tailpt->next;
00197     headpt = tailpt;
00198   }
00199   while (tailpt != startpt);
00200 }


Variable Documentation

WERD* clone

Definition at line 72 of file tstruct.h.

Referenced by make_ed_word(), and WERD::WERD().


Generated on Wed Feb 28 19:49:16 2007 for Tesseract by  doxygen 1.5.1