2007-03-08 04:03:40 +08:00
|
|
|
/**********************************************************************
|
|
|
|
* File: edgblob.h (Formerly edgeloop.h)
|
|
|
|
* Description: Functions to clean up an outline before approximation.
|
|
|
|
* Author: Ray Smith
|
|
|
|
* Created: Tue Mar 26 16:56:25 GMT 1991
|
|
|
|
*
|
|
|
|
* (C) Copyright 1991, 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.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#ifndef EDGBLOB_H
|
|
|
|
#define EDGBLOB_H
|
|
|
|
|
2008-02-01 08:48:25 +08:00
|
|
|
#include "scrollview.h"
|
2010-11-24 02:34:14 +08:00
|
|
|
#include "params.h"
|
2007-03-08 04:03:40 +08:00
|
|
|
#include "ocrblock.h"
|
|
|
|
#include "coutln.h"
|
|
|
|
#include "crakedge.h"
|
|
|
|
|
|
|
|
#define BUCKETSIZE 16
|
|
|
|
|
|
|
|
class OL_BUCKETS
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
OL_BUCKETS( //constructor
|
|
|
|
ICOORD bleft, //corners
|
|
|
|
ICOORD tright);
|
|
|
|
|
|
|
|
~OL_BUCKETS () { //cleanup
|
|
|
|
delete[]buckets;
|
|
|
|
}
|
|
|
|
C_OUTLINE_LIST *operator () (//array access
|
2008-04-22 08:34:11 +08:00
|
|
|
inT16 x, //image coords
|
|
|
|
inT16 y);
|
2007-03-08 04:03:40 +08:00
|
|
|
//first non-empty bucket
|
2008-04-22 08:34:11 +08:00
|
|
|
C_OUTLINE_LIST *start_scan() {
|
2007-03-08 04:03:40 +08:00
|
|
|
for (index = 0; buckets[index].empty () && index < bxdim * bydim - 1;
|
|
|
|
index++);
|
|
|
|
return &buckets[index];
|
|
|
|
}
|
|
|
|
//next non-empty bucket
|
2008-04-22 08:34:11 +08:00
|
|
|
C_OUTLINE_LIST *scan_next() {
|
2007-03-08 04:03:40 +08:00
|
|
|
for (; buckets[index].empty () && index < bxdim * bydim - 1; index++);
|
|
|
|
return &buckets[index];
|
|
|
|
}
|
2008-04-22 08:34:11 +08:00
|
|
|
inT32 count_children( //recursive sum
|
2007-03-08 04:03:40 +08:00
|
|
|
C_OUTLINE *outline, //parent outline
|
2009-07-11 10:39:56 +08:00
|
|
|
inT32 max_count); // max output
|
|
|
|
inT32 outline_complexity( // new version of count_children
|
|
|
|
C_OUTLINE *outline, // parent outline
|
|
|
|
inT32 max_count, // max output
|
|
|
|
inT16 depth); // level of recursion
|
2007-03-08 04:03:40 +08:00
|
|
|
void extract_children( //single level get
|
|
|
|
C_OUTLINE *outline, //parent outline
|
|
|
|
C_OUTLINE_IT *it); //destination iterator
|
|
|
|
|
|
|
|
private:
|
|
|
|
C_OUTLINE_LIST * buckets; //array of buckets
|
2008-04-22 08:34:11 +08:00
|
|
|
inT16 bxdim; //size of array
|
|
|
|
inT16 bydim;
|
2007-03-08 04:03:40 +08:00
|
|
|
ICOORD bl; //corners
|
|
|
|
ICOORD tr;
|
2008-04-22 08:34:11 +08:00
|
|
|
inT32 index; //for extraction scan
|
2007-03-08 04:03:40 +08:00
|
|
|
};
|
|
|
|
|
2010-11-24 02:34:14 +08:00
|
|
|
void extract_edges(Pix* pix, // thresholded image
|
|
|
|
BLOCK* block); // block to scan
|
2007-03-08 04:03:40 +08:00
|
|
|
void outlines_to_blobs( //find blobs
|
|
|
|
BLOCK *block, //block to scan
|
|
|
|
ICOORD bleft, //block box //outlines in block
|
|
|
|
ICOORD tright,
|
|
|
|
C_OUTLINE_LIST *outlines);
|
|
|
|
void fill_buckets( //find blobs
|
|
|
|
C_OUTLINE_LIST *outlines, //outlines in block
|
|
|
|
OL_BUCKETS *buckets //output buckets
|
|
|
|
);
|
|
|
|
void empty_buckets( //find blobs
|
|
|
|
BLOCK *block, //block to scan
|
|
|
|
OL_BUCKETS *buckets //output buckets
|
|
|
|
);
|
|
|
|
BOOL8 capture_children( //find children
|
|
|
|
OL_BUCKETS *buckets, //bucket sort clanss
|
|
|
|
C_BLOB_IT *reject_it, //dead grandchildren
|
|
|
|
C_OUTLINE_IT *blob_it //output outlines
|
|
|
|
);
|
|
|
|
#endif
|