|
Tesseract
3.02
|
#include <bbgrid.h>
Public Member Functions | |
| IntGrid () | |
| IntGrid (int gridsize, const ICOORD &bleft, const ICOORD &tright) | |
| virtual | ~IntGrid () |
| void | Init (int gridsize, const ICOORD &bleft, const ICOORD &tright) |
| void | Clear () |
| void | Rotate (const FCOORD &rotation) |
| IntGrid * | NeighbourhoodSum () const |
| int | GridCellValue (int grid_x, int grid_y) const |
| void | SetGridCell (int grid_x, int grid_y, int value) |
| bool | RectMostlyOverThreshold (const TBOX &rect, int threshold) const |
| bool | AnyZeroInRect (const TBOX &rect) const |
| Pix * | ThresholdToPix (int threshold) const |
| tesseract::IntGrid::IntGrid | ( | ) |
Definition at line 66 of file bbgrid.cpp.
{
grid_ = NULL;
}
Definition at line 70 of file bbgrid.cpp.
| tesseract::IntGrid::~IntGrid | ( | ) | [virtual] |
Definition at line 75 of file bbgrid.cpp.
{
if (grid_ != NULL)
delete [] grid_;
}
| bool tesseract::IntGrid::AnyZeroInRect | ( | const TBOX & | rect | ) | const |
Definition at line 178 of file bbgrid.cpp.
{
int min_x, min_y, max_x, max_y;
GridCoords(rect.left(), rect.bottom(), &min_x, &min_y);
GridCoords(rect.right(), rect.top(), &max_x, &max_y);
for (int y = min_y; y <= max_y; ++y) {
for (int x = min_x; x <= max_x; ++x) {
if (GridCellValue(x, y) == 0)
return true;
}
}
return false;
}
| void tesseract::IntGrid::Clear | ( | ) |
Definition at line 91 of file bbgrid.cpp.
{
for (int i = 0; i < gridbuckets_; ++i) {
grid_[i] = 0;
}
}
| int tesseract::IntGrid::GridCellValue | ( | int | grid_x, |
| int | grid_y | ||
| ) | const [inline] |
Definition at line 125 of file bbgrid.h.
{
ClipGridCoords(&grid_x, &grid_y);
return grid_[grid_y * gridwidth_ + grid_x];
}
Reimplemented from tesseract::GridBase.
Definition at line 82 of file bbgrid.cpp.
{
GridBase::Init(gridsize, bleft, tright);
if (grid_ != NULL)
delete [] grid_;
grid_ = new int[gridbuckets_];
Clear();
}
| IntGrid * tesseract::IntGrid::NeighbourhoodSum | ( | ) | const |
Definition at line 136 of file bbgrid.cpp.
{
IntGrid* sumgrid = new IntGrid(gridsize(), bleft(), tright());
for (int y = 0; y < gridheight(); ++y) {
for (int x = 0; x < gridwidth(); ++x) {
int cell_count = 0;
for (int yoffset = -1; yoffset <= 1; ++yoffset) {
for (int xoffset = -1; xoffset <= 1; ++xoffset) {
int grid_x = x + xoffset;
int grid_y = y + yoffset;
ClipGridCoords(&grid_x, &grid_y);
cell_count += GridCellValue(grid_x, grid_y);
}
}
if (GridCellValue(x, y) > 1)
sumgrid->SetGridCell(x, y, cell_count);
}
}
return sumgrid;
}
| bool tesseract::IntGrid::RectMostlyOverThreshold | ( | const TBOX & | rect, |
| int | threshold | ||
| ) | const |
Definition at line 158 of file bbgrid.cpp.
{
int min_x, min_y, max_x, max_y;
GridCoords(rect.left(), rect.bottom(), &min_x, &min_y);
GridCoords(rect.right(), rect.top(), &max_x, &max_y);
int total_area = 0;
for (int y = min_y; y <= max_y; ++y) {
for (int x = min_x; x <= max_x; ++x) {
int value = GridCellValue(x, y);
if (value > threshold) {
TBOX cell_box(x * gridsize_, y * gridsize_,
(x + 1) * gridsize_, (y + 1) * gridsize_);
cell_box &= rect; // This is in-place box intersection.
total_area += cell_box.area();
}
}
}
return total_area * 2 > rect.area();
}
| void tesseract::IntGrid::Rotate | ( | const FCOORD & | rotation | ) |
Definition at line 103 of file bbgrid.cpp.
{
ASSERT_HOST(rotation.x() == 0.0f || rotation.y() == 0.0f);
ICOORD old_bleft(bleft());
ICOORD old_tright(tright());
int old_width = gridwidth();
int old_height = gridheight();
TBOX box(bleft(), tright());
box.rotate(rotation);
int* old_grid = grid_;
grid_ = NULL;
Init(gridsize(), box.botleft(), box.topright());
// Iterate over the old grid, copying data to the rotated position in the new.
int oldi = 0;
FCOORD x_step(rotation);
x_step *= gridsize();
for (int oldy = 0; oldy < old_height; ++oldy) {
FCOORD line_pos(old_bleft.x(), old_bleft.y() + gridsize() * oldy);
line_pos.rotate(rotation);
for (int oldx = 0; oldx < old_width; ++oldx, line_pos += x_step, ++oldi) {
int grid_x, grid_y;
GridCoords(static_cast<int>(line_pos.x() + 0.5),
static_cast<int>(line_pos.y() + 0.5),
&grid_x, &grid_y);
grid_[grid_y * gridwidth() + grid_x] = old_grid[oldi];
}
}
delete [] old_grid;
}
| void tesseract::IntGrid::SetGridCell | ( | int | grid_x, |
| int | grid_y, | ||
| int | value | ||
| ) | [inline] |
Definition at line 129 of file bbgrid.h.
{
ASSERT_HOST(grid_x >= 0 && grid_x < gridwidth());
ASSERT_HOST(grid_y >= 0 && grid_y < gridheight());
grid_[grid_y * gridwidth_ + grid_x] = value;
}
| Pix * tesseract::IntGrid::ThresholdToPix | ( | int | threshold | ) | const |
Definition at line 194 of file bbgrid.cpp.
{
Pix* pix = pixCreate(tright().x() - bleft().x(),
tright().y() - bleft().y(), 1);
int cellsize = gridsize();
for (int y = 0; y < gridheight(); ++y) {
for (int x = 0; x < gridwidth(); ++x) {
if (GridCellValue(x, y) > threshold &&
GridCellValue(x - 1, y) > 0 && GridCellValue(x + 1, y) > 0 &&
GridCellValue(x, y - 1) > 0 && GridCellValue(x, y + 1) > 0) {
pixRasterop(pix, x * cellsize, tright().y() - ((y + 1) * cellsize),
cellsize, cellsize, PIX_SET, NULL, 0, 0);
}
}
}
return pix;
}