#include "mfcpch.h"
#include "charcut.h"
#include "imgs.h"
#include "showim.h"
#include "evnts.h"
#include "notdll.h"
Go to the source code of this file.
#define BUG_OFFSET 1 |
Definition at line 29 of file charcut.cpp.
Referenced by char_clip_word(), display_clip_image(), and generate_imlines().
#define EXTERN |
Definition at line 31 of file charcut.cpp.
#define LARGEST | ( | a, | |||
b | ) | ( (a) > (b) ? (a) : (b) ) |
* (C) Copyright 1992, Hewlett-Packard Ltd. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** http://www.apache.org/licenses/LICENSE-2.0 ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License.
Definition at line 27 of file charcut.cpp.
Referenced by PIXROW::extend().
#define SMALLEST | ( | a, | |||
b | ) | ( (a) > (b) ? (b) : (a) ) |
void char_clip_word | ( | WERD * | word, | |
IMAGE & | bin_image, | |||
PIXROW_LIST *& | pixrow_list, | |||
IMAGELINE *& | imlines, | |||
BOX & | pix_box | |||
) |
Generate a PIXROW_LIST with one element for each blob in the word, together with the image lines for the whole word.
word | word to be processed | |
bin_image | whole image | |
pixrow_list | pixrows built | |
imlines | lines cut from image | |
pix_box | box defining imlines |
Definition at line 468 of file charcut.cpp.
References ASSERT_HOST, WERD::blob_list(), BOX::bottom(), WERD::bounding_box(), BUG_OFFSET, PIXROW::extend(), FALSE, WERD::flag(), generate_imlines(), IMAGE::get_xsize(), IMAGE::get_ysize(), BOX::height(), BOX::left(), BOX::move_bottom_edge(), BOX::move_left_edge(), BOX::move_right_edge(), BOX::move_top_edge(), NULL, and W_INVERSE.
Referenced by adapt_to_good_ems(), adapt_to_good_samples(), collect_characters_for_adaption(), and collect_ems_for_adaption().
00474 { 00475 BOX word_box = word->bounding_box (); 00476 PBLOB_LIST *blob_list; 00477 PBLOB_IT blob_it; 00478 PIXROW_IT pixrow_it; 00479 INT16 pix_offset; //Y pos of pixrow[0] 00480 INT16 row_height; //No of pix rows 00481 INT16 imlines_x_offset; 00482 PIXROW *prev; 00483 PIXROW *next; 00484 PIXROW *current; 00485 BOOL8 changed; //still improving 00486 BOOL8 just_changed; //still improving 00487 INT16 iteration_count = 0; 00488 INT16 foreground_colour; 00489 00490 if (word->flag (W_INVERSE)) 00491 foreground_colour = 1; 00492 else 00493 foreground_colour = 0; 00494 00495 /* Define region for max pixrow expansion */ 00496 pix_box = word_box; 00497 pix_box.move_bottom_edge (-pix_word_margin); 00498 pix_box.move_top_edge (pix_word_margin); 00499 pix_box.move_left_edge (-pix_word_margin); 00500 pix_box.move_right_edge (pix_word_margin); 00501 pix_box -= BOX (ICOORD (0, 0 + BUG_OFFSET), 00502 ICOORD (bin_image.get_xsize (), 00503 bin_image.get_ysize () - BUG_OFFSET)); 00504 00505 /* Generate pixrows list */ 00506 00507 pix_offset = pix_box.bottom (); 00508 row_height = pix_box.height (); 00509 blob_list = word->blob_list (); 00510 blob_it.set_to_list (blob_list); 00511 00512 pixrow_list = new PIXROW_LIST; 00513 pixrow_it.set_to_list (pixrow_list); 00514 00515 for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) { 00516 PIXROW *row = new PIXROW (pix_offset, row_height, blob_it.data ()); 00517 ASSERT_HOST (!row-> 00518 bad_box (bin_image.get_xsize (), bin_image.get_ysize ())); 00519 pixrow_it.add_after_then_move (row); 00520 } 00521 00522 imlines = generate_imlines (bin_image, pix_box); 00523 00524 /* Contract pixrows - shrink min and max back to black pixels */ 00525 00526 imlines_x_offset = pix_box.left (); 00527 00528 pixrow_it.move_to_first (); 00529 for (pixrow_it.mark_cycle_pt (); 00530 !pixrow_it.cycled_list (); pixrow_it.forward ()) { 00531 ASSERT_HOST (!pixrow_it.data ()-> 00532 bad_box (bin_image.get_xsize (), bin_image.get_ysize ())); 00533 pixrow_it.data ()->contract (imlines, imlines_x_offset, 00534 foreground_colour); 00535 ASSERT_HOST (!pixrow_it.data ()-> 00536 bad_box (bin_image.get_xsize (), bin_image.get_ysize ())); 00537 } 00538 00539 /* Expand pixrows iteratively 1 pixel at a time */ 00540 do { 00541 changed = FALSE; 00542 pixrow_it.move_to_first (); 00543 prev = NULL; 00544 current = NULL; 00545 next = pixrow_it.data (); 00546 for (pixrow_it.mark_cycle_pt (); 00547 !pixrow_it.cycled_list (); pixrow_it.forward ()) { 00548 prev = current; 00549 current = next; 00550 if (pixrow_it.at_last ()) 00551 next = NULL; 00552 else 00553 next = pixrow_it.data_relative (1); 00554 just_changed = current->extend (imlines, pix_box, prev, next, 00555 foreground_colour); 00556 ASSERT_HOST (!current-> 00557 bad_box (bin_image.get_xsize (), 00558 bin_image.get_ysize ())); 00559 changed = changed || just_changed; 00560 } 00561 iteration_count++; 00562 } 00563 while (changed); 00564 }
WINDOW display_clip_image | ( | WERD * | word, | |
IMAGE & | bin_image, | |||
PIXROW_LIST * | pixrow_list, | |||
BOX & | pix_box | |||
) |
All the boring user interface bits to let you see what's going on.
word | word to be processed | |
bin_image | whole image | |
pixrow_list | pixrows built | |
pix_box | box defining imlines |
Definition at line 604 of file charcut.cpp.
References BLUE, BOX::bottom(), WERD::bounding_box(), BUG_OFFSET, clear_view_surface, create_window, FALSE, IMAGE::get_xsize(), IMAGE::get_ysize(), BOX::height(), INT_HOLLOW, BOX::left(), BOX::move_bottom_edge(), BOX::move_left_edge(), BOX::move_right_edge(), BOX::move_top_edge(), overlap_picture_ops, pgeditor_msg(), WERD::plot(), BOX::plot(), plot_pixrows(), RED, BOX::right(), SCROLLINGWIN, show_sub_image, BOX::top(), TRUE, and BOX::width().
Referenced by adapt_to_good_ems(), and adapt_to_good_samples().
00608 { 00609 WINDOW clip_window; //window for debug 00610 BOX word_box = word->bounding_box (); 00611 int border = word_box.height () / 2; 00612 BOX display_box = word_box; 00613 00614 display_box.move_bottom_edge (-border); 00615 display_box.move_top_edge (border); 00616 display_box.move_left_edge (-border); 00617 display_box.move_right_edge (border); 00618 display_box -= BOX (ICOORD (0, 0 - BUG_OFFSET), 00619 ICOORD (bin_image.get_xsize (), 00620 bin_image.get_ysize () - BUG_OFFSET)); 00621 00622 pgeditor_msg ("Creating Clip window..."); 00623 clip_window = 00624 create_window ("Clipped Blobs", 00625 SCROLLINGWIN, 00626 editor_word_xpos, editor_word_ypos, 00627 3 * (word_box.width () + 2 * border), 00628 3 * (word_box.height () + 2 * border), 00629 //window width,height 00630 // xmin, xmax 00631 display_box.left (), display_box.right (), 00632 display_box.bottom () - BUG_OFFSET, 00633 display_box.top () - BUG_OFFSET, 00634 // ymin, ymax 00635 TRUE, FALSE, FALSE, TRUE); // down event & key only 00636 pgeditor_msg ("Creating Clip window...Done"); 00637 00638 clear_view_surface(clip_window); 00639 show_sub_image (&bin_image, 00640 display_box.left (), 00641 display_box.bottom (), 00642 display_box.width (), 00643 display_box.height (), 00644 clip_window, 00645 display_box.left (), display_box.bottom () - BUG_OFFSET); 00646 00647 word->plot (clip_window, RED); 00648 word_box.plot (clip_window, INT_HOLLOW, TRUE, BLUE, BLUE); 00649 pix_box.plot (clip_window, INT_HOLLOW, TRUE, BLUE, BLUE); 00650 plot_pixrows(pixrow_list, clip_window); 00651 overlap_picture_ops(TRUE); 00652 return clip_window; 00653 }
Show a pair of clip and scaled character images and wait for key before continuing.
Definition at line 660 of file charcut.cpp.
Referenced by CHAR_PROTO::match().
00660 { 00661 WINDOW clip_im_window; //window for debug 00662 WINDOW scale_im_window; //window for debug 00663 INT16 i; 00664 GRAPHICS_EVENT event; // c; 00665 00666 // xmin xmax ymin ymax 00667 clip_im_window = create_window ("Clipped Blob", SCROLLINGWIN, 00668 editor_word_xpos - 20, editor_word_ypos - 100, 00669 5 * clip_image.get_xsize (), 5 * clip_image.get_ysize (), 00670 0, clip_image.get_xsize (), 0, clip_image.get_ysize (), 00671 TRUE, FALSE, FALSE, TRUE); // down event & key only 00672 00673 clear_view_surface(clip_im_window); 00674 show_sub_image (&clip_image, 00675 0, 0, 00676 clip_image.get_xsize (), clip_image.get_ysize (), 00677 clip_im_window, 0, 0); 00678 00679 line_color_index(clip_im_window, RED); 00680 for (i = 1; i < clip_image.get_xsize (); i++) { 00681 move2d (clip_im_window, i, 0); 00682 draw2d (clip_im_window, i, clip_image.get_xsize ()); 00683 } 00684 for (i = 1; i < clip_image.get_ysize (); i++) { 00685 move2d (clip_im_window, 0, i); 00686 draw2d (clip_im_window, clip_image.get_xsize (), i); 00687 } 00688 00689 // xmin xmax ymin ymax 00690 scale_im_window = create_window ("Scaled Blob", SCROLLINGWIN, 00691 editor_word_xpos + 300, editor_word_ypos - 100, 00692 5 * scaled_image.get_xsize (), 5 * scaled_image.get_ysize (), 00693 0, scaled_image.get_xsize (), 0, scaled_image.get_ysize (), 00694 TRUE, FALSE, FALSE, TRUE); // down event & key only 00695 00696 clear_view_surface(scale_im_window); 00697 show_sub_image (&scaled_image, 00698 0, 0, 00699 scaled_image.get_xsize (), scaled_image.get_ysize (), 00700 scale_im_window, 0, 0); 00701 00702 line_color_index(scale_im_window, RED); 00703 for (i = 1; i < scaled_image.get_xsize (); i++) { 00704 move2d (scale_im_window, i, 0); 00705 draw2d (scale_im_window, i, scaled_image.get_xsize ()); 00706 } 00707 for (i = 1; i < scaled_image.get_ysize (); i++) { 00708 move2d (scale_im_window, 0, i); 00709 draw2d (scale_im_window, scaled_image.get_xsize (), i); 00710 } 00711 00712 overlap_picture_ops(TRUE); 00713 await_event(scale_im_window, TRUE, ANY_EVENT, &event); 00714 destroy_window(clip_im_window); 00715 destroy_window(scale_im_window); 00716 }
ELISTIZE | ( | PIXROW | ) |
Constructor for a specified size PIXROW from a blob.
pos | Position | |
count | Count | |
blob | Blob in question class_def_PIXROW |
Definition at line 40 of file charcut.cpp.
References alloc_mem(), max, MAX_INT16, min, and outline_it.
00049 { 00050 OUTLINE_LIST *outline_list; 00051 OUTLINE_IT outline_it; 00052 POLYPT_LIST *pts_list; 00053 POLYPT_IT pts_it; 00054 INT16 i; 00055 FCOORD pt; 00056 FCOORD vec; 00057 float y_coord; 00058 INT16 x_coord; 00059 00060 row_offset = pos; 00061 row_count = count; 00062 min = (INT16 *) alloc_mem (count * sizeof (INT16)); 00063 max = (INT16 *) alloc_mem (count * sizeof (INT16)); 00064 outline_list = blob->out_list (); 00065 outline_it.set_to_list (outline_list); 00066 00067 for (i = 0; i < count; i++) { 00068 min[i] = MAX_INT16 - 1; 00069 max[i] = -MAX_INT16 + 1; 00070 y_coord = row_offset + i + 0.5; 00071 for (outline_it.mark_cycle_pt (); 00072 !outline_it.cycled_list (); outline_it.forward ()) { 00073 pts_list = outline_it.data ()->polypts (); 00074 pts_it.set_to_list (pts_list); 00075 for (pts_it.mark_cycle_pt (); 00076 !pts_it.cycled_list (); pts_it.forward ()) { 00077 pt = pts_it.data ()->pos; 00078 vec = pts_it.data ()->vec; 00079 if ((vec.y () != 0) && 00080 (((pt.y () <= y_coord) && (pt.y () + vec.y () >= y_coord)) 00081 || ((pt.y () >= y_coord) 00082 && (pt.y () + vec.y () <= y_coord)))) { 00083 /* The segment crosses y_coord so find x-point and check for min/max. */ 00084 x_coord = (INT16) floor ((y_coord - 00085 pt.y ()) * vec.x () / vec.y () + 00086 pt.x () + 0.5); 00087 if (x_coord < min[i]) 00088 min[i] = x_coord; 00089 x_coord--; //to get pix to left of line 00090 if (x_coord > max[i]) 00091 max[i] = x_coord; 00092 } 00093 } 00094 } 00095 } 00096 }
Get an array of IMAGELINES holding a portion of an image.
bin_image | whole image (where we get some imagelines from) | |
pix_box | box defining imlines |
Definition at line 574 of file charcut.cpp.
References BOX::bottom(), BUG_OFFSET, IMAGE::fast_get_line(), BOX::height(), BOX::left(), and BOX::width().
Referenced by char_clip_word().
00576 { 00577 IMAGELINE *imlines; //array of lines 00578 int i; 00579 00580 imlines = new IMAGELINE[pix_box.height ()]; 00581 for (i = 0; i < pix_box.height (); i++) { 00582 imlines[i].init (pix_box.width ()); 00583 //coord to start at 00584 bin_image.fast_get_line (pix_box.left (), 00585 pix_box.bottom () + i + BUG_OFFSET, 00586 //line to get 00587 pix_box.width (), //width to get 00588 imlines + i); //dest imline 00589 } 00590 return imlines; 00591 }
void plot_pixrows | ( | PIXROW_LIST * | pixrow_list, | |
WINDOW | win | |||
) |
Display a list of pixrows [for all blobs].
Definition at line 722 of file charcut.cpp.
References INT_HOLLOW, interior_style, perimeter_color_index, RED, and TRUE.
Referenced by display_clip_image().
00724 { 00725 PIXROW_IT pixrow_it(pixrow_list); 00726 INT16 colour = RED; 00727 00728 for (pixrow_it.mark_cycle_pt (); 00729 !pixrow_it.cycled_list (); pixrow_it.forward ()) { 00730 if (colour > RED + 7) 00731 colour = RED; 00732 00733 perimeter_color_index (win, (COLOUR) colour); 00734 interior_style(win, INT_HOLLOW, TRUE); 00735 pixrow_it.data ()->plot (win); 00736 colour++; 00737 } 00738 }