// -*- C++ -*- // Copyright 2006-2007 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: roughocr -- mock OCR system exercising the interfaces and useful for testing // File: ocr-labels-to-grid.cc // Purpose: output grid file corresponding to label file // Responsible: tmb // Reviewer: // Primary Repository: // Web Sites: www.iupr.org, www.dfki.de #include "colib.h" #include "imgio.h" #include "imglib.h" using namespace ocropus; using namespace colib; int grid_pack(bytearray &result,narray &components) { int x = 0; int y = 0; int max_ch = 0; fill(result,0); if(result.dim(0)>0 && result.dim(1)>0) result(0,0) = 255; for(int i=0;iresult.dim(0)) { y = y + 1 + max_ch; max_ch = 0; x = 0; } CHECK_CONDITION(cw+10) return y+1+max_ch; else return y; } void unpack_grid(narray &components,bytearray &image) { objlist clist; int y0 = 0; while(y0 clist;; for(int file=2;file=1000000,"max(image)>=1M; make sure components are numbered sequentially from 1"); narray bboxes; bounding_boxes(bboxes,image); fprintf(stderr,"# %s: %d boxes\n",argv[file],bboxes.length()); for(int i=1;i components; move(components,clist); bytearray result; result.resize(1000,0); int h = grid_pack(result,components); result.resize(1000,h); grid_pack(result,components); write_png(stdio(argv[1],"w"),result); } catch(const char *oops) { fprintf(stderr,"oops: %s\n",oops); } }