mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-12-04 09:49:16 +08:00
Use std::max/std::min instead of MAX/MIN macros.
This commit is contained in:
parent
c34e145b1a
commit
14ae0b8727
@ -42,6 +42,7 @@
|
||||
#include <unistd.h>
|
||||
#endif // _WIN32
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
@ -2122,7 +2123,7 @@ bool TessBaseAPI::GetTextDirection(int* out_offset, float* out_slope) {
|
||||
// Shift the baseline down so it passes through the nearest bottom-corner
|
||||
// of the textline's bounding box. This is the difference between the y
|
||||
// at the lowest (max) edge of the box and the actual box bottom.
|
||||
*out_offset += bottom - MAX(left_y, right_y);
|
||||
*out_offset += bottom - std::max(left_y, right_y);
|
||||
// Switch back to bottom-up tesseract coordinates. Requires negation of
|
||||
// the slope and height - offset for the offset.
|
||||
*out_slope = -*out_slope;
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "config_auto.h"
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <string.h>
|
||||
#include <cmath>
|
||||
#ifdef __UNIX__
|
||||
@ -783,7 +784,7 @@ static void EvaluateWordSpan(const PointerVector<WERD_RES>& words,
|
||||
*bad = true;
|
||||
} else {
|
||||
*rating += choice->rating();
|
||||
*certainty = MIN(*certainty, choice->certainty());
|
||||
*certainty = std::min(*certainty, choice->certainty());
|
||||
if (!Dict::valid_word_permuter(choice->permuter(), false))
|
||||
*valid_permuter = false;
|
||||
}
|
||||
@ -818,7 +819,7 @@ static int SelectBestWords(double rating_ratio,
|
||||
int n_right = -INT32_MAX;
|
||||
int next_n_left = INT32_MAX;
|
||||
WordGap(*new_words, n, &n_right, &next_n_left);
|
||||
if (MAX(b_right, n_right) < MIN(next_b_left, next_n_left)) {
|
||||
if (std::max(b_right, n_right) < std::min(next_b_left, next_n_left)) {
|
||||
// The word breaks overlap. [start_b,b] and [start_n, n] match.
|
||||
break;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <float.h>
|
||||
#include <limits>
|
||||
|
||||
@ -336,11 +337,11 @@ void EquationDetect::IdentifyBlobsToSkip(ColPartition* part) {
|
||||
const bool xoverlap = blob_box.major_x_overlap(nextblob_box),
|
||||
yoverlap = blob_box.y_overlap(nextblob_box);
|
||||
const float widthR = static_cast<float>(
|
||||
MIN(nextblob_box.width(), blob_box.width())) /
|
||||
MAX(nextblob_box.width(), blob_box.width());
|
||||
std::min(nextblob_box.width(), blob_box.width())) /
|
||||
std::max(nextblob_box.width(), blob_box.width());
|
||||
const float heightR = static_cast<float>(
|
||||
MIN(nextblob_box.height(), blob_box.height())) /
|
||||
MAX(nextblob_box.height(), blob_box.height());
|
||||
std::min(nextblob_box.height(), blob_box.height())) /
|
||||
std::max(nextblob_box.height(), blob_box.height());
|
||||
|
||||
if (xoverlap && yoverlap && widthR > kWidthR && heightR > kHeightR) {
|
||||
// Found one, set nextblob type and recompute blob_box.
|
||||
@ -882,7 +883,7 @@ int EquationDetect::EstimateTextPartLineSpacing() {
|
||||
if (current_box.major_x_overlap(prev_box) &&
|
||||
!current_box.y_overlap(prev_box)) {
|
||||
int gap = current_box.y_gap(prev_box);
|
||||
if (gap < MIN(current_box.height(), prev_box.height())) {
|
||||
if (gap < std::min(current_box.height(), prev_box.height())) {
|
||||
// The gap should be smaller than the height of the bounding boxes.
|
||||
ygaps.push_back(gap);
|
||||
}
|
||||
@ -955,7 +956,7 @@ bool EquationDetect::IsInline(const bool search_bottom,
|
||||
while ((neighbor = search.NextVerticalSearch(search_bottom)) != nullptr) {
|
||||
const TBOX& neighbor_box(neighbor->bounding_box());
|
||||
if (part_box.y_gap(neighbor_box) > kYGapRatioTh *
|
||||
MIN(part_box.height(), neighbor_box.height())) {
|
||||
std::min(part_box.height(), neighbor_box.height())) {
|
||||
// Finished searching.
|
||||
break;
|
||||
}
|
||||
@ -971,8 +972,8 @@ bool EquationDetect::IsInline(const bool search_bottom,
|
||||
if (part_box.x_overlap(neighbor_box) && // Location feature.
|
||||
part_box.y_gap(neighbor_box) <= kYGapTh && // Line spacing.
|
||||
// Geo feature.
|
||||
static_cast<float>(MIN(part_box.height(), neighbor_box.height())) /
|
||||
MAX(part_box.height(), neighbor_box.height()) > kHeightRatioTh) {
|
||||
static_cast<float>(std::min(part_box.height(), neighbor_box.height())) /
|
||||
std::max(part_box.height(), neighbor_box.height()) > kHeightRatioTh) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -17,11 +17,12 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "params.h"
|
||||
#include "float2int.h"
|
||||
#include "tesseractclass.h"
|
||||
#include <algorithm>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "params.h"
|
||||
#include "float2int.h"
|
||||
#include "tesseractclass.h"
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
@ -123,7 +124,7 @@ float Tesseract::ComputeCompatibleXheight(WERD_RES *word_res,
|
||||
// Chars with a wild top range would mess up the result so ignore them.
|
||||
if (max_top - min_top > kMaxCharTopRange)
|
||||
continue;
|
||||
int misfit_dist = MAX((min_top - x_ht_acceptance_tolerance) - top,
|
||||
int misfit_dist = std::max((min_top - x_ht_acceptance_tolerance) - top,
|
||||
top - (max_top + x_ht_acceptance_tolerance));
|
||||
int height = top - kBlnBaselineOffset;
|
||||
if (debug_x_ht_level >= 2) {
|
||||
|
@ -29,6 +29,8 @@
|
||||
#include "pageres.h"
|
||||
#include "tprintf.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
// Scale factor to make certainty more comparable to Tesseract.
|
||||
@ -279,13 +281,13 @@ void Tesseract::SearchWords(PointerVector<WERD_RES>* words) {
|
||||
word->tess_would_adapt = false;
|
||||
word->done = true;
|
||||
word->tesseract = this;
|
||||
float word_certainty = MIN(word->space_certainty,
|
||||
float word_certainty = std::min(word->space_certainty,
|
||||
word->best_choice->certainty());
|
||||
word_certainty *= kCertaintyScale;
|
||||
if (getDict().stopper_debug_level >= 1) {
|
||||
tprintf("Best choice certainty=%g, space=%g, scaled=%g, final=%g\n",
|
||||
word->best_choice->certainty(), word->space_certainty,
|
||||
MIN(word->space_certainty, word->best_choice->certainty()) *
|
||||
std::min(word->space_certainty, word->best_choice->certainty()) *
|
||||
kCertaintyScale,
|
||||
word_certainty);
|
||||
word->best_choice->print();
|
||||
|
@ -33,6 +33,8 @@
|
||||
#include "tesseractclass.h"
|
||||
#include "textord.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
const int kMinCharactersToTry = 50;
|
||||
const int kMaxCharactersToTry = 5 * kMinCharactersToTry;
|
||||
|
||||
@ -282,7 +284,7 @@ int os_detect_blobs(const GenericVector<int>* allowed_scripts,
|
||||
ScriptDetector s(allowed_scripts, osr, tess);
|
||||
|
||||
BLOBNBOX_C_IT filtered_it(blob_list);
|
||||
int real_max = MIN(filtered_it.length(), kMaxCharactersToTry);
|
||||
int real_max = std::min(filtered_it.length(), kMaxCharactersToTry);
|
||||
// tprintf("Total blobs found = %d\n", blobs_total);
|
||||
// tprintf("Number of blobs post-filtering = %d\n", filtered_it.length());
|
||||
// tprintf("Number of blobs to try = %d\n", real_max);
|
||||
|
@ -24,6 +24,8 @@
|
||||
#include "pageres.h"
|
||||
#include "tesseractclass.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
PageIterator::PageIterator(PAGE_RES* page_res, Tesseract* tesseract, int scale,
|
||||
@ -421,9 +423,9 @@ Pix* PageIterator::GetBinaryImage(PageIteratorLevel level) const {
|
||||
int mask_x = left - mask_box.left();
|
||||
int mask_y = top - (tesseract_->ImageHeight() - mask_box.top());
|
||||
// AND the mask and pix, putting the result in pix.
|
||||
pixRasterop(pix, MAX(0, -mask_x), MAX(0, -mask_y), pixGetWidth(pix),
|
||||
pixGetHeight(pix), PIX_SRC & PIX_DST, mask, MAX(0, mask_x),
|
||||
MAX(0, mask_y));
|
||||
pixRasterop(pix, std::max(0, -mask_x), std::max(0, -mask_y), pixGetWidth(pix),
|
||||
pixGetHeight(pix), PIX_SRC & PIX_DST, mask, std::max(0, mask_x),
|
||||
std::max(0, mask_y));
|
||||
pixDestroy(&mask);
|
||||
}
|
||||
return pix;
|
||||
@ -450,10 +452,10 @@ Pix* PageIterator::GetImage(PageIteratorLevel level, int padding,
|
||||
return GetBinaryImage(level);
|
||||
|
||||
// Expand the box.
|
||||
*left = MAX(*left - padding, 0);
|
||||
*top = MAX(*top - padding, 0);
|
||||
right = MIN(right + padding, rect_width_);
|
||||
bottom = MIN(bottom + padding, rect_height_);
|
||||
*left = std::max(*left - padding, 0);
|
||||
*top = std::max(*top - padding, 0);
|
||||
right = std::min(right + padding, rect_width_);
|
||||
bottom = std::min(bottom + padding, rect_height_);
|
||||
Box* box = boxCreate(*left, *top, right - *left, bottom - *top);
|
||||
Pix* grey_pix = pixClipRectangle(original_img, box, nullptr);
|
||||
boxDestroy(&box);
|
||||
@ -467,8 +469,8 @@ Pix* PageIterator::GetImage(PageIteratorLevel level, int padding,
|
||||
int width = pixGetWidth(grey_pix);
|
||||
int height = pixGetHeight(grey_pix);
|
||||
Pix* resized_mask = pixCreate(width, height, 1);
|
||||
pixRasterop(resized_mask, MAX(0, -mask_x), MAX(0, -mask_y), width, height,
|
||||
PIX_SRC, mask, MAX(0, mask_x), MAX(0, mask_y));
|
||||
pixRasterop(resized_mask, std::max(0, -mask_x), std::max(0, -mask_y), width, height,
|
||||
PIX_SRC, mask, std::max(0, mask_x), std::max(0, mask_y));
|
||||
pixDestroy(&mask);
|
||||
pixDilateBrick(resized_mask, resized_mask, 2 * padding + 1,
|
||||
2 * padding + 1);
|
||||
|
@ -17,6 +17,7 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#include <algorithm>
|
||||
#include <ctype.h>
|
||||
#include <memory> // std::unique_ptr
|
||||
|
||||
@ -2415,7 +2416,7 @@ void InitializeRowInfo(bool after_recognition,
|
||||
info->pix_ldistance = row->lmargin();
|
||||
info->pix_rdistance = row->rmargin();
|
||||
info->average_interword_space =
|
||||
row->space() > 0 ? row->space() : MAX(row->x_height(), 1);
|
||||
row->space() > 0 ? row->space() : std::max(static_cast<int>(row->x_height()), 1);
|
||||
info->pix_xheight = row->x_height();
|
||||
info->has_leaders = false;
|
||||
info->has_drop_cap = row->has_drop_cap();
|
||||
|
@ -28,6 +28,8 @@
|
||||
#include "helpers.h"
|
||||
#include "normalis.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#define PROJECTION_MARGIN 10 //arbitrary
|
||||
#define EXTERN
|
||||
|
||||
@ -194,14 +196,14 @@ void BLOBNBOX::NeighbourGaps(int gaps[BND_COUNT]) const {
|
||||
// and avoid reporting the other gap as a ridiculously large number
|
||||
void BLOBNBOX::MinMaxGapsClipped(int* h_min, int* h_max,
|
||||
int* v_min, int* v_max) const {
|
||||
int max_dimension = MAX(box.width(), box.height());
|
||||
int max_dimension = std::max(box.width(), box.height());
|
||||
int gaps[BND_COUNT];
|
||||
NeighbourGaps(gaps);
|
||||
*h_min = MIN(gaps[BND_LEFT], gaps[BND_RIGHT]);
|
||||
*h_max = MAX(gaps[BND_LEFT], gaps[BND_RIGHT]);
|
||||
*h_min = std::min(gaps[BND_LEFT], gaps[BND_RIGHT]);
|
||||
*h_max = std::max(gaps[BND_LEFT], gaps[BND_RIGHT]);
|
||||
if (*h_max > max_dimension && *h_min < max_dimension) *h_max = *h_min;
|
||||
*v_min = MIN(gaps[BND_ABOVE], gaps[BND_BELOW]);
|
||||
*v_max = MAX(gaps[BND_ABOVE], gaps[BND_BELOW]);
|
||||
*v_min = std::min(gaps[BND_ABOVE], gaps[BND_BELOW]);
|
||||
*v_max = std::max(gaps[BND_ABOVE], gaps[BND_BELOW]);
|
||||
if (*v_max > max_dimension && *v_min < max_dimension) *v_max = *v_min;
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,8 @@
|
||||
#include "structures.h"
|
||||
#include "werd.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using tesseract::CCStruct;
|
||||
|
||||
// A Vector representing the "vertical" direction when measuring the
|
||||
@ -587,10 +589,10 @@ static void SegmentLLSQ(const FCOORD& pt1, const FCOORD& pt2,
|
||||
LLSQ* accumulator) {
|
||||
FCOORD step(pt2);
|
||||
step -= pt1;
|
||||
int xstart = IntCastRounded(MIN(pt1.x(), pt2.x()));
|
||||
int xend = IntCastRounded(MAX(pt1.x(), pt2.x()));
|
||||
int ystart = IntCastRounded(MIN(pt1.y(), pt2.y()));
|
||||
int yend = IntCastRounded(MAX(pt1.y(), pt2.y()));
|
||||
int xstart = IntCastRounded(std::min(pt1.x(), pt2.x()));
|
||||
int xend = IntCastRounded(std::max(pt1.x(), pt2.x()));
|
||||
int ystart = IntCastRounded(std::min(pt1.y(), pt2.y()));
|
||||
int yend = IntCastRounded(std::max(pt1.y(), pt2.y()));
|
||||
if (xstart == xend && ystart == yend) return; // Nothing to do.
|
||||
double weight = step.length() / (xend - xstart + yend - ystart);
|
||||
// Compute and save the y-position at the middle of each x-step.
|
||||
@ -616,14 +618,14 @@ static void SegmentCoords(const FCOORD& pt1, const FCOORD& pt2,
|
||||
GenericVector<GenericVector<int> >* y_coords) {
|
||||
FCOORD step(pt2);
|
||||
step -= pt1;
|
||||
int start = ClipToRange(IntCastRounded(MIN(pt1.x(), pt2.x())), 0, x_limit);
|
||||
int end = ClipToRange(IntCastRounded(MAX(pt1.x(), pt2.x())), 0, x_limit);
|
||||
int start = ClipToRange(IntCastRounded(std::min(pt1.x(), pt2.x())), 0, x_limit);
|
||||
int end = ClipToRange(IntCastRounded(std::max(pt1.x(), pt2.x())), 0, x_limit);
|
||||
for (int x = start; x < end; ++x) {
|
||||
int y = IntCastRounded(pt1.y() + step.y() * (x + 0.5 - pt1.x()) / step.x());
|
||||
(*y_coords)[x].push_back(y);
|
||||
}
|
||||
start = ClipToRange(IntCastRounded(MIN(pt1.y(), pt2.y())), 0, y_limit);
|
||||
end = ClipToRange(IntCastRounded(MAX(pt1.y(), pt2.y())), 0, y_limit);
|
||||
start = ClipToRange(IntCastRounded(std::min(pt1.y(), pt2.y())), 0, y_limit);
|
||||
end = ClipToRange(IntCastRounded(std::max(pt1.y(), pt2.y())), 0, y_limit);
|
||||
for (int y = start; y < end; ++y) {
|
||||
int x = IntCastRounded(pt1.x() + step.x() * (y + 0.5 - pt1.y()) / step.y());
|
||||
(*x_coords)[y].push_back(x);
|
||||
@ -636,24 +638,24 @@ static void SegmentCoords(const FCOORD& pt1, const FCOORD& pt2,
|
||||
static void SegmentBBox(const FCOORD& pt1, const FCOORD& pt2, TBOX* bbox) {
|
||||
FCOORD step(pt2);
|
||||
step -= pt1;
|
||||
int x1 = IntCastRounded(MIN(pt1.x(), pt2.x()));
|
||||
int x2 = IntCastRounded(MAX(pt1.x(), pt2.x()));
|
||||
int x1 = IntCastRounded(std::min(pt1.x(), pt2.x()));
|
||||
int x2 = IntCastRounded(std::max(pt1.x(), pt2.x()));
|
||||
if (x2 > x1) {
|
||||
int y1 = IntCastRounded(pt1.y() + step.y() * (x1 + 0.5 - pt1.x()) /
|
||||
step.x());
|
||||
int y2 = IntCastRounded(pt1.y() + step.y() * (x2 - 0.5 - pt1.x()) /
|
||||
step.x());
|
||||
TBOX point(x1, MIN(y1, y2), x2, MAX(y1, y2));
|
||||
TBOX point(x1, std::min(y1, y2), x2, std::max(y1, y2));
|
||||
*bbox += point;
|
||||
}
|
||||
int y1 = IntCastRounded(MIN(pt1.y(), pt2.y()));
|
||||
int y2 = IntCastRounded(MAX(pt1.y(), pt2.y()));
|
||||
int y1 = IntCastRounded(std::min(pt1.y(), pt2.y()));
|
||||
int y2 = IntCastRounded(std::max(pt1.y(), pt2.y()));
|
||||
if (y2 > y1) {
|
||||
int x1 = IntCastRounded(pt1.x() + step.x() * (y1 + 0.5 - pt1.y()) /
|
||||
step.y());
|
||||
int x2 = IntCastRounded(pt1.x() + step.x() * (y2 - 0.5 - pt1.y()) /
|
||||
step.y());
|
||||
TBOX point(MIN(x1, x2), y1, MAX(x1, x2), y2);
|
||||
TBOX point(std::min(x1, x2), y1, std::max(x1, x2), y2);
|
||||
*bbox += point;
|
||||
}
|
||||
}
|
||||
@ -956,7 +958,7 @@ bool divisible_blob(TBLOB *blob, bool italic_blob, TPOINT* location) {
|
||||
int min_prod2, max_prod2;
|
||||
outline2->MinMaxCrossProduct(vertical, &min_prod2, &max_prod2);
|
||||
int mid_gap = abs(mid_prod2 - mid_prod1);
|
||||
int overlap = MIN(max_prod1, max_prod2) - MAX(min_prod1, min_prod2);
|
||||
int overlap = std::min(max_prod1, max_prod2) - std::max(min_prod1, min_prod2);
|
||||
if (mid_gap - overlap / 4 > max_gap) {
|
||||
max_gap = mid_gap - overlap / 4;
|
||||
*location = mid_pt1;
|
||||
|
@ -17,6 +17,7 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#include <algorithm>
|
||||
#include <string.h>
|
||||
#ifdef __UNIX__
|
||||
#include <assert.h>
|
||||
@ -750,7 +751,7 @@ void C_OUTLINE::ComputeEdgeOffsets(int threshold, Pix* pix) {
|
||||
if (pt1.y == pt2.y && abs(gradient.y()) * 2 >= abs(gradient.x())) {
|
||||
// Horizontal step. diff_sign == 1 indicates black above.
|
||||
int diff_sign = (pt1.x > pt2.x) == negative ? 1 : -1;
|
||||
int x = MIN(pt1.x, pt2.x);
|
||||
int x = std::min(pt1.x, pt2.x);
|
||||
int y = height - pt1.y;
|
||||
int best_sum = 0;
|
||||
int best_y = y;
|
||||
@ -773,7 +774,7 @@ void C_OUTLINE::ComputeEdgeOffsets(int threshold, Pix* pix) {
|
||||
// Vertical step. diff_sign == 1 indicates black on the left.
|
||||
int diff_sign = (pt1.y > pt2.y) == negative ? 1 : -1;
|
||||
int x = pt1.x;
|
||||
int y = height - MAX(pt1.y, pt2.y);
|
||||
int y = height - std::max(pt1.y, pt2.y);
|
||||
const l_uint32* line = pixGetData(pix) + y * wpl;
|
||||
int best_sum = 0;
|
||||
int best_x = x;
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include "ndminx.h"
|
||||
#include "tprintf.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
// The number of points to consider at each end.
|
||||
@ -77,14 +79,14 @@ double DetLineFit::Fit(int skip_first, int skip_last,
|
||||
ICOORD* starts[kNumEndPoints];
|
||||
if (skip_first >= pt_count) skip_first = pt_count - 1;
|
||||
int start_count = 0;
|
||||
int end_i = MIN(skip_first + kNumEndPoints, pt_count);
|
||||
int end_i = std::min(skip_first + kNumEndPoints, pt_count);
|
||||
for (int i = skip_first; i < end_i; ++i) {
|
||||
starts[start_count++] = &pts_[i].pt;
|
||||
}
|
||||
ICOORD* ends[kNumEndPoints];
|
||||
if (skip_last >= pt_count) skip_last = pt_count - 1;
|
||||
int end_count = 0;
|
||||
end_i = MAX(0, pt_count - kNumEndPoints - skip_last);
|
||||
end_i = std::max(0, pt_count - kNumEndPoints - skip_last);
|
||||
for (int i = pt_count - 1 - skip_last; i >= end_i; --i) {
|
||||
ends[end_count++] = &pts_[i].pt;
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ Pix* ImageData::PreScale(int target_height, int max_height, float* scale_factor,
|
||||
input_width = pixGetWidth(src_pix);
|
||||
input_height = pixGetHeight(src_pix);
|
||||
if (target_height == 0) {
|
||||
target_height = MIN(input_height, max_height);
|
||||
target_height = std::min(input_height, max_height);
|
||||
}
|
||||
float im_factor = static_cast<float>(target_height) / input_height;
|
||||
if (scaled_width != nullptr)
|
||||
|
@ -29,6 +29,7 @@
|
||||
#ifndef TESSERACT_CCSTRUCT_MATRIX_H_
|
||||
#define TESSERACT_CCSTRUCT_MATRIX_H_
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include "kdpair.h"
|
||||
#include "points.h"
|
||||
@ -250,7 +251,7 @@ class GENERIC_2D_ARRAY {
|
||||
void operator+=(const GENERIC_2D_ARRAY<T>& addend) {
|
||||
if (dim2_ == addend.dim2_) {
|
||||
// Faster if equal size in the major dimension.
|
||||
int size = MIN(num_elements(), addend.num_elements());
|
||||
int size = std::min(num_elements(), addend.num_elements());
|
||||
for (int i = 0; i < size; ++i) {
|
||||
array_[i] += addend.array_[i];
|
||||
}
|
||||
@ -266,7 +267,7 @@ class GENERIC_2D_ARRAY {
|
||||
void operator-=(const GENERIC_2D_ARRAY<T>& minuend) {
|
||||
if (dim2_ == minuend.dim2_) {
|
||||
// Faster if equal size in the major dimension.
|
||||
int size = MIN(num_elements(), minuend.num_elements());
|
||||
int size = std::min(num_elements(), minuend.num_elements());
|
||||
for (int i = 0; i < size; ++i) {
|
||||
array_[i] -= minuend.array_[i];
|
||||
}
|
||||
@ -416,8 +417,8 @@ class GENERIC_2D_ARRAY {
|
||||
// Higher dimensions above 2 are strictly the responsibility of the caller.
|
||||
void RotatingTranspose(const int* dims, int num_dims, int src_dim,
|
||||
int dest_dim, GENERIC_2D_ARRAY<T>* result) const {
|
||||
int max_d = MAX(src_dim, dest_dim);
|
||||
int min_d = MIN(src_dim, dest_dim);
|
||||
int max_d = std::max(src_dim, dest_dim);
|
||||
int min_d = std::min(src_dim, dest_dim);
|
||||
// In a tensor of shape [d0, d1... min_d, ... max_d, ... dn-2, dn-1], the
|
||||
// ends outside of min_d and max_d are unaffected, with [max_d +1, dn-1]
|
||||
// being contiguous blocks of data that will move together, and
|
||||
@ -544,7 +545,7 @@ class BandTriMatrix : public GENERIC_2D_ARRAY<T> {
|
||||
// to *this.
|
||||
void AttachOnCorner(BandTriMatrix<T>* array2) {
|
||||
int new_dim1 = this->dim1_ + array2->dim1_;
|
||||
int new_dim2 = MAX(this->dim2_, array2->dim2_);
|
||||
int new_dim2 = std::max(this->dim2_, array2->dim2_);
|
||||
T* new_array = new T[new_dim1 * new_dim2];
|
||||
for (int col = 0; col < new_dim1; ++col) {
|
||||
for (int j = 0; j < new_dim2; ++j) {
|
||||
|
@ -21,11 +21,12 @@
|
||||
#define _USE_MATH_DEFINES
|
||||
#endif // _MSC_VER
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "helpers.h"
|
||||
#include "ndminx.h"
|
||||
#include "serialis.h"
|
||||
#include "points.h"
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
#include "helpers.h"
|
||||
#include "ndminx.h"
|
||||
#include "serialis.h"
|
||||
#include "points.h"
|
||||
|
||||
ELISTIZE (ICOORDELT) //turn to list
|
||||
bool FCOORD::normalise() { //Convert to unit vec
|
||||
@ -43,7 +44,7 @@ bool FCOORD::normalise() { //Convert to unit vec
|
||||
void ICOORD::set_with_shrink(int x, int y) {
|
||||
// Fit the vector into an ICOORD, which is 16 bit.
|
||||
int factor = 1;
|
||||
int max_extent = MAX(abs(x), abs(y));
|
||||
int max_extent = std::max(abs(x), abs(y));
|
||||
if (max_extent > INT16_MAX)
|
||||
factor = max_extent / INT16_MAX + 1;
|
||||
xcoord = x / factor;
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include "ratngs.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include "blobs.h"
|
||||
#include "callcpp.h"
|
||||
@ -142,10 +143,10 @@ bool BLOB_CHOICE::PosAndSizeAgree(const BLOB_CHOICE& other, float x_height,
|
||||
}
|
||||
double this_range = max_xheight() - min_xheight();
|
||||
double other_range = other.max_xheight() - other.min_xheight();
|
||||
double denominator = ClipToRange(MIN(this_range, other_range),
|
||||
double denominator = ClipToRange(std::min(this_range, other_range),
|
||||
1.0, kMaxOverlapDenominator * x_height);
|
||||
double overlap = MIN(max_xheight(), other.max_xheight()) -
|
||||
MAX(min_xheight(), other.min_xheight());
|
||||
double overlap = std::min(max_xheight(), other.max_xheight()) -
|
||||
std::max(min_xheight(), other.min_xheight());
|
||||
overlap /= denominator;
|
||||
if (debug) {
|
||||
tprintf("PosAndSize for %d v %d: bl diff = %g, ranges %g, %g / %g ->%g\n",
|
||||
|
@ -215,16 +215,16 @@ class DLLSYM TBOX { // bounding box
|
||||
// overlap horizontally then the return value is negative, indicating
|
||||
// the amount of the overlap.
|
||||
int x_gap(const TBOX& box) const {
|
||||
return MAX(bot_left.x(), box.bot_left.x()) -
|
||||
MIN(top_right.x(), box.top_right.x());
|
||||
return std::max(bot_left.x(), box.bot_left.x()) -
|
||||
std::min(top_right.x(), box.top_right.x());
|
||||
}
|
||||
|
||||
// Return the vertical gap between the boxes. If the boxes
|
||||
// overlap vertically then the return value is negative, indicating
|
||||
// the amount of the overlap.
|
||||
int y_gap(const TBOX& box) const {
|
||||
return MAX(bot_left.y(), box.bot_left.y()) -
|
||||
MIN(top_right.y(), box.top_right.y());
|
||||
return std::max(bot_left.y(), box.bot_left.y()) -
|
||||
std::min(top_right.y(), box.top_right.y());
|
||||
}
|
||||
|
||||
// Do boxes overlap on x axis by more than
|
||||
@ -357,15 +357,15 @@ inline bool TBOX::overlap( // do boxes overlap
|
||||
|
||||
inline bool TBOX::major_overlap( // Do boxes overlap more that half.
|
||||
const TBOX &box) const {
|
||||
int overlap = MIN(box.top_right.x(), top_right.x());
|
||||
overlap -= MAX(box.bot_left.x(), bot_left.x());
|
||||
int overlap = std::min(box.top_right.x(), top_right.x());
|
||||
overlap -= std::max(box.bot_left.x(), bot_left.x());
|
||||
overlap += overlap;
|
||||
if (overlap < MIN(box.width(), width()))
|
||||
if (overlap < std::min(box.width(), width()))
|
||||
return false;
|
||||
overlap = MIN(box.top_right.y(), top_right.y());
|
||||
overlap -= MAX(box.bot_left.y(), bot_left.y());
|
||||
overlap = std::min(box.top_right.y(), top_right.y());
|
||||
overlap -= std::max(box.bot_left.y(), bot_left.y());
|
||||
overlap += overlap;
|
||||
if (overlap < MIN(box.height(), height()))
|
||||
if (overlap < std::min(box.height(), height()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@ -445,8 +445,8 @@ inline bool TBOX::major_y_overlap(const TBOX &box) const {
|
||||
**********************************************************************/
|
||||
|
||||
inline double TBOX::x_overlap_fraction(const TBOX& other) const {
|
||||
int low = MAX(left(), other.left());
|
||||
int high = MIN(right(), other.right());
|
||||
int low = std::max(left(), other.left());
|
||||
int high = std::min(right(), other.right());
|
||||
int width = right() - left();
|
||||
if (width == 0) {
|
||||
int x = left();
|
||||
@ -455,7 +455,7 @@ inline double TBOX::x_overlap_fraction(const TBOX& other) const {
|
||||
else
|
||||
return 0.0;
|
||||
} else {
|
||||
return MAX(0, static_cast<double>(high - low) / width);
|
||||
return std::max(0.0, static_cast<double>(high - low) / width);
|
||||
}
|
||||
}
|
||||
|
||||
@ -467,8 +467,8 @@ inline double TBOX::x_overlap_fraction(const TBOX& other) const {
|
||||
**********************************************************************/
|
||||
|
||||
inline double TBOX::y_overlap_fraction(const TBOX& other) const {
|
||||
int low = MAX(bottom(), other.bottom());
|
||||
int high = MIN(top(), other.top());
|
||||
int low = std::max(bottom(), other.bottom());
|
||||
int high = std::min(top(), other.top());
|
||||
int height = top() - bottom();
|
||||
if (height == 0) {
|
||||
int y = bottom();
|
||||
@ -477,7 +477,7 @@ inline double TBOX::y_overlap_fraction(const TBOX& other) const {
|
||||
else
|
||||
return 0.0;
|
||||
} else {
|
||||
return MAX(0, static_cast<double>(high - low) / height);
|
||||
return std::max(0.0, static_cast<double>(high - low) / height);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,8 @@
|
||||
#include "coutln.h"
|
||||
#include "tprintf.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#ifdef __UNIX__
|
||||
#include <assert.h>
|
||||
#endif
|
||||
@ -51,8 +53,8 @@ BOOL_VAR(wordrec_display_splits, 0, "Display splits");
|
||||
// Returns the bounding box of all the points in the split.
|
||||
TBOX SPLIT::bounding_box() const {
|
||||
return TBOX(
|
||||
MIN(point1->pos.x, point2->pos.x), MIN(point1->pos.y, point2->pos.y),
|
||||
MAX(point1->pos.x, point2->pos.x), MAX(point1->pos.y, point2->pos.y));
|
||||
std::min(point1->pos.x, point2->pos.x), std::min(point1->pos.y, point2->pos.y),
|
||||
std::max(point1->pos.x, point2->pos.x), std::max(point1->pos.y, point2->pos.y));
|
||||
}
|
||||
|
||||
// Hides the SPLIT so the outlines appear not to be cut by it.
|
||||
@ -91,15 +93,15 @@ float SPLIT::FullPriority(int xmin, int xmax, double overlap_knob,
|
||||
double width_change_knob) const {
|
||||
TBOX box1 = Box12();
|
||||
TBOX box2 = Box21();
|
||||
int min_left = MIN(box1.left(), box2.left());
|
||||
int max_right = MAX(box1.right(), box2.right());
|
||||
int min_left = std::min(box1.left(), box2.left());
|
||||
int max_right = std::max(box1.right(), box2.right());
|
||||
if (xmin < min_left && xmax > max_right) return kBadPriority;
|
||||
|
||||
float grade = 0.0f;
|
||||
// grade_overlap.
|
||||
int width1 = box1.width();
|
||||
int width2 = box2.width();
|
||||
int min_width = MIN(width1, width2);
|
||||
int min_width = std::min(width1, width2);
|
||||
int overlap = -box1.x_gap(box2);
|
||||
if (overlap == min_width) {
|
||||
grade += 100.0f; // Total overlap.
|
||||
@ -109,10 +111,10 @@ float SPLIT::FullPriority(int xmin, int xmax, double overlap_knob,
|
||||
}
|
||||
// grade_center_of_blob.
|
||||
if (width1 <= centered_maxwidth || width2 <= centered_maxwidth) {
|
||||
grade += MIN(kCenterGradeCap, center_knob * abs(width1 - width2));
|
||||
grade += std::min(static_cast<double>(kCenterGradeCap), center_knob * abs(width1 - width2));
|
||||
}
|
||||
// grade_width_change.
|
||||
float width_change_grade = 20 - (max_right - min_left - MAX(width1, width2));
|
||||
float width_change_grade = 20 - (max_right - min_left - std::max(width1, width2));
|
||||
if (width_change_grade > 0.0f)
|
||||
grade += width_change_grade * width_change_knob;
|
||||
return grade;
|
||||
|
@ -24,6 +24,8 @@
|
||||
#include "helpers.h"
|
||||
#include "ndminx.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
// Fast lookup table to get the first least significant set bit in a byte.
|
||||
@ -225,26 +227,26 @@ int BitVector::NumSetBits() const {
|
||||
// Logical in-place operations on whole bit vectors. Tries to do something
|
||||
// sensible if they aren't the same size, but they should be really.
|
||||
void BitVector::operator|=(const BitVector& other) {
|
||||
int length = MIN(WordLength(), other.WordLength());
|
||||
int length = std::min(WordLength(), other.WordLength());
|
||||
for (int w = 0; w < length; ++w)
|
||||
array_[w] |= other.array_[w];
|
||||
}
|
||||
void BitVector::operator&=(const BitVector& other) {
|
||||
int length = MIN(WordLength(), other.WordLength());
|
||||
int length = std::min(WordLength(), other.WordLength());
|
||||
for (int w = 0; w < length; ++w)
|
||||
array_[w] &= other.array_[w];
|
||||
for (int w = WordLength() - 1; w >= length; --w)
|
||||
array_[w] = 0;
|
||||
}
|
||||
void BitVector::operator^=(const BitVector& other) {
|
||||
int length = MIN(WordLength(), other.WordLength());
|
||||
int length = std::min(WordLength(), other.WordLength());
|
||||
for (int w = 0; w < length; ++w)
|
||||
array_[w] ^= other.array_[w];
|
||||
}
|
||||
// Set subtraction *this = v1 - v2.
|
||||
void BitVector::SetSubtract(const BitVector& v1, const BitVector& v2) {
|
||||
Alloc(v1.size());
|
||||
int length = MIN(v1.WordLength(), v2.WordLength());
|
||||
int length = std::min(v1.WordLength(), v2.WordLength());
|
||||
for (int w = 0; w < length; ++w)
|
||||
array_[w] = v1.array_[w] ^ (v1.array_[w] & v2.array_[w]);
|
||||
for (int w = WordLength() - 1; w >= length; --w)
|
||||
|
@ -20,6 +20,7 @@
|
||||
#ifndef TESSERACT_CCUTIL_GENERICVECTOR_H_
|
||||
#define TESSERACT_CCUTIL_GENERICVECTOR_H_
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
@ -298,7 +299,7 @@ class GenericVector {
|
||||
|
||||
T dot_product(const GenericVector<T>& other) const {
|
||||
T result = static_cast<T>(0);
|
||||
for (int i = MIN(size_used_, other.size_used_) - 1; i >= 0; --i)
|
||||
for (int i = std::min(size_used_, other.size_used_) - 1; i >= 0; --i)
|
||||
result += data_[i] * other.data_[i];
|
||||
return result;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "unicharset.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
@ -482,9 +483,9 @@ void UNICHARSET::AppendOtherUnicharset(const UNICHARSET& src) {
|
||||
// Returns true if the acceptable ranges of the tops of the characters do
|
||||
// not overlap, making their x-height calculations distinct.
|
||||
bool UNICHARSET::SizesDistinct(UNICHAR_ID id1, UNICHAR_ID id2) const {
|
||||
int overlap = MIN(unichars[id1].properties.max_top,
|
||||
int overlap = std::min(unichars[id1].properties.max_top,
|
||||
unichars[id2].properties.max_top) -
|
||||
MAX(unichars[id1].properties.min_top,
|
||||
std::max(unichars[id1].properties.min_top,
|
||||
unichars[id2].properties.min_top);
|
||||
return overlap <= 0;
|
||||
}
|
||||
|
@ -55,6 +55,7 @@
|
||||
#include "unicharset.h"
|
||||
#include "werd.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
@ -1370,7 +1371,7 @@ int Classify::CharNormTrainingSample(bool pruner_only,
|
||||
// Compute the char_norm_array from the saved cn_feature.
|
||||
FEATURE norm_feature = sample.GetCNFeature();
|
||||
uint8_t* char_norm_array = new uint8_t[unicharset.size()];
|
||||
int num_pruner_classes = MAX(unicharset.size(),
|
||||
int num_pruner_classes = std::max(unicharset.size(),
|
||||
PreTrainedTemplates->NumClasses);
|
||||
uint8_t* pruner_norm_array = new uint8_t[num_pruner_classes];
|
||||
adapt_results->BlobLength =
|
||||
@ -1491,7 +1492,7 @@ void Classify::ConvertMatchesToChoices(const DENORM& denorm, const TBOX& box,
|
||||
// whether adapted or static.
|
||||
// TODO(rays) find some way of automatically tuning these constants.
|
||||
if (Certainty > best_certainty) {
|
||||
best_certainty = MIN(Certainty, classify_adapted_pruning_threshold);
|
||||
best_certainty = std::min(Certainty, static_cast<float>(classify_adapted_pruning_threshold));
|
||||
} else if (adapted &&
|
||||
Certainty / classify_adapted_pruning_factor < best_certainty) {
|
||||
continue; // Don't accept bad adapted results.
|
||||
|
@ -12,6 +12,7 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
#include <algorithm>
|
||||
#include <ctime>
|
||||
|
||||
#include "errorcounter.h"
|
||||
@ -479,11 +480,11 @@ bool ErrorCounter::ComputeRates(const Counts& counts, double rates[CT_SIZE]) {
|
||||
counts.n[CT_REJECT];
|
||||
const int junk_samples = counts.n[CT_REJECTED_JUNK] + counts.n[CT_ACCEPTED_JUNK];
|
||||
// Compute rates for normal chars.
|
||||
double denominator = static_cast<double>(MAX(ok_samples, 1));
|
||||
double denominator = static_cast<double>(std::max(ok_samples, 1));
|
||||
for (int ct = 0; ct <= CT_RANK; ++ct)
|
||||
rates[ct] = counts.n[ct] / denominator;
|
||||
// Compute rates for junk.
|
||||
denominator = static_cast<double>(MAX(junk_samples, 1));
|
||||
denominator = static_cast<double>(std::max(junk_samples, 1));
|
||||
for (int ct = CT_REJECTED_JUNK; ct <= CT_ACCEPTED_JUNK; ++ct)
|
||||
rates[ct] = counts.n[ct] / denominator;
|
||||
return ok_samples != 0 || junk_samples != 0;
|
||||
|
@ -19,6 +19,7 @@
|
||||
Include Files and Type Defines
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cassert>
|
||||
@ -409,7 +410,7 @@ void AddProtoToProtoPruner(PROTO Proto, int ProtoId,
|
||||
Length = Proto->Length;
|
||||
|
||||
X = Proto->X + X_SHIFT;
|
||||
Pad = MAX (fabs (cos (Angle)) * (Length / 2.0 +
|
||||
Pad = std::max(fabs (cos (Angle)) * (Length / 2.0 +
|
||||
classify_pp_end_pad *
|
||||
GetPicoFeatureLength ()),
|
||||
fabs (sin (Angle)) * (classify_pp_side_pad *
|
||||
@ -418,7 +419,7 @@ void AddProtoToProtoPruner(PROTO Proto, int ProtoId,
|
||||
FillPPLinearBits(ProtoSet->ProtoPruner[PRUNER_X], Index, X, Pad, debug);
|
||||
|
||||
Y = Proto->Y + Y_SHIFT;
|
||||
Pad = MAX (fabs (sin (Angle)) * (Length / 2.0 +
|
||||
Pad = std::max(fabs (sin (Angle)) * (Length / 2.0 +
|
||||
classify_pp_end_pad *
|
||||
GetPicoFeatureLength ()),
|
||||
fabs (cos (Angle)) * (classify_pp_side_pad *
|
||||
|
@ -24,6 +24,8 @@
|
||||
#include "kdtree.h"
|
||||
#include "const.h"
|
||||
#include "emalloc.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
|
||||
@ -456,7 +458,7 @@ FLOAT32 DistanceSquared(int k, PARAM_DESC *dim, FLOAT32 p1[], FLOAT32 p2[]) {
|
||||
if (dim->Circular) {
|
||||
dimension_distance = Magnitude(dimension_distance);
|
||||
FLOAT32 wrap_distance = dim->Max - dim->Min - dimension_distance;
|
||||
dimension_distance = MIN(dimension_distance, wrap_distance);
|
||||
dimension_distance = std::min(dimension_distance, wrap_distance);
|
||||
}
|
||||
|
||||
total_distance += dimension_distance * dimension_distance;
|
||||
@ -500,7 +502,7 @@ bool KDTreeSearch::BoxIntersectsSearch(FLOAT32 *lower, FLOAT32 *upper) {
|
||||
wrap_distance = *query + dim->Max - dim->Min - *upper;
|
||||
else if (*query > *upper)
|
||||
wrap_distance = *lower - (*query - (dim->Max - dim->Min));
|
||||
dimension_distance = MIN(dimension_distance, wrap_distance);
|
||||
dimension_distance = std::min(dimension_distance, wrap_distance);
|
||||
}
|
||||
|
||||
total_distance += dimension_distance * dimension_distance;
|
||||
|
@ -29,6 +29,8 @@
|
||||
#include "unicharset.h"
|
||||
#include "unicity_table.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
// Helper function to get the index of the first result with the required
|
||||
@ -340,7 +342,7 @@ int ShapeTable::AddShape(int unichar_id, int font_id) {
|
||||
Shape* shape = new Shape;
|
||||
shape->AddToShape(unichar_id, font_id);
|
||||
shape_table_.push_back(shape);
|
||||
num_fonts_ = MAX(num_fonts_, font_id + 1);
|
||||
num_fonts_ = std::max(num_fonts_, font_id + 1);
|
||||
return index;
|
||||
}
|
||||
|
||||
@ -371,7 +373,7 @@ void ShapeTable::DeleteShape(int shape_id) {
|
||||
void ShapeTable::AddToShape(int shape_id, int unichar_id, int font_id) {
|
||||
Shape& shape = *shape_table_[shape_id];
|
||||
shape.AddToShape(unichar_id, font_id);
|
||||
num_fonts_ = MAX(num_fonts_, font_id + 1);
|
||||
num_fonts_ = std::max(num_fonts_, font_id + 1);
|
||||
}
|
||||
|
||||
// Adds the given shape to the existing shape with the given index.
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "trainingsample.h"
|
||||
#include "unicity_table.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
const int kTestChar = -1; // 37;
|
||||
@ -270,7 +272,7 @@ float TrainingSampleSet::UnicharDistance(const UnicharAndFonts& uf1,
|
||||
// the smaller set so as to ensure that all the pairs are different.
|
||||
int increment = kPrime1 != num_fonts2 ? kPrime1 : kPrime2;
|
||||
int index = 0;
|
||||
int num_samples = MAX(num_fonts1, num_fonts2);
|
||||
int num_samples = std::max(num_fonts1, num_fonts2);
|
||||
for (int i = 0; i < num_samples; ++i, index += increment) {
|
||||
int f1 = uf1.font_ids[i % num_fonts1];
|
||||
int f2 = uf2.font_ids[index % num_fonts2];
|
||||
@ -668,7 +670,7 @@ void TrainingSampleSet::ReplicateAndRandomizeSamples() {
|
||||
for (int c = 0; c < unicharset_size_; ++c) {
|
||||
FontClassInfo& fcinfo = (*font_class_array_)(font_index, c);
|
||||
int sample_count = fcinfo.samples.size();
|
||||
int min_samples = 2 * MAX(kSampleRandomSize, sample_count);
|
||||
int min_samples = 2 * std::max(kSampleRandomSize, sample_count);
|
||||
if (sample_count > 0 && sample_count < min_samples) {
|
||||
int base_count = sample_count;
|
||||
for (int base_index = 0; sample_count < min_samples; ++sample_count) {
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "tprintf.h"
|
||||
#include "params.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <ctype.h>
|
||||
#include "dict.h"
|
||||
|
||||
@ -376,7 +377,7 @@ bool Dict::fragment_state_okay(UNICHAR_ID curr_unichar_id,
|
||||
prev_char_frag_info->rating + curr_rating;
|
||||
char_frag_info->num_fragments = prev_char_frag_info->num_fragments + 1;
|
||||
char_frag_info->certainty =
|
||||
MIN(curr_certainty, prev_char_frag_info->certainty);
|
||||
std::min(curr_certainty, prev_char_frag_info->certainty);
|
||||
} else {
|
||||
if (this_fragment->is_beginning()) {
|
||||
if (debug) tprintf("Record fragment beginning\n");
|
||||
|
@ -17,6 +17,7 @@
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
#include "ctc.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
||||
#include "genericvector.h"
|
||||
@ -252,7 +253,7 @@ float CTC::CalculateBiasFraction() {
|
||||
// false positives, because they don't affect CTC at all.
|
||||
}
|
||||
if (total_labels == 0) return 0.0f;
|
||||
return exp(MAX(true_pos - false_pos, 1) * log(kMinProb_) / total_labels);
|
||||
return exp(std::max(true_pos - false_pos, 1) * log(kMinProb_) / total_labels);
|
||||
}
|
||||
|
||||
// Given ln(x) and ln(y), returns ln(x + y), using:
|
||||
@ -398,7 +399,7 @@ void CTC::NormalizeProbs(GENERIC_2D_ARRAY<float>* probs) {
|
||||
total += increment;
|
||||
for (int c = 0; c < num_classes; ++c) {
|
||||
float prob = probs_t[c] / total;
|
||||
probs_t[c] = MAX(prob, kMinProb_);
|
||||
probs_t[c] = std::max(prob, kMinProb_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1279,7 +1279,7 @@ void LSTMTrainer::UpdateErrorBuffer(double new_error, ErrorTypes type) {
|
||||
int index = training_iteration_ % kRollingBufferSize_;
|
||||
error_buffers_[type][index] = new_error;
|
||||
// Compute the mean error.
|
||||
int mean_count = MIN(training_iteration_ + 1, error_buffers_[type].size());
|
||||
int mean_count = std::min(training_iteration_ + 1, error_buffers_[type].size());
|
||||
double buffer_sum = 0.0;
|
||||
for (int i = 0; i < mean_count; ++i) buffer_sum += error_buffers_[type][i];
|
||||
double mean = buffer_sum / mean_count;
|
||||
|
@ -309,7 +309,7 @@ void Network::DisplayBackward(const NetworkIO& matrix) {
|
||||
void Network::ClearWindow(bool tess_coords, const char* window_name,
|
||||
int width, int height, ScrollView** window) {
|
||||
if (*window == nullptr) {
|
||||
int min_size = MIN(width, height);
|
||||
int min_size = std::min(width, height);
|
||||
if (min_size < kMinWinSize) {
|
||||
if (min_size < 1) min_size = 1;
|
||||
width = width * kMinWinSize / min_size;
|
||||
|
@ -23,6 +23,8 @@
|
||||
#include "pageres.h"
|
||||
#include "unicharcompress.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
// Clipping value for certainty inside Tesseract. Reflects the minimum value
|
||||
@ -185,7 +187,7 @@ void RecodeBeamSearch::ExtractBestPathAsWords(const TBOX& line_box,
|
||||
// Create a WERD_RES for the output word.
|
||||
WERD_RES* word_res = InitializeWord(
|
||||
leading_space, line_box, word_start, word_end,
|
||||
MIN(space_cert, prev_space_cert), unicharset, xcoords, scale_factor);
|
||||
std::min(space_cert, prev_space_cert), unicharset, xcoords, scale_factor);
|
||||
for (int i = word_start; i < word_end; ++i) {
|
||||
BLOB_CHOICE_LIST* choices = new BLOB_CHOICE_LIST;
|
||||
BLOB_CHOICE_IT bc_it(choices);
|
||||
|
@ -24,6 +24,8 @@
|
||||
#include "alignedblob.h"
|
||||
#include "ndminx.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
INT_VAR(textord_debug_tabfind, 0, "Debug tab finding");
|
||||
INT_VAR(textord_debug_bugs, 0, "Turn on output related to bugs in tab finding");
|
||||
INT_VAR(textord_testregion_left, -1, "Left edge of debug reporting rectangle");
|
||||
@ -123,8 +125,8 @@ AlignedBlobParams::AlignedBlobParams(int vertical_x, int vertical_y,
|
||||
min_points(1),
|
||||
min_length(kVLineMinLength) {
|
||||
// Compute threshold for left and right alignment.
|
||||
l_align_tolerance = MAX(kVLineAlignment, width);
|
||||
r_align_tolerance = MAX(kVLineAlignment, width);
|
||||
l_align_tolerance = std::max(kVLineAlignment, width);
|
||||
r_align_tolerance = std::max(kVLineAlignment, width);
|
||||
|
||||
// Fit the vertical vector into an ICOORD, which is 16 bit.
|
||||
set_vertical(vertical_x, vertical_y);
|
||||
@ -394,8 +396,8 @@ BLOBNBOX* AlignedBlob::FindAlignedBlob(const AlignedBlobParams& p,
|
||||
*end_y = start_y + p.max_v_gap;
|
||||
}
|
||||
// Expand the box by an additional skew tolerance
|
||||
int xmin = MIN(x_start, x2) - skew_tolerance;
|
||||
int xmax = MAX(x_start, x2) + skew_tolerance;
|
||||
int xmin = std::min(x_start, x2) - skew_tolerance;
|
||||
int xmax = std::max(x_start, x2) + skew_tolerance;
|
||||
// Now add direction-specific tolerances.
|
||||
if (p.right_tab) {
|
||||
xmax += p.min_gutter;
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
#include "baselinedetect.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include "allheaders.h"
|
||||
#include "blobbox.h"
|
||||
@ -107,8 +108,8 @@ double BaselineRow::BaselineAngle() const {
|
||||
// between this and other.
|
||||
double BaselineRow::SpaceBetween(const BaselineRow& other) const {
|
||||
// Find the x-centre of overlap of the lines.
|
||||
float x = (MAX(bounding_box_.left(), other.bounding_box_.left()) +
|
||||
MIN(bounding_box_.right(), other.bounding_box_.right())) / 2.0f;
|
||||
float x = (std::max(bounding_box_.left(), other.bounding_box_.left()) +
|
||||
std::min(bounding_box_.right(), other.bounding_box_.right())) / 2.0f;
|
||||
// Find the vertical centre between them.
|
||||
float y = (StraightYAtX(x) + other.StraightYAtX(x)) / 2.0f;
|
||||
// Find the perpendicular distance of (x,y) from each line.
|
||||
@ -506,7 +507,7 @@ void BaselineBlock::ParallelizeBaselines(double default_block_skew) {
|
||||
void BaselineBlock::SetupBlockParameters() const {
|
||||
if (line_spacing_ > 0.0) {
|
||||
// Where was block_line_spacing set before?
|
||||
float min_spacing = MIN(block_->line_spacing, line_spacing_);
|
||||
float min_spacing = std::min(block_->line_spacing, static_cast<float>(line_spacing_));
|
||||
if (min_spacing < block_->line_size)
|
||||
block_->line_size = min_spacing;
|
||||
block_->line_spacing = line_spacing_;
|
||||
|
@ -23,6 +23,8 @@
|
||||
#include "topitch.h"
|
||||
#include "tovars.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
BOOL_VAR(textord_space_size_is_variable, FALSE,
|
||||
"If true, word delimiter spaces are assumed to have "
|
||||
"variable width, even though characters have fixed pitch.");
|
||||
@ -399,8 +401,8 @@ class FPRow {
|
||||
|
||||
private:
|
||||
static float x_overlap_fraction(const TBOX& box1, const TBOX& box2) {
|
||||
if (MIN(box1.width(), box2.width()) == 0) return 0.0;
|
||||
return -box1.x_gap(box2) / (float)MIN(box1.width(), box2.width());
|
||||
if (std::min(box1.width(), box2.width()) == 0) return 0.0;
|
||||
return -box1.x_gap(box2) / (float)std::min(box1.width(), box2.width());
|
||||
}
|
||||
|
||||
static bool mostly_overlap(const TBOX& box1, const TBOX& box2) {
|
||||
@ -408,7 +410,7 @@ class FPRow {
|
||||
}
|
||||
|
||||
static bool significant_overlap(const TBOX& box1, const TBOX& box2) {
|
||||
if (MIN(box1.width(), box2.width()) == 0) return false;
|
||||
if (std::min(box1.width(), box2.width()) == 0) return false;
|
||||
int overlap = -box1.x_gap(box2);
|
||||
return overlap > 1 || x_overlap_fraction(box1, box2) > 0.1;
|
||||
}
|
||||
@ -521,7 +523,7 @@ void FPRow::OutputEstimations() {
|
||||
// are skinny. Use pitch_ - height_ instead if it's smaller, but
|
||||
// positive.
|
||||
real_row_->kern_size = real_row_->pr_nonsp =
|
||||
MIN(good_gaps_.ile(0.125), MAX(pitch_ - height_, 0));
|
||||
std::min(good_gaps_.ile(0.125), std::max(pitch_ - height_, 0.0f));
|
||||
real_row_->body_size = pitch_ - real_row_->kern_size;
|
||||
|
||||
if (good_pitches_.size() < all_pitches_.size() * kFixedPitchThreshold) {
|
||||
@ -546,12 +548,12 @@ void FPRow::OutputEstimations() {
|
||||
|
||||
// Don't consider a quarter space as a real space, because it's used
|
||||
// for line justification in traditional Japanese books.
|
||||
real_row_->max_nonspace = MAX(pitch_ * 0.25 + good_gaps_.minimum(),
|
||||
real_row_->max_nonspace = std::max(pitch_ * 0.25 + good_gaps_.minimum(),
|
||||
(double)good_gaps_.ile(0.875));
|
||||
|
||||
int space_threshold =
|
||||
MIN((real_row_->max_nonspace + real_row_->min_space) / 2,
|
||||
real_row_->xheight);
|
||||
std::min((real_row_->max_nonspace + real_row_->min_space) / 2,
|
||||
static_cast<int>(real_row_->xheight));
|
||||
|
||||
// Make max_nonspace larger than any intra-character gap so that
|
||||
// make_prop_words() won't break a row at the middle of a character.
|
||||
@ -561,8 +563,8 @@ void FPRow::OutputEstimations() {
|
||||
}
|
||||
}
|
||||
real_row_->space_threshold =
|
||||
MIN((real_row_->max_nonspace + real_row_->min_space) / 2,
|
||||
real_row_->xheight);
|
||||
std::min((real_row_->max_nonspace + real_row_->min_space) / 2,
|
||||
static_cast<int>(real_row_->xheight));
|
||||
real_row_->used_dm_model = false;
|
||||
|
||||
// Setup char_cells.
|
||||
@ -616,7 +618,7 @@ void FPRow::EstimatePitch(bool pass1) {
|
||||
for (int i = 1; i < num_chars(); i++) {
|
||||
cx1 = center_x(i);
|
||||
int32_t pitch = cx1 - cx0;
|
||||
int32_t gap = MAX(0, real_body(i - 1).x_gap(real_body(i)));
|
||||
int32_t gap = std::max(0, real_body(i - 1).x_gap(real_body(i)));
|
||||
|
||||
heights_.Add(box(i).height());
|
||||
// Ignore if the pitch is too close. But don't ignore wide pitch
|
||||
|
@ -38,6 +38,8 @@
|
||||
#include "params.h"
|
||||
#include "workingpartset.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
// When assigning columns, the max number of misfit grid rows/ColPartitionSets
|
||||
@ -1106,8 +1108,8 @@ void ColumnFinder::GridMergePartitions() {
|
||||
if (neighbour_box.right() < part->left_margin() &&
|
||||
part_box.left() > neighbour->right_margin())
|
||||
continue; // Neighbour is too far to the left.
|
||||
int h_gap = MAX(part_box.left(), neighbour_box.left()) -
|
||||
MIN(part_box.right(), neighbour_box.right());
|
||||
int h_gap = std::max(part_box.left(), neighbour_box.left()) -
|
||||
std::min(part_box.right(), neighbour_box.right());
|
||||
if (h_gap < mean_column_gap_ * kHorizontalGapMergeFraction ||
|
||||
part_box.width() < mean_column_gap_ ||
|
||||
neighbour_box.width() < mean_column_gap_) {
|
||||
@ -1199,8 +1201,8 @@ void ColumnFinder::InsertRemainingNoise(TO_BLOCK* block) {
|
||||
|
||||
// Helper makes a box from a horizontal line.
|
||||
static TBOX BoxFromHLine(const TabVector* hline) {
|
||||
int top = MAX(hline->startpt().y(), hline->endpt().y());
|
||||
int bottom = MIN(hline->startpt().y(), hline->endpt().y());
|
||||
int top = std::max(hline->startpt().y(), hline->endpt().y());
|
||||
int bottom = std::min(hline->startpt().y(), hline->endpt().y());
|
||||
top += hline->mean_width();
|
||||
if (top == bottom) {
|
||||
if (bottom > 0)
|
||||
@ -1285,8 +1287,8 @@ void ColumnFinder::GridInsertVLinePartitions() {
|
||||
TabVector* vline = vline_it.data();
|
||||
if (!vline->IsSeparator())
|
||||
continue;
|
||||
int left = MIN(vline->startpt().x(), vline->endpt().x());
|
||||
int right = MAX(vline->startpt().x(), vline->endpt().x());
|
||||
int left = std::min(vline->startpt().x(), vline->endpt().x());
|
||||
int right = std::max(vline->startpt().x(), vline->endpt().x());
|
||||
right += vline->mean_width();
|
||||
if (left == right) {
|
||||
if (left > 0)
|
||||
|
@ -30,6 +30,8 @@
|
||||
#include "imagefind.h"
|
||||
#include "workingpartset.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
ELIST2IZE(ColPartition)
|
||||
@ -682,8 +684,8 @@ void ColPartition::Absorb(ColPartition* other, WidthCallback* cb) {
|
||||
bbox2->set_owner(this);
|
||||
it.add_to_end(bbox2);
|
||||
}
|
||||
left_margin_ = MIN(left_margin_, other->left_margin_);
|
||||
right_margin_ = MAX(right_margin_, other->right_margin_);
|
||||
left_margin_ = std::min(left_margin_, other->left_margin_);
|
||||
right_margin_ = std::max(right_margin_, other->right_margin_);
|
||||
if (other->left_key_ < left_key_) {
|
||||
left_key_ = other->left_key_;
|
||||
left_key_tab_ = other->left_key_tab_;
|
||||
@ -979,7 +981,7 @@ void ColPartition::SetPartitionType(int resolution, ColPartitionSet* columns) {
|
||||
ColumnSpanningType span_type =
|
||||
columns->SpanningType(resolution,
|
||||
bounding_box_.left(), bounding_box_.right(),
|
||||
MIN(bounding_box_.height(), bounding_box_.width()),
|
||||
std::min(bounding_box_.height(), bounding_box_.width()),
|
||||
MidY(), left_margin_, right_margin_,
|
||||
&first_column_, &last_column_,
|
||||
&first_spanned_col);
|
||||
@ -1063,7 +1065,7 @@ void ColPartition::ColumnRange(int resolution, ColPartitionSet* columns,
|
||||
ColumnSpanningType span_type =
|
||||
columns->SpanningType(resolution,
|
||||
bounding_box_.left(), bounding_box_.right(),
|
||||
MIN(bounding_box_.height(), bounding_box_.width()),
|
||||
std::min(bounding_box_.height(), bounding_box_.width()),
|
||||
MidY(), left_margin_, right_margin_,
|
||||
first_col, last_col,
|
||||
&first_spanned_col);
|
||||
@ -1107,8 +1109,8 @@ bool ColPartition::MarkAsLeaderIfMonospaced() {
|
||||
}
|
||||
double median_gap = gap_stats.median();
|
||||
double median_width = width_stats.median();
|
||||
double max_width = MAX(median_gap, median_width);
|
||||
double min_width = MIN(median_gap, median_width);
|
||||
double max_width = std::max(median_gap, median_width);
|
||||
double min_width = std::min(median_gap, median_width);
|
||||
double gap_iqr = gap_stats.ile(0.75f) - gap_stats.ile(0.25f);
|
||||
if (textord_debug_tabfind >= 4) {
|
||||
tprintf("gap iqr = %g, blob_count=%d, limits=%g,%g\n",
|
||||
@ -1559,7 +1561,7 @@ static TO_BLOCK* MoveBlobsToBlock(bool vertical_text, int line_spacing,
|
||||
// that have have to continue to exist until the part grid is deleted.
|
||||
// Compute the median blob size as we go, as the block needs to know.
|
||||
TBOX block_box(block->pdblk.bounding_box());
|
||||
STATS sizes(0, MAX(block_box.width(), block_box.height()));
|
||||
STATS sizes(0, std::max(block_box.width(), block_box.height()));
|
||||
bool text_type = block->pdblk.poly_block()->IsText();
|
||||
ColPartition_IT it(block_parts);
|
||||
TO_BLOCK* to_block = new TO_BLOCK(block);
|
||||
@ -2099,8 +2101,8 @@ void ColPartition::RefinePartnersByOverlap(bool upper,
|
||||
int best_overlap = 0;
|
||||
for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
|
||||
ColPartition* partner = it.data();
|
||||
int overlap = MIN(bounding_box_.right(), partner->bounding_box_.right())
|
||||
- MAX(bounding_box_.left(), partner->bounding_box_.left());
|
||||
int overlap = std::min(bounding_box_.right(), partner->bounding_box_.right())
|
||||
- std::max(bounding_box_.left(), partner->bounding_box_.left());
|
||||
if (overlap > best_overlap) {
|
||||
best_overlap = overlap;
|
||||
best_partner = partner;
|
||||
@ -2133,9 +2135,9 @@ bool ColPartition::ThisPartitionBetter(BLOBNBOX* bbox,
|
||||
return true;
|
||||
int top = box.top();
|
||||
int bottom = box.bottom();
|
||||
int this_overlap = MIN(top, median_top_) - MAX(bottom, median_bottom_);
|
||||
int other_overlap = MIN(top, other.median_top_) -
|
||||
MAX(bottom, other.median_bottom_);
|
||||
int this_overlap = std::min(top, median_top_) - std::max(bottom, median_bottom_);
|
||||
int other_overlap = std::min(top, other.median_top_) -
|
||||
std::max(bottom, other.median_bottom_);
|
||||
int this_miss = median_top_ - median_bottom_ - this_overlap;
|
||||
int other_miss = other.median_top_ - other.median_bottom_ - other_overlap;
|
||||
if (TabFind::WithinTestRegion(3, box.left(), box.bottom())) {
|
||||
@ -2358,9 +2360,9 @@ bool ColPartition::SpacingEqual(int spacing, int resolution) const {
|
||||
// match to within suitable margins dictated by the image resolution.
|
||||
bool ColPartition::SpacingsEqual(const ColPartition& other,
|
||||
int resolution) const {
|
||||
int bottom_error = MAX(BottomSpacingMargin(resolution),
|
||||
int bottom_error = std::max(BottomSpacingMargin(resolution),
|
||||
other.BottomSpacingMargin(resolution));
|
||||
int top_error = MAX(TopSpacingMargin(resolution),
|
||||
int top_error = std::max(TopSpacingMargin(resolution),
|
||||
other.TopSpacingMargin(resolution));
|
||||
return NearlyEqual(bottom_spacing_, other.bottom_spacing_, bottom_error) &&
|
||||
(NearlyEqual(top_spacing_, other.top_spacing_, top_error) ||
|
||||
@ -2373,9 +2375,9 @@ bool ColPartition::SpacingsEqual(const ColPartition& other,
|
||||
// by the image resolution.
|
||||
bool ColPartition::SummedSpacingOK(const ColPartition& other,
|
||||
int spacing, int resolution) const {
|
||||
int bottom_error = MAX(BottomSpacingMargin(resolution),
|
||||
int bottom_error = std::max(BottomSpacingMargin(resolution),
|
||||
other.BottomSpacingMargin(resolution));
|
||||
int top_error = MAX(TopSpacingMargin(resolution),
|
||||
int top_error = std::max(TopSpacingMargin(resolution),
|
||||
other.TopSpacingMargin(resolution));
|
||||
int bottom_total = bottom_spacing_ + other.bottom_spacing_;
|
||||
int top_total = top_spacing_ + other.top_spacing_;
|
||||
@ -2417,12 +2419,12 @@ static bool UpdateLeftMargin(const ColPartition& part,
|
||||
int tr_key = part.SortKey(part_box.left(), top);
|
||||
int bl_key = part.SortKey(part.left_margin(), bottom);
|
||||
int br_key = part.SortKey(part_box.left(), bottom);
|
||||
int left_key = MAX(tl_key, bl_key);
|
||||
int right_key = MIN(tr_key, br_key);
|
||||
int left_key = std::max(tl_key, bl_key);
|
||||
int right_key = std::min(tr_key, br_key);
|
||||
if (left_key <= *margin_right && right_key >= *margin_left) {
|
||||
// This part is good - let's keep it.
|
||||
*margin_right = MIN(*margin_right, right_key);
|
||||
*margin_left = MAX(*margin_left, left_key);
|
||||
*margin_right = std::min(*margin_right, right_key);
|
||||
*margin_left = std::max(*margin_left, left_key);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -2503,12 +2505,12 @@ static bool UpdateRightMargin(const ColPartition& part,
|
||||
int tr_key = part.SortKey(part.right_margin(), top);
|
||||
int bl_key = part.SortKey(part_box.right(), bottom);
|
||||
int br_key = part.SortKey(part.right_margin(), bottom);
|
||||
int left_key = MAX(tl_key, bl_key);
|
||||
int right_key = MIN(tr_key, br_key);
|
||||
int left_key = std::max(tl_key, bl_key);
|
||||
int right_key = std::min(tr_key, br_key);
|
||||
if (left_key <= *margin_right && right_key >= *margin_left) {
|
||||
// This part is good - let's keep it.
|
||||
*margin_right = MIN(*margin_right, right_key);
|
||||
*margin_left = MAX(*margin_left, left_key);
|
||||
*margin_right = std::min(*margin_right, right_key);
|
||||
*margin_left = std::max(*margin_left, left_key);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -30,6 +30,8 @@
|
||||
#include "tabfind.h" // For WidthCallback.
|
||||
#include "tabvector.h" // For BLOBNBOX_CLIST.
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
// Number of colors in the color1, color2 arrays.
|
||||
@ -373,20 +375,20 @@ class ColPartition : public ELIST2_LINK {
|
||||
// Returns the vertical overlap (by median) of this and other.
|
||||
// WARNING! Only makes sense on horizontal partitions!
|
||||
int VCoreOverlap(const ColPartition& other) const {
|
||||
return MIN(median_top_, other.median_top_) -
|
||||
MAX(median_bottom_, other.median_bottom_);
|
||||
return std::min(median_top_, other.median_top_) -
|
||||
std::max(median_bottom_, other.median_bottom_);
|
||||
}
|
||||
// Returns the horizontal overlap (by median) of this and other.
|
||||
// WARNING! Only makes sense on vertical partitions!
|
||||
int HCoreOverlap(const ColPartition& other) const {
|
||||
return MIN(median_right_, other.median_right_) -
|
||||
MAX(median_left_, other.median_left_);
|
||||
return std::min(median_right_, other.median_right_) -
|
||||
std::max(median_left_, other.median_left_);
|
||||
}
|
||||
// Returns true if this and other overlap significantly vertically.
|
||||
// WARNING! Only makes sense on horizontal partitions!
|
||||
bool VSignificantCoreOverlap(const ColPartition& other) const {
|
||||
int overlap = VCoreOverlap(other);
|
||||
int height = MIN(median_top_ - median_bottom_,
|
||||
int height = std::min(median_top_ - median_bottom_,
|
||||
other.median_top_ - other.median_bottom_);
|
||||
return overlap * 3 > height;
|
||||
}
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "colpartitionset.h"
|
||||
#include "imagefind.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
BOOL_VAR(textord_tabfind_show_color_fit, false, "Show stroke widths");
|
||||
@ -201,7 +203,7 @@ static bool OKMergeCandidate(const ColPartition* part,
|
||||
// Candidates must be within a reasonable distance.
|
||||
if (candidate->IsVerticalType() || part->IsVerticalType()) {
|
||||
int h_dist = -part->HCoreOverlap(*candidate);
|
||||
if (h_dist >= MAX(part_box.width(), c_box.width()) / 2) {
|
||||
if (h_dist >= std::max(part_box.width(), c_box.width()) / 2) {
|
||||
if (debug)
|
||||
tprintf("Too far away: h_dist = %d\n", h_dist);
|
||||
return false;
|
||||
@ -209,7 +211,7 @@ static bool OKMergeCandidate(const ColPartition* part,
|
||||
} else {
|
||||
// Coarse filter by vertical distance between partitions.
|
||||
int v_dist = -part->VCoreOverlap(*candidate);
|
||||
if (v_dist >= MAX(part_box.height(), c_box.height()) / 2) {
|
||||
if (v_dist >= std::max(part_box.height(), c_box.height()) / 2) {
|
||||
if (debug)
|
||||
tprintf("Too far away: v_dist = %d\n", v_dist);
|
||||
return false;
|
||||
@ -1412,8 +1414,8 @@ bool ColPartitionGrid::SmoothRegionType(Pix* nontext_map,
|
||||
}
|
||||
BlobRegionType best_type = BRT_UNKNOWN;
|
||||
int best_dist = INT32_MAX;
|
||||
int max_dist = MIN(part_box.width(), part_box.height());
|
||||
max_dist = MAX(max_dist * kMaxNeighbourDistFactor, gridsize() * 2);
|
||||
int max_dist = std::min(part_box.width(), part_box.height());
|
||||
max_dist = std::max(max_dist * kMaxNeighbourDistFactor, gridsize() * 2);
|
||||
// Search with the pad truncated on each side of the box in turn.
|
||||
bool any_image = false;
|
||||
bool all_image = true;
|
||||
@ -1477,8 +1479,8 @@ static void ComputeSearchBoxAndScaling(BlobNeighbourDir direction,
|
||||
*search_box = part_box;
|
||||
// Generate a pad value based on the min dimension of part_box, but at least
|
||||
// min_padding and then scaled by kMaxPadFactor.
|
||||
int padding = MIN(part_box.height(), part_box.width());
|
||||
padding = MAX(padding, min_padding);
|
||||
int padding = std::min(part_box.height(), part_box.width());
|
||||
padding = std::max(padding, min_padding);
|
||||
padding *= kMaxPadFactor;
|
||||
search_box->pad(padding, padding);
|
||||
// Truncate the box in the appropriate direction and make the distance
|
||||
@ -1635,8 +1637,8 @@ void ColPartitionGrid::AccumulatePartDistances(const ColPartition& base_part,
|
||||
continue; // Text not visible the other side of image.
|
||||
if (BLOBNBOX::IsLineType(n_type))
|
||||
continue; // Don't use horizontal lines as neighbours.
|
||||
int x_gap = MAX(part_box.x_gap(nbox), 0);
|
||||
int y_gap = MAX(part_box.y_gap(nbox), 0);
|
||||
int x_gap = std::max(part_box.x_gap(nbox), 0);
|
||||
int y_gap = std::max(part_box.y_gap(nbox), 0);
|
||||
int n_dist = x_gap * dist_scaling.x() + y_gap* dist_scaling.y();
|
||||
if (debug) {
|
||||
tprintf("Part has x-gap=%d, y=%d, dist=%d at:",
|
||||
@ -1644,7 +1646,7 @@ void ColPartitionGrid::AccumulatePartDistances(const ColPartition& base_part,
|
||||
nbox.print();
|
||||
}
|
||||
// Truncate the number of boxes, so text doesn't get too much advantage.
|
||||
int n_boxes = MIN(neighbour->boxes_count(), kSmoothDecisionMargin);
|
||||
int n_boxes = std::min(neighbour->boxes_count(), kSmoothDecisionMargin);
|
||||
BlobTextFlowType n_flow = neighbour->flow();
|
||||
GenericVector<int>* count_vector = nullptr;
|
||||
if (n_flow == BTFT_STRONG_CHAIN) {
|
||||
@ -1730,9 +1732,9 @@ int ColPartitionGrid::FindMargin(int x, bool right_to_left, int x_limit,
|
||||
// Must overlap by enough, based on the min of the heights, so
|
||||
// large partitions can't smash through small ones.
|
||||
TBOX box = part->bounding_box();
|
||||
int min_overlap = MIN(height, box.height());
|
||||
int min_overlap = std::min(height, static_cast<int>(box.height()));
|
||||
min_overlap = static_cast<int>(min_overlap * kMarginOverlapFraction + 0.5);
|
||||
int y_overlap = MIN(y_top, box.top()) - MAX(y_bottom, box.bottom());
|
||||
int y_overlap = std::min(y_top, static_cast<int>(box.top())) - std::max(y_bottom, static_cast<int>(box.bottom()));
|
||||
if (y_overlap < min_overlap)
|
||||
continue;
|
||||
// Must be going the right way.
|
||||
|
@ -31,6 +31,8 @@
|
||||
|
||||
#include "allheaders.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
INT_VAR(textord_tabfind_show_images, false, "Show image blobs");
|
||||
|
||||
namespace tesseract {
|
||||
@ -420,12 +422,12 @@ void ImageFind::ComputeRectangleColors(const TBOX& rect, Pix* pix, int factor,
|
||||
// background.
|
||||
int width = pixGetWidth(pix);
|
||||
int height = pixGetHeight(pix);
|
||||
int left_pad = MAX(rect.left() - 2 * factor, 0) / factor;
|
||||
int left_pad = std::max(rect.left() - 2 * factor, 0) / factor;
|
||||
int top_pad = (rect.top() + 2 * factor + (factor - 1)) / factor;
|
||||
top_pad = MIN(height, top_pad);
|
||||
top_pad = std::min(height, top_pad);
|
||||
int right_pad = (rect.right() + 2 * factor + (factor - 1)) / factor;
|
||||
right_pad = MIN(width, right_pad);
|
||||
int bottom_pad = MAX(rect.bottom() - 2 * factor, 0) / factor;
|
||||
right_pad = std::min(width, right_pad);
|
||||
int bottom_pad = std::max(rect.bottom() - 2 * factor, 0) / factor;
|
||||
int width_pad = right_pad - left_pad;
|
||||
int height_pad = top_pad - bottom_pad;
|
||||
if (width_pad < 1 || height_pad < 1 || width_pad + height_pad < 4)
|
||||
@ -581,13 +583,13 @@ bool ImageFind::BlankImageInBetween(const TBOX& box1, const TBOX& box2,
|
||||
if (box1.x_gap(box2) >= box1.y_gap(box2)) {
|
||||
if (box1.x_gap(box2) <= 0)
|
||||
return true;
|
||||
search_box.set_left(MIN(box1.right(), box2.right()));
|
||||
search_box.set_right(MAX(box1.left(), box2.left()));
|
||||
search_box.set_left(std::min(box1.right(), box2.right()));
|
||||
search_box.set_right(std::max(box1.left(), box2.left()));
|
||||
} else {
|
||||
if (box1.y_gap(box2) <= 0)
|
||||
return true;
|
||||
search_box.set_top(MAX(box1.bottom(), box2.bottom()));
|
||||
search_box.set_bottom(MIN(box1.top(), box2.top()));
|
||||
search_box.set_top(std::max(box1.bottom(), box2.bottom()));
|
||||
search_box.set_bottom(std::min(box1.top(), box2.top()));
|
||||
}
|
||||
return CountPixelsInRotatedBox(search_box, im_box, rotation, pix) == 0;
|
||||
}
|
||||
@ -1070,8 +1072,8 @@ static bool ExpandImageIntoParts(const TBOX& max_image_box,
|
||||
DeletePartition(part);
|
||||
continue;
|
||||
}
|
||||
int x_dist = MAX(0, box.x_gap(im_part_box));
|
||||
int y_dist = MAX(0, box.y_gap(im_part_box));
|
||||
int x_dist = std::max(0, box.x_gap(im_part_box));
|
||||
int y_dist = std::max(0, box.y_gap(im_part_box));
|
||||
int dist = x_dist * x_dist + y_dist * y_dist;
|
||||
if (dist > box.area() || dist > im_part_box.area())
|
||||
continue; // Not close enough.
|
||||
|
@ -31,6 +31,8 @@
|
||||
|
||||
#include "allheaders.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
/// Denominator of resolution makes max pixel width to allow thin lines.
|
||||
@ -152,13 +154,13 @@ static int CountPixelsAdjacentToLine(int line_width, Box* line_box,
|
||||
boxGetGeometry(line_box, &x, &y, &box_width, &box_height);
|
||||
if (box_width > box_height) {
|
||||
// horizontal line.
|
||||
int bottom = MIN(pixGetHeight(nonline_pix), y + box_height + line_width);
|
||||
y = MAX(0, y - line_width);
|
||||
int bottom = std::min(pixGetHeight(nonline_pix), y + box_height + line_width);
|
||||
y = std::max(0, y - line_width);
|
||||
box_height = bottom - y;
|
||||
} else {
|
||||
// Vertical line.
|
||||
int right = MIN(pixGetWidth(nonline_pix), x + box_width + line_width);
|
||||
x = MAX(0, x - line_width);
|
||||
int right = std::min(pixGetWidth(nonline_pix), x + box_width + line_width);
|
||||
x = std::max(0, x - line_width);
|
||||
box_width = right - x;
|
||||
}
|
||||
Box* box = boxCreate(x, y, box_width, box_height);
|
||||
|
@ -41,6 +41,8 @@
|
||||
#include "config_auto.h"
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
BOOL_VAR(textord_heavy_nr, FALSE, "Vigorously remove noise");
|
||||
BOOL_VAR(textord_show_initial_rows, FALSE, "Display row accumulation");
|
||||
BOOL_VAR(textord_show_parallel_rows, FALSE, "Display page correlated rows");
|
||||
@ -391,8 +393,8 @@ static bool dot_of_i(BLOBNBOX* dot, BLOBNBOX* i, TO_ROW* row) {
|
||||
const TBOX& dotbox = dot->bounding_box();
|
||||
|
||||
// Must overlap horizontally by enough and be high enough.
|
||||
int overlap = MIN(dotbox.right(), ibox.right()) -
|
||||
MAX(dotbox.left(), ibox.left());
|
||||
int overlap = std::min(dotbox.right(), ibox.right()) -
|
||||
std::max(dotbox.left(), ibox.left());
|
||||
if (ibox.height() <= 2 * dotbox.height() ||
|
||||
(overlap * 2 < ibox.width() && overlap < dotbox.width()))
|
||||
return false;
|
||||
@ -405,7 +407,7 @@ static bool dot_of_i(BLOBNBOX* dot, BLOBNBOX* i, TO_ROW* row) {
|
||||
// So search the outline for a piece of large height close to the edges
|
||||
// of the dot.
|
||||
const double kHeightFraction = 0.6;
|
||||
double target_height = MIN(dotbox.bottom(), ibox.top());
|
||||
double target_height = std::min(dotbox.bottom(), ibox.top());
|
||||
target_height -= row->line_m()*dotbox.left() + row->line_c();
|
||||
target_height *= kHeightFraction;
|
||||
int left_min = dotbox.left() - dotbox.width();
|
||||
|
@ -18,20 +18,22 @@
|
||||
**********************************************************************/
|
||||
|
||||
#include "ccstruct.h"
|
||||
#include "statistc.h"
|
||||
#include "quadlsq.h"
|
||||
#include "detlinefit.h"
|
||||
#include "makerow.h"
|
||||
#include "drawtord.h"
|
||||
#include "oldbasel.h"
|
||||
#include "textord.h"
|
||||
#include "tprintf.h"
|
||||
#include "statistc.h"
|
||||
#include "quadlsq.h"
|
||||
#include "detlinefit.h"
|
||||
#include "makerow.h"
|
||||
#include "drawtord.h"
|
||||
#include "oldbasel.h"
|
||||
#include "textord.h"
|
||||
#include "tprintf.h"
|
||||
|
||||
// Include automatically generated configuration file if running autoconf.
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config_auto.h"
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#define EXTERN
|
||||
|
||||
EXTERN BOOL_VAR (textord_really_old_xheight, FALSE,
|
||||
@ -204,7 +206,7 @@ void Textord::correlate_neighbours(TO_BLOCK *block, // block rows are in.
|
||||
if (row->xheight < 0) /*linear failed */
|
||||
/*make do */
|
||||
row->xheight = -row->xheight;
|
||||
biggest = MAX (biggest, row->xheight);
|
||||
biggest = std::max(biggest, row->xheight);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1624,8 +1626,8 @@ void pick_x_height(TO_ROW * row, //row to do
|
||||
if (modelist[x] && modelist[y] &&
|
||||
heightstat->pile_count (modelist[x]) > mode_threshold &&
|
||||
(!textord_ocropus_mode ||
|
||||
MIN(rights[modelist[x]], rights[modelist[y]]) >
|
||||
MAX(lefts[modelist[x]], lefts[modelist[y]]))) {
|
||||
std::min(rights[modelist[x]], rights[modelist[y]]) >
|
||||
std::max(lefts[modelist[x]], lefts[modelist[y]]))) {
|
||||
ratio = (float) modelist[y] / (float) modelist[x];
|
||||
if (1.2 < ratio && ratio < 1.8) {
|
||||
/* Two modes found */
|
||||
@ -1638,8 +1640,8 @@ void pick_x_height(TO_ROW * row, //row to do
|
||||
for (z = 0; z < MODENUM; z++) {
|
||||
if (modelist[z] == best_x_height + 1 &&
|
||||
(!textord_ocropus_mode ||
|
||||
MIN(rights[modelist[x]], rights[modelist[y]]) >
|
||||
MAX(lefts[modelist[x]], lefts[modelist[y]]))) {
|
||||
std::min(rights[modelist[x]], rights[modelist[y]]) >
|
||||
std::max(lefts[modelist[x]], lefts[modelist[y]]))) {
|
||||
ratio = (float) modelist[y] / (float) modelist[z];
|
||||
if ((1.2 < ratio && ratio < 1.8) &&
|
||||
/* Should be half of best */
|
||||
@ -1665,8 +1667,8 @@ void pick_x_height(TO_ROW * row, //row to do
|
||||
for (z = 0; z < MODENUM; z++) {
|
||||
if (modelist[z] > best_asc &&
|
||||
(!textord_ocropus_mode ||
|
||||
MIN(rights[modelist[x]], rights[modelist[y]]) >
|
||||
MAX(lefts[modelist[x]], lefts[modelist[y]]))) {
|
||||
std::min(rights[modelist[x]], rights[modelist[y]]) >
|
||||
std::max(lefts[modelist[x]], lefts[modelist[y]]))) {
|
||||
ratio = (float) modelist[z] / (float) best_x_height;
|
||||
if ((1.2 < ratio && ratio < 1.8) &&
|
||||
/* Should be half of best */
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include "strokewidth.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include "blobbox.h"
|
||||
@ -895,8 +896,8 @@ int StrokeWidth::FindGoodNeighbour(BlobNeighbourDir dir, bool leaders,
|
||||
// being larger than a multiple of the min dimension of the line
|
||||
// and the larger dimension being smaller than a fraction of the max
|
||||
// dimension of the line.
|
||||
int line_trap_max = MAX(width, height) / kLineTrapLongest;
|
||||
int line_trap_min = MIN(width, height) * kLineTrapShortest;
|
||||
int line_trap_max = std::max(width, height) / kLineTrapLongest;
|
||||
int line_trap_min = std::min(width, height) * kLineTrapShortest;
|
||||
int line_trap_count = 0;
|
||||
|
||||
int min_good_overlap = (dir == BND_LEFT || dir == BND_RIGHT)
|
||||
@ -951,14 +952,14 @@ int StrokeWidth::FindGoodNeighbour(BlobNeighbourDir dir, bool leaders,
|
||||
// width accepted by the morphological line detector.
|
||||
int n_width = nbox.width();
|
||||
int n_height = nbox.height();
|
||||
if (MIN(n_width, n_height) > line_trap_min &&
|
||||
MAX(n_width, n_height) < line_trap_max)
|
||||
if (std::min(n_width, n_height) > line_trap_min &&
|
||||
std::max(n_width, n_height) < line_trap_max)
|
||||
++line_trap_count;
|
||||
// Heavily joined text, such as Arabic may have very different sizes when
|
||||
// looking at the maxes, but the heights may be almost identical, so check
|
||||
// for a difference in height if looking sideways or width vertically.
|
||||
if (TabFind::VeryDifferentSizes(MAX(n_width, n_height),
|
||||
MAX(width, height)) &&
|
||||
if (TabFind::VeryDifferentSizes(std::max(n_width, n_height),
|
||||
std::max(width, height)) &&
|
||||
(((dir == BND_LEFT || dir ==BND_RIGHT) &&
|
||||
TabFind::DifferentSizes(n_height, height)) ||
|
||||
((dir == BND_BELOW || dir ==BND_ABOVE) &&
|
||||
@ -975,7 +976,7 @@ int StrokeWidth::FindGoodNeighbour(BlobNeighbourDir dir, bool leaders,
|
||||
int perp_overlap;
|
||||
int gap;
|
||||
if (dir == BND_LEFT || dir == BND_RIGHT) {
|
||||
overlap = MIN(nbox.top(), top) - MAX(nbox.bottom(), bottom);
|
||||
overlap = std::min(static_cast<int>(nbox.top()), top) - std::max(static_cast<int>(nbox.bottom()), bottom);
|
||||
if (overlap == nbox.height() && nbox.width() > nbox.height())
|
||||
perp_overlap = nbox.width();
|
||||
else
|
||||
@ -987,7 +988,7 @@ int StrokeWidth::FindGoodNeighbour(BlobNeighbourDir dir, bool leaders,
|
||||
}
|
||||
gap -= n_width;
|
||||
} else {
|
||||
overlap = MIN(nbox.right(), right) - MAX(nbox.left(), left);
|
||||
overlap = std::min(static_cast<int>(nbox.right()), right) - std::max(static_cast<int>(nbox.left()), left);
|
||||
if (overlap == nbox.width() && nbox.height() > nbox.width())
|
||||
perp_overlap = nbox.height();
|
||||
else
|
||||
@ -1966,8 +1967,8 @@ ScrollView* StrokeWidth::DisplayGoodBlobs(const char* window_name,
|
||||
static void DrawDiacriticJoiner(const BLOBNBOX* blob, ScrollView* window) {
|
||||
#ifndef GRAPHICS_DISABLED
|
||||
const TBOX& blob_box(blob->bounding_box());
|
||||
int top = MAX(blob_box.top(), blob->base_char_top());
|
||||
int bottom = MIN(blob_box.bottom(), blob->base_char_bottom());
|
||||
int top = std::max(static_cast<int>(blob_box.top()), blob->base_char_top());
|
||||
int bottom = std::min(static_cast<int>(blob_box.bottom()), blob->base_char_bottom());
|
||||
int x = (blob_box.left() + blob_box.right()) / 2;
|
||||
window->Line(x, top, x, bottom);
|
||||
#endif // GRAPHICS_DISABLED
|
||||
|
@ -29,6 +29,8 @@
|
||||
#include "linefind.h"
|
||||
#include "ndminx.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
// Multiple of box size to search for initial gaps.
|
||||
@ -164,7 +166,7 @@ int TabFind::GutterWidth(int bottom_y, int top_y, const TabVector& v,
|
||||
bool right_to_left = v.IsLeftTab();
|
||||
int bottom_x = v.XAtY(bottom_y);
|
||||
int top_x = v.XAtY(top_y);
|
||||
int start_x = right_to_left ? MAX(top_x, bottom_x) : MIN(top_x, bottom_x);
|
||||
int start_x = right_to_left ? std::max(top_x, bottom_x) : std::min(top_x, bottom_x);
|
||||
BlobGridSearch sidesearch(this);
|
||||
sidesearch.StartSideSearch(start_x, bottom_y, top_y);
|
||||
int min_gap = max_gutter_width;
|
||||
@ -490,8 +492,8 @@ void TabFind::TidyBlobs(TO_BLOCK* block) {
|
||||
void TabFind::SetupTabSearch(int x, int y, int* min_key, int* max_key) {
|
||||
int key1 = TabVector::SortKey(vertical_skew_, x, (y + tright_.y()) / 2);
|
||||
int key2 = TabVector::SortKey(vertical_skew_, x, (y + bleft_.y()) / 2);
|
||||
*min_key = MIN(key1, key2);
|
||||
*max_key = MAX(key1, key2);
|
||||
*min_key = std::min(key1, key2);
|
||||
*max_key = std::max(key1, key2);
|
||||
}
|
||||
|
||||
ScrollView* TabFind::DisplayTabVectors(ScrollView* tab_win) {
|
||||
@ -893,7 +895,7 @@ TabVector* TabFind::FindTabVector(int search_size_multiple,
|
||||
TabAlignment alignment,
|
||||
BLOBNBOX* bbox,
|
||||
int* vertical_x, int* vertical_y) {
|
||||
int height = MAX(bbox->bounding_box().height(), gridsize());
|
||||
int height = std::max(static_cast<int>(bbox->bounding_box().height()), gridsize());
|
||||
AlignedBlobParams align_params(*vertical_x, *vertical_y,
|
||||
height,
|
||||
search_size_multiple, min_gutter_width,
|
||||
@ -1130,14 +1132,14 @@ BLOBNBOX* TabFind::AdjacentBlob(const BLOBNBOX* bbox,
|
||||
const TBOX& nbox = neighbour->bounding_box();
|
||||
int n_top_y = nbox.top();
|
||||
int n_bottom_y = nbox.bottom();
|
||||
int v_overlap = MIN(n_top_y, top_y) - MAX(n_bottom_y, bottom_y);
|
||||
int v_overlap = std::min(n_top_y, top_y) - std::max(n_bottom_y, bottom_y);
|
||||
int height = top_y - bottom_y;
|
||||
int n_height = n_top_y - n_bottom_y;
|
||||
if (v_overlap > min_overlap_fraction * MIN(height, n_height) &&
|
||||
if (v_overlap > min_overlap_fraction * std::min(height, n_height) &&
|
||||
(min_overlap_fraction == 0.0 || !DifferentSizes(height, n_height))) {
|
||||
int n_left = nbox.left();
|
||||
int n_right = nbox.right();
|
||||
int h_gap = MAX(n_left, left) - MIN(n_right, right);
|
||||
int h_gap = std::max(n_left, left) - std::min(n_right, right);
|
||||
int n_mid_x = (n_left + n_right) / 2;
|
||||
if (look_left == (n_mid_x < mid_x) && n_mid_x != mid_x) {
|
||||
if (h_gap > gap_limit) {
|
||||
|
@ -22,6 +22,7 @@
|
||||
#endif
|
||||
|
||||
#include "tablefind.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include "allheaders.h"
|
||||
@ -473,7 +474,7 @@ void TableFinder::SplitAndInsertFragmentedTextPartition(ColPartition* part) {
|
||||
}
|
||||
|
||||
// The right side of the previous blobs.
|
||||
previous_right = MAX(previous_right, box.right());
|
||||
previous_right = std::max(previous_right, static_cast<int>(box.right()));
|
||||
}
|
||||
}
|
||||
// When a split is not found, the right part is minimized
|
||||
@ -597,12 +598,12 @@ void TableFinder::SetPartitionSpacings(ColPartitionGrid* grid,
|
||||
ColPartition* right_column = columns->ColumnContaining(box.right(), y);
|
||||
// set distance from left column as space to the left
|
||||
if (left_column) {
|
||||
int left_space = MAX(0, box.left() - left_column->LeftAtY(y));
|
||||
int left_space = std::max(0, box.left() - left_column->LeftAtY(y));
|
||||
part->set_space_to_left(left_space);
|
||||
}
|
||||
// set distance from right column as space to the right
|
||||
if (right_column) {
|
||||
int right_space = MAX(0, right_column->RightAtY(y) - box.right());
|
||||
int right_space = std::max(0, right_column->RightAtY(y) - box.right());
|
||||
part->set_space_to_right(right_space);
|
||||
}
|
||||
|
||||
@ -617,7 +618,7 @@ void TableFinder::SetPartitionSpacings(ColPartitionGrid* grid,
|
||||
neighbor->type() == PT_HEADING_IMAGE) {
|
||||
int right = neighbor->bounding_box().right();
|
||||
if (right < box.left()) {
|
||||
int space = MIN(box.left() - right, part->space_to_left());
|
||||
int space = std::min(box.left() - right, part->space_to_left());
|
||||
part->set_space_to_left(space);
|
||||
}
|
||||
}
|
||||
@ -630,7 +631,7 @@ void TableFinder::SetPartitionSpacings(ColPartitionGrid* grid,
|
||||
neighbor->type() == PT_HEADING_IMAGE) {
|
||||
int left = neighbor->bounding_box().left();
|
||||
if (left > box.right()) {
|
||||
int space = MIN(left - box.right(), part->space_to_right());
|
||||
int space = std::min(left - box.right(), part->space_to_right());
|
||||
part->set_space_to_right(space);
|
||||
}
|
||||
}
|
||||
@ -638,8 +639,8 @@ void TableFinder::SetPartitionSpacings(ColPartitionGrid* grid,
|
||||
|
||||
ColPartition* upper_part = part->SingletonPartner(true);
|
||||
if (upper_part) {
|
||||
int space = MAX(0, upper_part->bounding_box().bottom() -
|
||||
part->bounding_box().bottom());
|
||||
int space = std::max(0, static_cast<int>(upper_part->bounding_box().bottom() -
|
||||
part->bounding_box().bottom()));
|
||||
part->set_space_above(space);
|
||||
} else {
|
||||
// TODO(nbeato): What constitutes a good value?
|
||||
@ -650,8 +651,8 @@ void TableFinder::SetPartitionSpacings(ColPartitionGrid* grid,
|
||||
|
||||
ColPartition* lower_part = part->SingletonPartner(false);
|
||||
if (lower_part) {
|
||||
int space = MAX(0, part->bounding_box().bottom() -
|
||||
lower_part->bounding_box().bottom());
|
||||
int space = std::max(0, static_cast<int>(part->bounding_box().bottom() -
|
||||
lower_part->bounding_box().bottom()));
|
||||
part->set_space_below(space);
|
||||
} else {
|
||||
// TODO(nbeato): What constitutes a good value?
|
||||
@ -665,8 +666,8 @@ void TableFinder::SetPartitionSpacings(ColPartitionGrid* grid,
|
||||
// Set spacing and closest neighbors above and below a given colpartition.
|
||||
void TableFinder::SetVerticalSpacing(ColPartition* part) {
|
||||
TBOX box = part->bounding_box();
|
||||
int top_range = MIN(box.top() + kMaxVerticalSpacing, tright().y());
|
||||
int bottom_range = MAX(box.bottom() - kMaxVerticalSpacing, bleft().y());
|
||||
int top_range = std::min(box.top() + kMaxVerticalSpacing, static_cast<int>(tright().y()));
|
||||
int bottom_range = std::max(box.bottom() - kMaxVerticalSpacing, static_cast<int>(bleft().y()));
|
||||
box.set_top(top_range);
|
||||
box.set_bottom(bottom_range);
|
||||
|
||||
@ -895,7 +896,7 @@ bool TableFinder::HasWideOrNoInterWordGap(ColPartition* part) const {
|
||||
// with diacritics (accents) or broken alphabet symbols (characters).
|
||||
// Merge boxes together by taking max of right sides.
|
||||
if (-gap < part->median_size() * kMaxBlobOverlapFactor) {
|
||||
previous_x1 = MAX(previous_x1, current_x1);
|
||||
previous_x1 = std::max(previous_x1, current_x1);
|
||||
continue;
|
||||
}
|
||||
// Extreme case, blobs overlap significantly in the same partition...
|
||||
@ -1024,14 +1025,14 @@ void TableFinder::FilterParagraphEndings() {
|
||||
if (left_to_right_language_) {
|
||||
// Left to right languages, use mid - left to figure out the distance
|
||||
// the middle is from the left margin.
|
||||
int left = MIN(part->bounding_box().left(),
|
||||
int left = std::min(part->bounding_box().left(),
|
||||
upper_part->bounding_box().left());
|
||||
current_spacing = mid - left;
|
||||
upper_spacing = upper_mid - left;
|
||||
} else {
|
||||
// Right to left languages, use right - mid to figure out the distance
|
||||
// the middle is from the right margin.
|
||||
int right = MAX(part->bounding_box().right(),
|
||||
int right = std::max(part->bounding_box().right(),
|
||||
upper_part->bounding_box().right());
|
||||
current_spacing = right - mid;
|
||||
upper_spacing = right - upper_mid;
|
||||
@ -1210,8 +1211,8 @@ void TableFinder::GridMergeColumnBlocks() {
|
||||
do {
|
||||
TBOX box = seg->bounding_box();
|
||||
// slightly expand the search region vertically
|
||||
int top_range = MIN(box.top() + margin, tright().y());
|
||||
int bottom_range = MAX(box.bottom() - margin, bleft().y());
|
||||
int top_range = std::min(box.top() + margin, static_cast<int>(tright().y()));
|
||||
int bottom_range = std::max(box.bottom() - margin, static_cast<int>(bleft().y()));
|
||||
box.set_top(top_range);
|
||||
box.set_bottom(bottom_range);
|
||||
neighbor_found = false;
|
||||
@ -1748,7 +1749,7 @@ void TableFinder::DeleteSingleColumnTables() {
|
||||
int xstart = pblob->bounding_box().left();
|
||||
int xend = pblob->bounding_box().right();
|
||||
|
||||
xstart = MAX(xstart, next_position_to_write);
|
||||
xstart = std::max(xstart, next_position_to_write);
|
||||
for (int i = xstart; i < xend; i++)
|
||||
table_xprojection[i - bleft().x()]++;
|
||||
next_position_to_write = xend;
|
||||
|
@ -26,6 +26,8 @@
|
||||
|
||||
#include "tablerecog.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
// The amount of space required between the ColPartitions in 2 columns
|
||||
@ -284,7 +286,7 @@ double StructuredTable::CalculateCellFilledPercentage(int row, int column) {
|
||||
if (current_area == 0) {
|
||||
return 1.0;
|
||||
}
|
||||
return MIN(1.0, area_covered / current_area);
|
||||
return std::min(1.0, area_covered / current_area);
|
||||
}
|
||||
|
||||
void StructuredTable::Display(ScrollView* window, ScrollView::Color color) {
|
||||
@ -419,8 +421,8 @@ void StructuredTable::FindWhitespacedRows() {
|
||||
continue;
|
||||
|
||||
ASSERT_HOST(text->bounding_box().bottom() < text->bounding_box().top());
|
||||
min_bottom = MIN(min_bottom, text->bounding_box().bottom());
|
||||
max_top = MAX(max_top, text->bounding_box().top());
|
||||
min_bottom = std::min(min_bottom, static_cast<int>(text->bounding_box().bottom()));
|
||||
max_top = std::max(max_top, static_cast<int>(text->bounding_box().top()));
|
||||
|
||||
// Ignore "tall" text partitions, as these are usually false positive
|
||||
// vertical text or multiple lines pulled together.
|
||||
@ -474,13 +476,13 @@ void StructuredTable::CalculateMargins() {
|
||||
// boundaries and updates the margin.
|
||||
void StructuredTable::UpdateMargins(ColPartitionGrid* grid) {
|
||||
int below = FindVerticalMargin(grid, bounding_box_.bottom(), true);
|
||||
space_below_ = MIN(space_below_, below);
|
||||
space_below_ = std::min(space_below_, below);
|
||||
int above = FindVerticalMargin(grid, bounding_box_.top(), false);
|
||||
space_above_ = MIN(space_above_, above);
|
||||
space_above_ = std::min(space_above_, above);
|
||||
int left = FindHorizontalMargin(grid, bounding_box_.left(), true);
|
||||
space_left_ = MIN(space_left_, left);
|
||||
space_left_ = std::min(space_left_, left);
|
||||
int right = FindHorizontalMargin(grid, bounding_box_.right(), false);
|
||||
space_right_ = MIN(space_right_, right);
|
||||
space_right_ = std::min(space_right_, right);
|
||||
}
|
||||
int StructuredTable::FindVerticalMargin(ColPartitionGrid* grid, int border,
|
||||
bool decrease) const {
|
||||
@ -933,7 +935,7 @@ bool TableRecognizer::RecognizeWhitespacedTable(const TBOX& guess_box,
|
||||
table->row_height(0) < max_row_height)) {
|
||||
best_box.set_bottom(bottom);
|
||||
best_below = table->space_below();
|
||||
best_cols = MAX(table->column_count(), best_cols);
|
||||
best_cols = std::max(table->column_count(), best_cols);
|
||||
found_good_border = true;
|
||||
}
|
||||
}
|
||||
@ -980,7 +982,7 @@ bool TableRecognizer::RecognizeWhitespacedTable(const TBOX& guess_box,
|
||||
table->row_height(last_row) < max_row_height)) {
|
||||
best_box.set_top(top);
|
||||
best_above = table->space_above();
|
||||
best_cols = MAX(table->column_count(), best_cols);
|
||||
best_cols = std::max(table->column_count(), best_cols);
|
||||
found_good_border = true;
|
||||
}
|
||||
}
|
||||
@ -1031,11 +1033,11 @@ int TableRecognizer::NextHorizontalSplit(int left, int right, int y,
|
||||
|
||||
const TBOX& text_box = text->bounding_box();
|
||||
if (top_to_bottom && (last_y >= y || last_y <= text_box.top())) {
|
||||
last_y = MIN(last_y, text_box.bottom());
|
||||
last_y = std::min(last_y, static_cast<int>(text_box.bottom()));
|
||||
continue;
|
||||
}
|
||||
if (!top_to_bottom && (last_y <= y || last_y >= text_box.bottom())) {
|
||||
last_y = MAX(last_y, text_box.top());
|
||||
last_y = std::max(last_y, static_cast<int>(text_box.top()));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,8 @@
|
||||
#include "detlinefit.h"
|
||||
#include "statistc.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
// Multiple of height used as a gutter for evaluation search.
|
||||
@ -153,8 +155,8 @@ void TabConstraint::GetConstraints(TabConstraint_LIST* constraints,
|
||||
tprintf("Constraint is [%d,%d]", constraint->y_min_, constraint->y_max_);
|
||||
constraint->vector_->Print(" for");
|
||||
}
|
||||
*y_min = MAX(*y_min, constraint->y_min_);
|
||||
*y_max = MIN(*y_max, constraint->y_max_);
|
||||
*y_min = std::max(*y_min, constraint->y_min_);
|
||||
*y_max = std::min(*y_max, constraint->y_max_);
|
||||
}
|
||||
}
|
||||
|
||||
@ -418,8 +420,8 @@ bool TabVector::SimilarTo(const ICOORD& vertical,
|
||||
sort_key_ < other.sort_key_) ? this : &other;
|
||||
int top_y = mover->endpt_.y();
|
||||
int bottom_y = mover->startpt_.y();
|
||||
int left = MIN(mover->XAtY(top_y), mover->XAtY(bottom_y));
|
||||
int right = MAX(mover->XAtY(top_y), mover->XAtY(bottom_y));
|
||||
int left = std::min(mover->XAtY(top_y), mover->XAtY(bottom_y));
|
||||
int right = std::max(mover->XAtY(top_y), mover->XAtY(bottom_y));
|
||||
int shift = abs(sort_key_ - other.sort_key_) / v_scale;
|
||||
if (IsRightTab()) {
|
||||
right += shift;
|
||||
@ -442,7 +444,7 @@ bool TabVector::SimilarTo(const ICOORD& vertical,
|
||||
right_at_box += shift;
|
||||
else
|
||||
left_at_box -= shift;
|
||||
if (MIN(right_at_box, box.right()) > MAX(left_at_box, box.left()))
|
||||
if (std::min(right_at_box, static_cast<int>(box.right())) > std::max(left_at_box, static_cast<int>(box.left())))
|
||||
return false;
|
||||
}
|
||||
return true; // Nothing found.
|
||||
@ -452,8 +454,8 @@ bool TabVector::SimilarTo(const ICOORD& vertical,
|
||||
|
||||
// Eat the other TabVector into this and delete it.
|
||||
void TabVector::MergeWith(const ICOORD& vertical, TabVector* other) {
|
||||
extended_ymin_ = MIN(extended_ymin_, other->extended_ymin_);
|
||||
extended_ymax_ = MAX(extended_ymax_, other->extended_ymax_);
|
||||
extended_ymin_ = std::min(extended_ymin_, other->extended_ymin_);
|
||||
extended_ymax_ = std::max(extended_ymax_, other->extended_ymax_);
|
||||
if (other->IsRagged()) {
|
||||
alignment_ = other->alignment_;
|
||||
}
|
||||
@ -653,11 +655,11 @@ void TabVector::Evaluate(const ICOORD& vertical, TabFind* finder) {
|
||||
int vertical_gap = box.bottom() - prev_good_box->top();
|
||||
double size1 = sqrt(static_cast<double>(prev_good_box->area()));
|
||||
double size2 = sqrt(static_cast<double>(box.area()));
|
||||
if (vertical_gap < kMaxFillinMultiple * MIN(size1, size2))
|
||||
if (vertical_gap < kMaxFillinMultiple * std::min(size1, size2))
|
||||
good_length += vertical_gap;
|
||||
if (debug) {
|
||||
tprintf("Box and prev good, gap=%d, target %g, goodlength=%d\n",
|
||||
vertical_gap, kMaxFillinMultiple * MIN(size1, size2),
|
||||
vertical_gap, kMaxFillinMultiple * std::min(size1, size2),
|
||||
good_length);
|
||||
}
|
||||
} else {
|
||||
|
@ -27,6 +27,8 @@
|
||||
#include "rect.h"
|
||||
#include "bbgrid.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
class BLOBNBOX;
|
||||
class ScrollView;
|
||||
|
||||
@ -197,16 +199,16 @@ class TabVector : public ELIST2_LINK {
|
||||
|
||||
// Compute the vertical overlap with the other TabVector.
|
||||
int VOverlap(const TabVector& other) const {
|
||||
return MIN(other.endpt_.y(), endpt_.y()) -
|
||||
MAX(other.startpt_.y(), startpt_.y());
|
||||
return std::min(other.endpt_.y(), endpt_.y()) -
|
||||
std::max(other.startpt_.y(), startpt_.y());
|
||||
}
|
||||
// Compute the vertical overlap with the given y bounds.
|
||||
int VOverlap(int top_y, int bottom_y) const {
|
||||
return MIN(top_y, endpt_.y()) - MAX(bottom_y, startpt_.y());
|
||||
return std::min(top_y, static_cast<int>(endpt_.y())) - std::max(bottom_y, static_cast<int>(startpt_.y()));
|
||||
}
|
||||
// Compute the extended vertical overlap with the given y bounds.
|
||||
int ExtendedOverlap(int top_y, int bottom_y) const {
|
||||
return MIN(top_y, extended_ymax_) - MAX(bottom_y, extended_ymin_);
|
||||
return std::min(top_y, extended_ymax_) - std::max(bottom_y, extended_ymin_);
|
||||
}
|
||||
|
||||
// Return true if this is a left tab stop, either aligned, or ragged.
|
||||
|
@ -23,6 +23,8 @@
|
||||
#include "colpartition.h"
|
||||
#include "normalis.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
// Padding factor to use on definitely oriented blobs
|
||||
const int kOrientedPadFactor = 8;
|
||||
// Padding factor to use on not definitely oriented blobs.
|
||||
@ -210,19 +212,19 @@ int TextlineProjection::DistanceOfBoxFromBox(const TBOX& from_box,
|
||||
end_pt.x = start_pt.x;
|
||||
if (from_box.top() - to_box.top() >= to_box.bottom() - from_box.bottom()) {
|
||||
start_pt.y = from_box.top();
|
||||
end_pt.y = MIN(to_box.top(), start_pt.y);
|
||||
end_pt.y = std::min(to_box.top(), start_pt.y);
|
||||
} else {
|
||||
start_pt.y = from_box.bottom();
|
||||
end_pt.y = MAX(to_box.bottom(), start_pt.y);
|
||||
end_pt.y = std::max(to_box.bottom(), start_pt.y);
|
||||
}
|
||||
} else {
|
||||
parallel_gap = from_box.y_gap(to_box) + from_box.height();
|
||||
if (from_box.right() - to_box.right() >= to_box.left() - from_box.left()) {
|
||||
start_pt.x = from_box.right();
|
||||
end_pt.x = MIN(to_box.right(), start_pt.x);
|
||||
end_pt.x = std::min(to_box.right(), start_pt.x);
|
||||
} else {
|
||||
start_pt.x = from_box.left();
|
||||
end_pt.x = MAX(to_box.left(), start_pt.x);
|
||||
end_pt.x = std::max(to_box.left(), start_pt.x);
|
||||
}
|
||||
start_pt.y = (from_box.bottom() + from_box.top()) / 2;
|
||||
end_pt.y = start_pt.y;
|
||||
@ -342,7 +344,7 @@ bool TextlineProjection::BoxOutOfHTextline(const TBOX& box,
|
||||
int grad1 = 0;
|
||||
int grad2 = 0;
|
||||
EvaluateBoxInternal(box, denorm, debug, &grad1, &grad2, nullptr, nullptr);
|
||||
int worst_result = MIN(grad1, grad2);
|
||||
int worst_result = std::min(grad1, grad2);
|
||||
int total_result = grad1 + grad2;
|
||||
if (total_result >= 6) return false; // Strongly in textline.
|
||||
// Medium strength: if either gradient is negative, it is likely outside
|
||||
@ -429,17 +431,17 @@ int TextlineProjection::EvaluateBoxInternal(const TBOX& box,
|
||||
int right_gradient = -BestMeanGradientInColumn(denorm, box.right(),
|
||||
box.bottom(), box.top(),
|
||||
false);
|
||||
int top_clipped = MAX(top_gradient, 0);
|
||||
int bottom_clipped = MAX(bottom_gradient, 0);
|
||||
int left_clipped = MAX(left_gradient, 0);
|
||||
int right_clipped = MAX(right_gradient, 0);
|
||||
int top_clipped = std::max(top_gradient, 0);
|
||||
int bottom_clipped = std::max(bottom_gradient, 0);
|
||||
int left_clipped = std::max(left_gradient, 0);
|
||||
int right_clipped = std::max(right_gradient, 0);
|
||||
if (debug) {
|
||||
tprintf("Gradients: top = %d, bottom = %d, left= %d, right= %d for box:",
|
||||
top_gradient, bottom_gradient, left_gradient, right_gradient);
|
||||
box.print();
|
||||
}
|
||||
int result = MAX(top_clipped, bottom_clipped) -
|
||||
MAX(left_clipped, right_clipped);
|
||||
int result = std::max(top_clipped, bottom_clipped) -
|
||||
std::max(left_clipped, right_clipped);
|
||||
if (hgrad1 != nullptr && hgrad2 != nullptr) {
|
||||
*hgrad1 = top_gradient;
|
||||
*hgrad2 = bottom_gradient;
|
||||
|
@ -36,6 +36,8 @@
|
||||
#include "config_auto.h"
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#define MAXSPACING 128 /*max expected spacing in pix */
|
||||
|
||||
namespace tesseract {
|
||||
@ -224,7 +226,7 @@ void Textord::block_spacing_stats(
|
||||
(row->pitch_decision == PITCH_DEF_PROP) ||
|
||||
(row->pitch_decision == PITCH_CORR_PROP))) {
|
||||
real_space_threshold =
|
||||
MAX (tosp_init_guess_kn_mult * block_non_space_gap_width,
|
||||
std::max (tosp_init_guess_kn_mult * block_non_space_gap_width,
|
||||
tosp_init_guess_xht_mult * row->xheight);
|
||||
blob_it.set_to_list (row->blob_list ());
|
||||
blob_it.mark_cycle_pt ();
|
||||
@ -278,8 +280,8 @@ void Textord::block_spacing_stats(
|
||||
block_space_gap_width = -1;//No est. space width
|
||||
else
|
||||
block_space_gap_width =
|
||||
MAX ((int16_t) floor (space_gap_stats.median ()),
|
||||
3 * block_non_space_gap_width);
|
||||
std::max(static_cast<int16_t>(floor(space_gap_stats.median())),
|
||||
static_cast<int16_t>(3 * block_non_space_gap_width));
|
||||
}
|
||||
}
|
||||
|
||||
@ -433,13 +435,13 @@ void Textord::row_spacing_stats(
|
||||
row_idx, row->kern_size, row->space_threshold, row->space_size);
|
||||
row->space_threshold =
|
||||
(int32_t) (tosp_table_kn_sp_ratio * row->kern_size);
|
||||
row->space_size = MAX (row->space_threshold + 1, row->xheight);
|
||||
row->space_size = std::max(row->space_threshold + 1.0f, row->xheight);
|
||||
}
|
||||
}
|
||||
else if (tosp_sanity_method == 1) {
|
||||
sane_space = row->space_size;
|
||||
/* NEVER let space size get too close to kern size */
|
||||
if ((row->space_size < tosp_min_sane_kn_sp * MAX (row->kern_size, 2.5))
|
||||
if ((row->space_size < tosp_min_sane_kn_sp * std::max(row->kern_size, 2.5f))
|
||||
|| ((row->space_size - row->kern_size) <
|
||||
(tosp_silly_kn_sp_gap * row->xheight))) {
|
||||
if (good_block_space_estimate &&
|
||||
@ -447,8 +449,8 @@ void Textord::row_spacing_stats(
|
||||
sane_space = block_space_gap_width;
|
||||
else
|
||||
sane_space =
|
||||
MAX (tosp_min_sane_kn_sp * MAX (row->kern_size, 2.5),
|
||||
row->xheight / 2);
|
||||
std::max(static_cast<float>(tosp_min_sane_kn_sp) * std::max(row->kern_size, 2.5f),
|
||||
row->xheight / 2.0f);
|
||||
if (tosp_debug_level > 5)
|
||||
tprintf("B:%d R:%d -- DON'T BELIEVE SPACE %3.2f %d %3.2f -> %3.2f.\n",
|
||||
block_idx, row_idx, row->kern_size, row->space_threshold,
|
||||
@ -460,7 +462,7 @@ void Textord::row_spacing_stats(
|
||||
}
|
||||
/* NEVER let threshold get VERY far away from kern */
|
||||
sane_threshold = int32_t (floor (tosp_max_sane_kn_thresh *
|
||||
MAX (row->kern_size, 2.5)));
|
||||
std::max(row->kern_size, 2.5f)));
|
||||
if (row->space_threshold > sane_threshold) {
|
||||
if (tosp_debug_level > 5)
|
||||
tprintf("B:%d R:%d -- DON'T BELIEVE THRESH %3.2f %d %3.2f->%d.\n",
|
||||
@ -472,7 +474,7 @@ void Textord::row_spacing_stats(
|
||||
}
|
||||
/* Beware of tables - there may be NO spaces */
|
||||
if (suspected_table) {
|
||||
sane_space = MAX (tosp_table_kn_sp_ratio * row->kern_size,
|
||||
sane_space = std::max(tosp_table_kn_sp_ratio * row->kern_size,
|
||||
tosp_table_xht_sp_ratio * row->xheight);
|
||||
sane_threshold = int32_t (floor ((sane_space + row->kern_size) / 2));
|
||||
|
||||
@ -485,7 +487,7 @@ void Textord::row_spacing_stats(
|
||||
row->space_threshold, row->space_size);
|
||||
//the minimum sane value
|
||||
row->space_threshold = (int32_t) sane_space;
|
||||
row->space_size = MAX (row->space_threshold + 1, row->xheight);
|
||||
row->space_size = std::max(row->space_threshold + 1.0f, row->xheight);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -502,7 +504,7 @@ void Textord::row_spacing_stats(
|
||||
else {
|
||||
/* Any gap greater than 0.6 x-ht is bound to be a space (isn't it:-) */
|
||||
row->min_space =
|
||||
MIN (int32_t (ceil (tosp_fuzzy_space_factor * row->xheight)),
|
||||
std::min(int32_t (ceil (tosp_fuzzy_space_factor * row->xheight)),
|
||||
int32_t (row->space_size));
|
||||
if (row->min_space <= row->space_threshold)
|
||||
// Don't be silly
|
||||
@ -540,7 +542,7 @@ void Textord::row_spacing_stats(
|
||||
|
||||
if ((tosp_fuzzy_sp_fraction > 0) &&
|
||||
(row->space_size > row->space_threshold))
|
||||
row->min_space = MAX (row->min_space,
|
||||
row->min_space = std::max(row->min_space,
|
||||
(int32_t) ceil (row->space_threshold +
|
||||
tosp_fuzzy_sp_fraction *
|
||||
(row->space_size -
|
||||
@ -555,7 +557,7 @@ void Textord::row_spacing_stats(
|
||||
|
||||
if ((tosp_table_fuzzy_kn_sp_ratio > 0) &&
|
||||
(suspected_table || tosp_fuzzy_limit_all))
|
||||
row->min_space = MAX (row->min_space,
|
||||
row->min_space = std::max(row->min_space,
|
||||
(int32_t) ceil (tosp_table_fuzzy_kn_sp_ratio *
|
||||
row->kern_size));
|
||||
|
||||
@ -659,7 +661,7 @@ void Textord::old_to_method(
|
||||
// space_threshold
|
||||
if (tosp_old_to_constrain_sp_kn && tosp_sanity_method == 1 &&
|
||||
((row->space_size <
|
||||
tosp_min_sane_kn_sp * MAX (row->kern_size, 2.5)) ||
|
||||
tosp_min_sane_kn_sp * std::max(row->kern_size, 2.5f)) ||
|
||||
((row->space_size - row->kern_size) <
|
||||
tosp_silly_kn_sp_gap * row->xheight))) {
|
||||
if (row->kern_size > 2.5)
|
||||
@ -696,7 +698,7 @@ BOOL8 Textord::isolated_row_stats(TO_ROW *row,
|
||||
int32_t row_length;
|
||||
|
||||
kern_estimate = all_gap_stats->median ();
|
||||
crude_threshold_estimate = MAX (tosp_init_guess_kn_mult * kern_estimate,
|
||||
crude_threshold_estimate = std::max(tosp_init_guess_kn_mult * kern_estimate,
|
||||
tosp_init_guess_xht_mult * row->xheight);
|
||||
small_gaps_count = stats_count_under (all_gap_stats,
|
||||
(int16_t)
|
||||
@ -1501,7 +1503,7 @@ BOOL8 Textord::make_a_word_break(
|
||||
if ((prev_blob_box.width () > 0) &&
|
||||
(next_blob_box.width () > 0) &&
|
||||
(current_gap >=
|
||||
tosp_kern_gap_factor1 * MAX (prev_gap, next_gap)) &&
|
||||
tosp_kern_gap_factor1 * std::max(prev_gap, next_gap)) &&
|
||||
wide_blob (row, prev_blob_box) &&
|
||||
wide_blob (row, next_blob_box)) {
|
||||
|
||||
@ -1526,7 +1528,7 @@ BOOL8 Textord::make_a_word_break(
|
||||
next_blob_box.width() > 0 &&
|
||||
current_gap > 5 && // Rule 9 handles small gap, big ratio.
|
||||
current_gap >=
|
||||
tosp_kern_gap_factor2 * MAX(prev_gap, next_gap) &&
|
||||
tosp_kern_gap_factor2 * std::max(prev_gap, next_gap) &&
|
||||
!(narrow_blob(row, prev_blob_box) ||
|
||||
suspected_punct_blob(row, prev_blob_box)) &&
|
||||
!(narrow_blob(row, next_blob_box) ||
|
||||
@ -1542,7 +1544,7 @@ BOOL8 Textord::make_a_word_break(
|
||||
else if ((tosp_kern_gap_factor3 > 0) &&
|
||||
(prev_blob_box.width () > 0) &&
|
||||
(next_blob_box.width () > 0) &&
|
||||
(current_gap >= tosp_kern_gap_factor3 * MAX (prev_gap, next_gap)) &&
|
||||
(current_gap >= tosp_kern_gap_factor3 * std::max(prev_gap, next_gap)) &&
|
||||
(!tosp_rule_9_test_punct ||
|
||||
(!suspected_punct_blob (row, prev_blob_box) &&
|
||||
!suspected_punct_blob (row, next_blob_box)))) {
|
||||
@ -1798,7 +1800,7 @@ TBOX Textord::reduced_box_next(
|
||||
else if (blob->joined_to_prev ()) {
|
||||
reduced_box +=
|
||||
reduced_box_for_blob(blob, row, &new_left_above_xht);
|
||||
left_above_xht = MIN (left_above_xht, new_left_above_xht);
|
||||
left_above_xht = std::min(left_above_xht, new_left_above_xht);
|
||||
}
|
||||
}
|
||||
//until next real blob
|
||||
|
@ -185,15 +185,15 @@ void BoxChar::InsertSpaces(bool rtl_rules, bool vertical_rules,
|
||||
Box* prev = (*boxes)[i - 1]->box_;
|
||||
Box* next = (*boxes)[i + 1]->box_;
|
||||
ASSERT_HOST(prev != nullptr && next != nullptr);
|
||||
int top = MIN(prev->y, next->y);
|
||||
int bottom = MAX(prev->y + prev->h, next->y + next->h);
|
||||
int top = std::min(prev->y, next->y);
|
||||
int bottom = std::max(prev->y + prev->h, next->y + next->h);
|
||||
int left = prev->x + prev->w;
|
||||
int right = next->x;
|
||||
if (vertical_rules) {
|
||||
top = prev->y + prev->h;
|
||||
bottom = next->y;
|
||||
left = MIN(prev->x, next->x);
|
||||
right = MAX(prev->x + prev->w, next->x + next->w);
|
||||
left = std::min(prev->x, next->x);
|
||||
right = std::max(prev->x + prev->w, next->x + next->w);
|
||||
} else if (rtl_rules) {
|
||||
// With RTL we have to account for BiDi.
|
||||
// Right becomes the min left of all prior boxes back to the first
|
||||
|
@ -16,6 +16,7 @@
|
||||
// but doesn't have to be the same as the training data.
|
||||
// Author: Ray Smith
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#ifdef GOOGLE_TESSERACT
|
||||
#include "base/commandlineflags.h"
|
||||
@ -128,7 +129,7 @@ int main(int argc, char **argv) {
|
||||
trainer->ReplicateAndRandomizeSamplesIfRequired();
|
||||
|
||||
trainer->TestClassifierOnSamples(tesseract::CT_UNICHAR_TOP1_ERR,
|
||||
MAX(3, FLAGS_debug_level), false,
|
||||
std::max(3, FLAGS_debug_level), false,
|
||||
shape_classifier, nullptr);
|
||||
delete shape_classifier;
|
||||
delete api;
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include "commontraining.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
#include <cmath>
|
||||
|
||||
@ -97,13 +98,13 @@ void ParseArguments(int* argc, char ***argv) {
|
||||
tessoptind = 1;
|
||||
// Set some global values based on the flags.
|
||||
Config.MinSamples =
|
||||
MAX(0.0, MIN(1.0, double(FLAGS_clusterconfig_min_samples_fraction)));
|
||||
std::max(0.0, std::min(1.0, double(FLAGS_clusterconfig_min_samples_fraction)));
|
||||
Config.MaxIllegal =
|
||||
MAX(0.0, MIN(1.0, double(FLAGS_clusterconfig_max_illegal)));
|
||||
std::max(0.0, std::min(1.0, double(FLAGS_clusterconfig_max_illegal)));
|
||||
Config.Independence =
|
||||
MAX(0.0, MIN(1.0, double(FLAGS_clusterconfig_independence)));
|
||||
std::max(0.0, std::min(1.0, double(FLAGS_clusterconfig_independence)));
|
||||
Config.Confidence =
|
||||
MAX(0.0, MIN(1.0, double(FLAGS_clusterconfig_confidence)));
|
||||
std::max(0.0, std::min(1.0, double(FLAGS_clusterconfig_confidence)));
|
||||
// Set additional parameters from config file if specified.
|
||||
if (!FLAGS_configfile.empty()) {
|
||||
tesseract::ParamUtils::ReadParamsFile(
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "intproto.h"
|
||||
#include "params.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
@ -183,7 +184,7 @@ int FindClosestExistingProto(CLASS_TYPE Class, int NumMerged[],
|
||||
(FLOAT32) NumMerged[Pid], 1.0, &MergedProto);
|
||||
OldMatch = CompareProtos(Proto, &MergedProto);
|
||||
NewMatch = CompareProtos(&NewProto, &MergedProto);
|
||||
Match = MIN(OldMatch, NewMatch);
|
||||
Match = std::min(OldMatch, NewMatch);
|
||||
if (Match > BestMatch) {
|
||||
BestProto = Pid;
|
||||
BestMatch = Match;
|
||||
@ -324,11 +325,11 @@ void ComputePaddedBoundingBox (PROTO Proto, FLOAT32 TangentPad,
|
||||
CosOfAngle = fabs(cos(Angle));
|
||||
SinOfAngle = fabs(sin(Angle));
|
||||
|
||||
Pad = MAX (CosOfAngle * Length, SinOfAngle * OrthogonalPad);
|
||||
Pad = std::max(CosOfAngle * Length, SinOfAngle * OrthogonalPad);
|
||||
BoundingBox->MinX = Proto->X - Pad;
|
||||
BoundingBox->MaxX = Proto->X + Pad;
|
||||
|
||||
Pad = MAX(SinOfAngle * Length, CosOfAngle * OrthogonalPad);
|
||||
Pad = std::max(SinOfAngle * Length, CosOfAngle * OrthogonalPad);
|
||||
BoundingBox->MinY = Proto->Y - Pad;
|
||||
BoundingBox->MaxY = Proto->Y + Pad;
|
||||
|
||||
|
@ -693,8 +693,8 @@ std::string FontUtils::BestFonts(
|
||||
std::vector<bool> ch_flags;
|
||||
int raw_score = 0;
|
||||
int ok_chars = FontScore(ch_map, font_names[i], &raw_score, &ch_flags);
|
||||
most_ok_chars = MAX(ok_chars, most_ok_chars);
|
||||
best_raw_score = MAX(raw_score, best_raw_score);
|
||||
most_ok_chars = std::max(ok_chars, most_ok_chars);
|
||||
best_raw_score = std::max(raw_score, best_raw_score);
|
||||
|
||||
font_flags.push_back(ch_flags);
|
||||
font_scores.push_back(ok_chars);
|
||||
|
@ -756,7 +756,7 @@ void ScrollView::ZoomToRectangle(int x1, int y1, int x2, int y2) {
|
||||
y1 = TranslateYCoordinate(y1);
|
||||
y2 = TranslateYCoordinate(y2);
|
||||
SendMsg("zoomRectangle(%d,%d,%d,%d)",
|
||||
MIN(x1, x2), MIN(y1, y2), MAX(x1, x2), MAX(y1, y2));
|
||||
std::min(x1, x2), std::min(y1, y2), std::max(x1, x2), std::max(y1, y2));
|
||||
}
|
||||
|
||||
// Send an image of type Pix.
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "wordrec.h"
|
||||
#include "chop.h"
|
||||
#include "ndminx.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
@ -60,7 +61,7 @@ PRIORITY Wordrec::grade_split_length(SPLIT *split) {
|
||||
else
|
||||
grade = sqrt (split_length) * chop_split_dist_knob;
|
||||
|
||||
return (MAX (0.0, grade));
|
||||
return (std::max(0.0f, grade));
|
||||
}
|
||||
|
||||
|
||||
|
@ -29,6 +29,8 @@
|
||||
#include "matrix.h"
|
||||
#include "pageres.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
const float LMPainPoints::kDefaultPainPointPriorityAdjustment = 2.0f;
|
||||
@ -49,7 +51,7 @@ void LMPainPoints::GenerateInitial(WERD_RES *word_res) {
|
||||
MATRIX *ratings = word_res->ratings;
|
||||
AssociateStats associate_stats;
|
||||
for (int col = 0; col < ratings->dimension(); ++col) {
|
||||
int row_end = MIN(ratings->dimension(), col + ratings->bandwidth() + 1);
|
||||
int row_end = std::min(ratings->dimension(), col + ratings->bandwidth() + 1);
|
||||
for (int row = col + 1; row < row_end; ++row) {
|
||||
MATRIX_COORD coord(col, row);
|
||||
if (coord.Valid(*ratings) &&
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include "lm_pain_points.h"
|
||||
#include "ratngs.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
void Wordrec::DoSegSearch(WERD_RES* word_res) {
|
||||
@ -186,7 +188,7 @@ void Wordrec::UpdateSegSearchNodes(
|
||||
for (int col = starting_col; col < ratings->dimension(); ++col) {
|
||||
if (!(*pending)[col].WorkToDo()) continue;
|
||||
int first_row = col;
|
||||
int last_row = MIN(ratings->dimension() - 1,
|
||||
int last_row = std::min(ratings->dimension() - 1,
|
||||
col + ratings->bandwidth() - 1);
|
||||
if ((*pending)[col].SingleRow() >= 0) {
|
||||
first_row = last_row = (*pending)[col].SingleRow();
|
||||
|
Loading…
Reference in New Issue
Block a user