// -*- C++ -*- // 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: ocr-text-image-seg-leptonica.cc // Purpose: Wrapper class for getting non-text mask from leptonica // Responsible: Faisal Shafait (faisal.shafait@dfki.de) // Reviewer: // Primary Repository: // Web Sites: www.iupr.org, www.dfki.de #include "colib.h" #include "ocr-utils.h" using namespace colib; #ifndef HAVE_LEPTONICA namespace ocropus { ITextImageClassification *make_TextImageSegByLeptonica(){ throw "Leptonica is disabled, please compile with it or don't use it!"; } } #else #include #include #include #include "imgio.h" #include "imglib.h" #include "allheaders.h" // leptonica image class #include "ocr-text-image-seg-leptonica.h" using namespace iulib; namespace ocropus { void TextImageSegByLeptonica::getLeptNonTextMask(bytearray &out, bytearray &in){ makelike(out,in); fill(out,255); PIX *pix; int w = in.dim(0); int h = in.dim(1); int d = 8; if ((pix = pixCreate(w, h, d)) == NULL){ fprintf(stderr,"PIX structure could not be made.\n"); exit(1); } unsigned int *data = pixGetData(pix); int wpl = pixGetWpl(pix); int bpl = (d * w + 7) / 8; unsigned int *line; unsigned char val8; for(int y=0; y binarize(make_BinarizeByOtsu()); makelike(in_binary,in); binarize->binarize(in_binary,in); }else{ copy(in_binary,in); } bytearray nontext_mask; getLeptNonTextMask(nontext_mask,in_binary); //write_image_gray("nontext-mask.png",nontext_mask); ASSERT(in_binary.length1d()==nontext_mask.length1d()); makelike(out,in_binary); int w = in_binary.dim(0); int h = in_binary.dim(1); for(int x=0; x