// Copyright 2006-2008 Deutsches Forschungszentrum fuer Kuenstliche Intelligenz // or its licensors, as applicable. // // You may not use this file except under the terms of the accompanying license. // // 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. // // Project: OCRopus // File: line-info.cc // Purpose: getting line information from a single line // Responsible: Faisal Shafait // Reviewer: // Primary Repository: // Web Sites: www.iupr.org, www.dfki.de #include #include "colib.h" #include "imgio.h" #include "imglib.h" #include "ocr-ctextline-rast-extended.h" #include "ocr-segmentations.h" using namespace iulib; using namespace colib; namespace ocropus { param_bool debug_line_info("debug_line_info",0,"Get line info image"); void paint_line(intarray &image, TextLineExtended l){ int width=image.dim(0); int height=image.dim(1); float y; float slope = l.m; float y_intercept = l.c; float descender = l.d; float ascender = l.a; float xheight = l.x; int start = (l.bbox.x0>0) ? (int) l.bbox.x0 : 0; int end = (l.bbox.x1 = 0) && (yl < height) ) image(x,yl) &= 0xff0000ff; if( (yh >= 0) && (yh < height) ) image(x,yh) &= 0xff0000ff; if(!baseline_only){ if( (dl >= 0) && (dl < height) ) image(x,dl) &= 0xff00ffff; if( (dh >= 0) && (dh < height) ) image(x,dh) &= 0xff00ffff; if( (al >= 0) && (al < height) ) image(x,al) &= 0x00ff0000; if( (ah >= 0) && (ah < height) ) image(x,ah) &= 0x00ff0000; if( (xl >= 0) && (xl < height) ) image(x,xl) &= 0x0000ff00; if( (xh >= 0) && (xh < height) ) image(x,xh) &= 0x0000ff00; } } } static void set_default_line_info(float &intercept, float &slope, float &xheight, float &descender_sink, float &ascender_rise, intarray &charimage) { int ystart=-1,yend=-1; for(int y=0, h=charimage.dim(1); y charstats(make_CharStats()); charstats->getCharBoxes(bboxes); if(!charstats->char_boxes.length()){ set_default_line_info(intercept, slope, xheight, descender_sink, ascender_rise, charimage); return true; } charstats->calcCharStats(); // Extract textlines autodel ctextline(make_CTextlineRASTExtended()); ctextline->min_q = 2.0; // Minimum acceptable quality of a textline ctextline->min_count = 2; // ---- number of characters in a textline ctextline->min_length = 30; // ---- length in pixels of a textline ctextline->max_results = 1; ctextline->min_gap = 500; ctextline->epsilon = 2; narray textlines; ctextline->extract(textlines,charstats); // Return the info if(!textlines.length()) { set_default_line_info(intercept, slope, xheight, descender_sink, ascender_rise, charimage); }else{ TextLineExtended &t = textlines[0]; intercept = t.c; slope = t.m; descender_sink = t.d; xheight = t.x; ascender_rise = t.x+t.a; if(debug_line_info){ intarray lineimage; makelike(lineimage, charimage); for(int i=0; i