Tesseract
3.02
|
00001 /* -*-C-*- 00002 ******************************************************************************** 00003 * 00004 * File: plotseg.c (Formerly plotseg.c) 00005 * Description: 00006 * Author: Mark Seaman, OCR Technology 00007 * Created: Fri Oct 16 14:37:00 1987 00008 * Modified: Fri Apr 26 10:03:05 1991 (Mark Seaman) marks@hpgrlt 00009 * Language: C 00010 * Package: N/A 00011 * Status: Reusable Software Component 00012 * 00013 * (c) Copyright 1987, Hewlett-Packard Company. 00014 ** Licensed under the Apache License, Version 2.0 (the "License"); 00015 ** you may not use this file except in compliance with the License. 00016 ** You may obtain a copy of the License at 00017 ** http://www.apache.org/licenses/LICENSE-2.0 00018 ** Unless required by applicable law or agreed to in writing, software 00019 ** distributed under the License is distributed on an "AS IS" BASIS, 00020 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00021 ** See the License for the specific language governing permissions and 00022 ** limitations under the License. 00023 * 00024 *********************************************************************************/ 00025 /*---------------------------------------------------------------------- 00026 I n c l u d e s 00027 ----------------------------------------------------------------------*/ 00028 #include "plotseg.h" 00029 #include "callcpp.h" 00030 #include "scrollview.h" 00031 #include "blobs.h" 00032 #include "const.h" 00033 #include <math.h> 00034 00035 // Include automatically generated configuration file if running autoconf. 00036 #ifdef HAVE_CONFIG_H 00037 #include "config_auto.h" 00038 #endif 00039 00040 #ifndef GRAPHICS_DISABLED 00041 00042 /*---------------------------------------------------------------------- 00043 V a r i a b l e s 00044 ----------------------------------------------------------------------*/ 00045 ScrollView *segm_window = NULL; 00046 00047 INT_VAR(wordrec_display_segmentations, 0, "Display Segmentations"); 00048 00049 /*---------------------------------------------------------------------- 00050 F u n c t i o n s 00051 ----------------------------------------------------------------------*/ 00052 /********************************************************************** 00053 * display_segmentation 00054 * 00055 * Display all the words on the page into a window. 00056 **********************************************************************/ 00057 void display_segmentation(TBLOB *chunks, SEARCH_STATE segmentation) { 00058 /* If no window create it */ 00059 if (segm_window == NULL) { 00060 segm_window = c_create_window ("Segmentation", 5, 10, 00061 500, 256, -1000.0, 1000.0, 0.0, 256.0); 00062 } 00063 else { 00064 c_clear_window(segm_window); 00065 } 00066 00067 render_segmentation(segm_window, chunks, segmentation); 00068 /* Put data in the window */ 00069 c_make_current(segm_window); 00070 } 00071 00072 /********************************************************************** 00073 * render_segmentation 00074 * 00075 * Create a list of line segments that represent the list of chunks 00076 * using the correct segmentation that was supplied as input. 00077 **********************************************************************/ 00078 void render_segmentation(ScrollView *window, 00079 TBLOB *chunks, 00080 SEARCH_STATE segmentation) { 00081 TBLOB *blob; 00082 C_COL color = Black; 00083 int char_num = -1; 00084 int chunks_left = 0; 00085 00086 TBOX bbox; 00087 if (chunks) bbox = chunks->bounding_box(); 00088 00089 for (blob = chunks; blob != NULL; blob = blob->next) { 00090 bbox += blob->bounding_box(); 00091 if (chunks_left-- == 0) { 00092 color = color_list[++char_num % NUM_COLORS]; 00093 00094 if (char_num < segmentation[0]) 00095 chunks_left = segmentation[char_num + 1]; 00096 else 00097 chunks_left = MAX_INT32; 00098 } 00099 render_outline(window, blob->outlines, color); 00100 } 00101 window->ZoomToRectangle(bbox.left(), bbox.top(), 00102 bbox.right(), bbox.bottom()); 00103 } 00104 00105 #endif // GRPAHICS_DISABLED