mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-12-12 23:49:06 +08:00
Use C++-11 code instead of TessCallback for WidthCallback
Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
1c1eb76c36
commit
0ea8ada308
@ -1,10 +1,9 @@
|
|||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
// File: ccnontextdetect.cpp
|
// File: ccnontextdetect.cpp
|
||||||
// Description: Connected-Component-based photo (non-text) detection.
|
// Description: Connected-Component-based photo (non-text) detection.
|
||||||
// Copyright 2011 Google Inc. All Rights Reserved.
|
|
||||||
// Author: rays@google.com (Ray Smith)
|
// Author: rays@google.com (Ray Smith)
|
||||||
// Created: Sat Jun 11 10:12:01 PST 2011
|
|
||||||
//
|
//
|
||||||
|
// Copyright 2011 Google Inc. All Rights Reserved.
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
// You may obtain a copy of the License at
|
// You may obtain a copy of the License at
|
||||||
|
@ -645,7 +645,7 @@ ColPartition* ColPartition::SingletonPartner(bool upper) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Merge with the other partition and delete it.
|
// Merge with the other partition and delete it.
|
||||||
void ColPartition::Absorb(ColPartition* other, WidthCallback* cb) {
|
void ColPartition::Absorb(ColPartition* other, WidthCallback cb) {
|
||||||
// The result has to either own all of the blobs or none of them.
|
// The result has to either own all of the blobs or none of them.
|
||||||
// Verify the flag is consistent.
|
// Verify the flag is consistent.
|
||||||
ASSERT_HOST(owns_blobs() == other->owns_blobs());
|
ASSERT_HOST(owns_blobs() == other->owns_blobs());
|
||||||
@ -1077,10 +1077,10 @@ void ColPartition::ColumnRange(int resolution, ColPartitionSet* columns,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sets the internal flags good_width_ and good_column_.
|
// Sets the internal flags good_width_ and good_column_.
|
||||||
void ColPartition::SetColumnGoodness(WidthCallback* cb) {
|
void ColPartition::SetColumnGoodness(WidthCallback cb) {
|
||||||
int y = MidY();
|
int y = MidY();
|
||||||
int width = RightAtY(y) - LeftAtY(y);
|
int width = RightAtY(y) - LeftAtY(y);
|
||||||
good_width_ = cb->Run(width);
|
good_width_ = cb(width);
|
||||||
good_column_ = blob_type_ == BRT_TEXT && left_key_tab_ && right_key_tab_;
|
good_column_ = blob_type_ == BRT_TEXT && left_key_tab_ && right_key_tab_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
// Description: Class to hold partitions of the page that correspond
|
// Description: Class to hold partitions of the page that correspond
|
||||||
// roughly to text lines.
|
// roughly to text lines.
|
||||||
// Author: Ray Smith
|
// Author: Ray Smith
|
||||||
// Created: Thu Aug 14 10:50:01 PDT 2008
|
|
||||||
//
|
//
|
||||||
// (C) Copyright 2008, Google Inc.
|
// (C) Copyright 2008, Google Inc.
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -573,7 +572,7 @@ class ColPartition : public ELIST2_LINK {
|
|||||||
ColPartition* SingletonPartner(bool upper);
|
ColPartition* SingletonPartner(bool upper);
|
||||||
|
|
||||||
// Merge with the other partition and delete it.
|
// Merge with the other partition and delete it.
|
||||||
void Absorb(ColPartition* other, WidthCallback* cb);
|
void Absorb(ColPartition* other, WidthCallback cb);
|
||||||
|
|
||||||
// Returns true if the overlap between this and the merged pair of
|
// Returns true if the overlap between this and the merged pair of
|
||||||
// merge candidates is sufficiently trivial to be allowed.
|
// merge candidates is sufficiently trivial to be allowed.
|
||||||
@ -618,7 +617,7 @@ class ColPartition : public ELIST2_LINK {
|
|||||||
int* first_col, int* last_col);
|
int* first_col, int* last_col);
|
||||||
|
|
||||||
// Sets the internal flags good_width_ and good_column_.
|
// Sets the internal flags good_width_ and good_column_.
|
||||||
void SetColumnGoodness(WidthCallback* cb);
|
void SetColumnGoodness(WidthCallback cb);
|
||||||
|
|
||||||
// Determines whether the blobs in this partition mostly represent
|
// Determines whether the blobs in this partition mostly represent
|
||||||
// a leader (fixed pitch sequence) and sets the member blobs accordingly.
|
// a leader (fixed pitch sequence) and sets the member blobs accordingly.
|
||||||
|
@ -99,9 +99,8 @@ void ColPartitionGrid::HandleClick(int x, int y) {
|
|||||||
// true, then the partitions are merged.
|
// true, then the partitions are merged.
|
||||||
// Both callbacks are deleted before returning.
|
// Both callbacks are deleted before returning.
|
||||||
void ColPartitionGrid::Merges(
|
void ColPartitionGrid::Merges(
|
||||||
TessResultCallback2<bool, ColPartition*, TBOX*>* box_cb,
|
std::function<bool(ColPartition*, TBOX*)> box_cb,
|
||||||
TessResultCallback2<bool, const ColPartition*,
|
std::function<bool(const ColPartition*, const ColPartition*)> confirm_cb) {
|
||||||
const ColPartition*>* confirm_cb) {
|
|
||||||
// Iterate the ColPartitions in the grid.
|
// Iterate the ColPartitions in the grid.
|
||||||
ColPartitionGridSearch gsearch(this);
|
ColPartitionGridSearch gsearch(this);
|
||||||
gsearch.StartFullSearch();
|
gsearch.StartFullSearch();
|
||||||
@ -110,8 +109,6 @@ void ColPartitionGrid::Merges(
|
|||||||
if (MergePart(box_cb, confirm_cb, part))
|
if (MergePart(box_cb, confirm_cb, part))
|
||||||
gsearch.RepositionIterator();
|
gsearch.RepositionIterator();
|
||||||
}
|
}
|
||||||
delete box_cb;
|
|
||||||
delete confirm_cb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// For the given partition, calls the box_cb permanent callback
|
// For the given partition, calls the box_cb permanent callback
|
||||||
@ -120,9 +117,8 @@ void ColPartitionGrid::Merges(
|
|||||||
// true, then the partitions are merged.
|
// true, then the partitions are merged.
|
||||||
// Returns true if the partition is consumed by one or more merges.
|
// Returns true if the partition is consumed by one or more merges.
|
||||||
bool ColPartitionGrid::MergePart(
|
bool ColPartitionGrid::MergePart(
|
||||||
TessResultCallback2<bool, ColPartition*, TBOX*>* box_cb,
|
std::function<bool(ColPartition*, TBOX*)> box_cb,
|
||||||
TessResultCallback2<bool, const ColPartition*,
|
std::function<bool(const ColPartition*, const ColPartition*)> confirm_cb,
|
||||||
const ColPartition*>* confirm_cb,
|
|
||||||
ColPartition* part) {
|
ColPartition* part) {
|
||||||
if (part->IsUnMergeableType())
|
if (part->IsUnMergeableType())
|
||||||
return false;
|
return false;
|
||||||
@ -138,7 +134,7 @@ bool ColPartitionGrid::MergePart(
|
|||||||
box.print();
|
box.print();
|
||||||
}
|
}
|
||||||
// Set up a rectangle search bounded by the part.
|
// Set up a rectangle search bounded by the part.
|
||||||
if (!box_cb->Run(part, &box))
|
if (!box_cb(part, &box))
|
||||||
continue;
|
continue;
|
||||||
// Create a list of merge candidates.
|
// Create a list of merge candidates.
|
||||||
ColPartition_CLIST merge_candidates;
|
ColPartition_CLIST merge_candidates;
|
||||||
@ -404,7 +400,7 @@ void ColPartitionGrid::FindOverlappingPartitions(const TBOX& box,
|
|||||||
// in overlap, or tightly spaced text would end up in bits.
|
// in overlap, or tightly spaced text would end up in bits.
|
||||||
ColPartition* ColPartitionGrid::BestMergeCandidate(
|
ColPartition* ColPartitionGrid::BestMergeCandidate(
|
||||||
const ColPartition* part, ColPartition_CLIST* candidates, bool debug,
|
const ColPartition* part, ColPartition_CLIST* candidates, bool debug,
|
||||||
TessResultCallback2<bool, const ColPartition*, const ColPartition*>* confirm_cb,
|
std::function<bool(const ColPartition*, const ColPartition*)> confirm_cb,
|
||||||
int* overlap_increase) {
|
int* overlap_increase) {
|
||||||
if (overlap_increase != nullptr)
|
if (overlap_increase != nullptr)
|
||||||
*overlap_increase = 0;
|
*overlap_increase = 0;
|
||||||
@ -448,7 +444,7 @@ ColPartition* ColPartitionGrid::BestMergeCandidate(
|
|||||||
int best_area = 0;
|
int best_area = 0;
|
||||||
for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
|
for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
|
||||||
ColPartition* candidate = it.data();
|
ColPartition* candidate = it.data();
|
||||||
if (confirm_cb != nullptr && !confirm_cb->Run(part, candidate)) {
|
if (confirm_cb != nullptr && !confirm_cb(part, candidate)) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
tprintf("Candidate not confirmed:");
|
tprintf("Candidate not confirmed:");
|
||||||
candidate->bounding_box().print();
|
candidate->bounding_box().print();
|
||||||
@ -818,7 +814,7 @@ bool ColPartitionGrid::MakeColPartSets(PartSetVector* part_sets) {
|
|||||||
// represents the total horizontal extent of the significant content on the
|
// represents the total horizontal extent of the significant content on the
|
||||||
// page. Used for the single column setting in place of automatic detection.
|
// page. Used for the single column setting in place of automatic detection.
|
||||||
// Returns nullptr if the page is empty of significant content.
|
// Returns nullptr if the page is empty of significant content.
|
||||||
ColPartitionSet* ColPartitionGrid::MakeSingleColumnSet(WidthCallback* cb) {
|
ColPartitionSet* ColPartitionGrid::MakeSingleColumnSet(WidthCallback cb) {
|
||||||
ColPartition* single_column_part = nullptr;
|
ColPartition* single_column_part = nullptr;
|
||||||
// Iterate the ColPartitions in the grid to get parts onto lists for the
|
// Iterate the ColPartitions in the grid to get parts onto lists for the
|
||||||
// y bottom of each.
|
// y bottom of each.
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// File: colpartitiongrid.h
|
// File: colpartitiongrid.h
|
||||||
// Description: Class collecting code that acts on a BBGrid of ColPartitions.
|
// Description: Class collecting code that acts on a BBGrid of ColPartitions.
|
||||||
// Author: Ray Smith
|
// Author: Ray Smith
|
||||||
// Created: Mon Oct 05 08:42:01 PDT 2009
|
|
||||||
//
|
//
|
||||||
// (C) Copyright 2009, Google Inc.
|
// (C) Copyright 2009, Google Inc.
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -49,18 +48,18 @@ class ColPartitionGrid : public BBGrid<ColPartition,
|
|||||||
// calls the confirm_cb to check any more rules. If the confirm_cb returns
|
// calls the confirm_cb to check any more rules. If the confirm_cb returns
|
||||||
// true, then the partitions are merged.
|
// true, then the partitions are merged.
|
||||||
// Both callbacks are deleted before returning.
|
// Both callbacks are deleted before returning.
|
||||||
void Merges(TessResultCallback2<bool, ColPartition*, TBOX*>* box_cb,
|
void Merges(std::function<bool(ColPartition*, TBOX*)> box_cb,
|
||||||
TessResultCallback2<bool, const ColPartition*,
|
std::function<bool(const ColPartition*,
|
||||||
const ColPartition*>* confirm_cb);
|
const ColPartition*)> confirm_cb);
|
||||||
|
|
||||||
// For the given partition, calls the box_cb permanent callback
|
// For the given partition, calls the box_cb permanent callback
|
||||||
// to compute the search box, searches the box, and if a candidate is found,
|
// to compute the search box, searches the box, and if a candidate is found,
|
||||||
// calls the confirm_cb to check any more rules. If the confirm_cb returns
|
// calls the confirm_cb to check any more rules. If the confirm_cb returns
|
||||||
// true, then the partitions are merged.
|
// true, then the partitions are merged.
|
||||||
// Returns true if the partition is consumed by one or more merges.
|
// Returns true if the partition is consumed by one or more merges.
|
||||||
bool MergePart(TessResultCallback2<bool, ColPartition*, TBOX*>* box_cb,
|
bool MergePart(std::function<bool(ColPartition*, TBOX*)> box_cb,
|
||||||
TessResultCallback2<bool, const ColPartition*,
|
std::function<bool(const ColPartition*,
|
||||||
const ColPartition*>* confirm_cb,
|
const ColPartition*)> confirm_cb,
|
||||||
ColPartition* part);
|
ColPartition* part);
|
||||||
|
|
||||||
// Computes and returns the total overlap of all partitions in the grid.
|
// Computes and returns the total overlap of all partitions in the grid.
|
||||||
@ -82,8 +81,8 @@ class ColPartitionGrid : public BBGrid<ColPartition,
|
|||||||
// See colpartitiongrid.cpp for a diagram.
|
// See colpartitiongrid.cpp for a diagram.
|
||||||
ColPartition* BestMergeCandidate(
|
ColPartition* BestMergeCandidate(
|
||||||
const ColPartition* part, ColPartition_CLIST* candidates, bool debug,
|
const ColPartition* part, ColPartition_CLIST* candidates, bool debug,
|
||||||
TessResultCallback2<bool, const ColPartition*,
|
std::function<bool(const ColPartition*,
|
||||||
const ColPartition*>* confirm_cb,
|
const ColPartition*)> confirm_cb,
|
||||||
int* overlap_increase);
|
int* overlap_increase);
|
||||||
|
|
||||||
// Split partitions where it reduces overlap between their bounding boxes.
|
// Split partitions where it reduces overlap between their bounding boxes.
|
||||||
@ -133,7 +132,7 @@ class ColPartitionGrid : public BBGrid<ColPartition,
|
|||||||
// represents the total horizontal extent of the significant content on the
|
// represents the total horizontal extent of the significant content on the
|
||||||
// page. Used for the single column setting in place of automatic detection.
|
// page. Used for the single column setting in place of automatic detection.
|
||||||
// Returns nullptr if the page is empty of significant content.
|
// Returns nullptr if the page is empty of significant content.
|
||||||
ColPartitionSet* MakeSingleColumnSet(WidthCallback* cb);
|
ColPartitionSet* MakeSingleColumnSet(WidthCallback cb);
|
||||||
|
|
||||||
// Mark the BLOBNBOXes in each partition as being owned by that partition.
|
// Mark the BLOBNBOXes in each partition as being owned by that partition.
|
||||||
void ClaimBoxes();
|
void ClaimBoxes();
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
// Description: Class to hold a list of ColPartitions of the page that
|
// Description: Class to hold a list of ColPartitions of the page that
|
||||||
// correspond roughly to columns.
|
// correspond roughly to columns.
|
||||||
// Author: Ray Smith
|
// Author: Ray Smith
|
||||||
// Created: Thu Aug 14 10:54:01 PDT 2008
|
|
||||||
//
|
//
|
||||||
// (C) Copyright 2008, Google Inc.
|
// (C) Copyright 2008, Google Inc.
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -87,7 +86,7 @@ void ColPartitionSet::RelinquishParts() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to improve this by adding partitions or expanding partitions.
|
// Attempt to improve this by adding partitions or expanding partitions.
|
||||||
void ColPartitionSet::ImproveColumnCandidate(WidthCallback* cb,
|
void ColPartitionSet::ImproveColumnCandidate(WidthCallback cb,
|
||||||
PartSetVector* src_sets) {
|
PartSetVector* src_sets) {
|
||||||
int set_size = src_sets->size();
|
int set_size = src_sets->size();
|
||||||
// Iterate over the provided column sets, as each one may have something
|
// Iterate over the provided column sets, as each one may have something
|
||||||
@ -124,13 +123,13 @@ void ColPartitionSet::ImproveColumnCandidate(WidthCallback* cb,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Check the edges of col_part to see if they can improve part.
|
// Check the edges of col_part to see if they can improve part.
|
||||||
bool part_width_ok = cb->Run(part->KeyWidth(part_left, part_right));
|
bool part_width_ok = cb(part->KeyWidth(part_left, part_right));
|
||||||
if (col_left < part_left && col_left > prev_right) {
|
if (col_left < part_left && col_left > prev_right) {
|
||||||
// The left edge of the column is better and it doesn't overlap,
|
// The left edge of the column is better and it doesn't overlap,
|
||||||
// so we can potentially expand it.
|
// so we can potentially expand it.
|
||||||
int col_box_left = col_part->BoxLeftKey();
|
int col_box_left = col_part->BoxLeftKey();
|
||||||
bool tab_width_ok = cb->Run(part->KeyWidth(col_left, part_right));
|
bool tab_width_ok = cb(part->KeyWidth(col_left, part_right));
|
||||||
bool box_width_ok = cb->Run(part->KeyWidth(col_box_left, part_right));
|
bool box_width_ok = cb(part->KeyWidth(col_box_left, part_right));
|
||||||
if (tab_width_ok || (!part_width_ok)) {
|
if (tab_width_ok || (!part_width_ok)) {
|
||||||
// The tab is leaving the good column metric at least as good as
|
// The tab is leaving the good column metric at least as good as
|
||||||
// it was before, so use the tab.
|
// it was before, so use the tab.
|
||||||
@ -150,8 +149,8 @@ void ColPartitionSet::ImproveColumnCandidate(WidthCallback* cb,
|
|||||||
part_it.data_relative(1)->left_key() > col_right)) {
|
part_it.data_relative(1)->left_key() > col_right)) {
|
||||||
// The right edge is better, so we can possibly expand it.
|
// The right edge is better, so we can possibly expand it.
|
||||||
int col_box_right = col_part->BoxRightKey();
|
int col_box_right = col_part->BoxRightKey();
|
||||||
bool tab_width_ok = cb->Run(part->KeyWidth(part_left, col_right));
|
bool tab_width_ok = cb(part->KeyWidth(part_left, col_right));
|
||||||
bool box_width_ok = cb->Run(part->KeyWidth(part_left, col_box_right));
|
bool box_width_ok = cb(part->KeyWidth(part_left, col_box_right));
|
||||||
if (tab_width_ok || (!part_width_ok)) {
|
if (tab_width_ok || (!part_width_ok)) {
|
||||||
// The tab is leaving the good column metric at least as good as
|
// The tab is leaving the good column metric at least as good as
|
||||||
// it was before, so use the tab.
|
// it was before, so use the tab.
|
||||||
@ -173,7 +172,7 @@ void ColPartitionSet::ImproveColumnCandidate(WidthCallback* cb,
|
|||||||
// If this set is good enough to represent a new partitioning into columns,
|
// If this set is good enough to represent a new partitioning into columns,
|
||||||
// add it to the vector of sets, otherwise delete it.
|
// add it to the vector of sets, otherwise delete it.
|
||||||
void ColPartitionSet::AddToColumnSetsIfUnique(PartSetVector* column_sets,
|
void ColPartitionSet::AddToColumnSetsIfUnique(PartSetVector* column_sets,
|
||||||
WidthCallback* cb) {
|
WidthCallback cb) {
|
||||||
bool debug = TabFind::WithinTestRegion(2, bounding_box_.left(),
|
bool debug = TabFind::WithinTestRegion(2, bounding_box_.left(),
|
||||||
bounding_box_.bottom());
|
bounding_box_.bottom());
|
||||||
if (debug) {
|
if (debug) {
|
||||||
@ -221,7 +220,7 @@ void ColPartitionSet::AddToColumnSetsIfUnique(PartSetVector* column_sets,
|
|||||||
// Return true if the partitions in other are all compatible with the columns
|
// Return true if the partitions in other are all compatible with the columns
|
||||||
// in this.
|
// in this.
|
||||||
bool ColPartitionSet::CompatibleColumns(bool debug, ColPartitionSet* other,
|
bool ColPartitionSet::CompatibleColumns(bool debug, ColPartitionSet* other,
|
||||||
WidthCallback* cb) {
|
WidthCallback cb) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
tprintf("CompatibleColumns testing compatibility\n");
|
tprintf("CompatibleColumns testing compatibility\n");
|
||||||
Print();
|
Print();
|
||||||
@ -254,7 +253,7 @@ bool ColPartitionSet::CompatibleColumns(bool debug, ColPartitionSet* other,
|
|||||||
}
|
}
|
||||||
return false; // A partition edge lies outside of all columns
|
return false; // A partition edge lies outside of all columns
|
||||||
}
|
}
|
||||||
if (right_col != left_col && cb->Run(right - left)) {
|
if (right_col != left_col && cb(right - left)) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
tprintf("CompatibleColumns false due to good width in multiple cols\n");
|
tprintf("CompatibleColumns false due to good width in multiple cols\n");
|
||||||
part->Print();
|
part->Print();
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
// Description: Class to hold a list of ColPartitions of the page that
|
// Description: Class to hold a list of ColPartitions of the page that
|
||||||
// correspond roughly to columns.
|
// correspond roughly to columns.
|
||||||
// Author: Ray Smith
|
// Author: Ray Smith
|
||||||
// Created: Thu Aug 14 10:50:01 PDT 2008
|
|
||||||
//
|
//
|
||||||
// (C) Copyright 2008, Google Inc.
|
// (C) Copyright 2008, Google Inc.
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -72,15 +71,15 @@ class ColPartitionSet : public ELIST_LINK {
|
|||||||
void RelinquishParts();
|
void RelinquishParts();
|
||||||
|
|
||||||
// Attempt to improve this by adding partitions or expanding partitions.
|
// Attempt to improve this by adding partitions or expanding partitions.
|
||||||
void ImproveColumnCandidate(WidthCallback* cb, PartSetVector* src_sets);
|
void ImproveColumnCandidate(WidthCallback cb, PartSetVector* src_sets);
|
||||||
|
|
||||||
// If this set is good enough to represent a new partitioning into columns,
|
// If this set is good enough to represent a new partitioning into columns,
|
||||||
// add it to the vector of sets, otherwise delete it.
|
// add it to the vector of sets, otherwise delete it.
|
||||||
void AddToColumnSetsIfUnique(PartSetVector* column_sets, WidthCallback* cb);
|
void AddToColumnSetsIfUnique(PartSetVector* column_sets, WidthCallback cb);
|
||||||
|
|
||||||
// Return true if the partitions in other are all compatible with the columns
|
// Return true if the partitions in other are all compatible with the columns
|
||||||
// in this.
|
// in this.
|
||||||
bool CompatibleColumns(bool debug, ColPartitionSet* other, WidthCallback* cb);
|
bool CompatibleColumns(bool debug, ColPartitionSet* other, WidthCallback cb);
|
||||||
|
|
||||||
// Returns the total width of all blobs in the part_set that do not lie
|
// Returns the total width of all blobs in the part_set that do not lie
|
||||||
// within an approved column. Used as a cost measure for using this
|
// within an approved column. Used as a cost measure for using this
|
||||||
|
@ -1865,9 +1865,10 @@ void StrokeWidth::CompletePartition(PageSegMode pageseg_mode,
|
|||||||
// Merge partitions where the merge appears harmless.
|
// Merge partitions where the merge appears harmless.
|
||||||
// As this
|
// As this
|
||||||
void StrokeWidth::EasyMerges(ColPartitionGrid* part_grid) {
|
void StrokeWidth::EasyMerges(ColPartitionGrid* part_grid) {
|
||||||
|
using namespace std::placeholders; // for _1, _2
|
||||||
part_grid->Merges(
|
part_grid->Merges(
|
||||||
NewPermanentTessCallback(this, &StrokeWidth::OrientationSearchBox),
|
std::bind(&StrokeWidth::OrientationSearchBox, this, _1, _2),
|
||||||
NewPermanentTessCallback(this, &StrokeWidth::ConfirmEasyMerge));
|
std::bind(&StrokeWidth::ConfirmEasyMerge, this, _1, _2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute a search box based on the orientation of the partition.
|
// Compute a search box based on the orientation of the partition.
|
||||||
|
@ -72,11 +72,11 @@ TabFind::TabFind(int gridsize, const ICOORD& bleft, const ICOORD& tright,
|
|||||||
width_cb_ = nullptr;
|
width_cb_ = nullptr;
|
||||||
v_it_.add_list_after(vlines);
|
v_it_.add_list_after(vlines);
|
||||||
SetVerticalSkewAndParallelize(vertical_x, vertical_y);
|
SetVerticalSkewAndParallelize(vertical_x, vertical_y);
|
||||||
width_cb_ = NewPermanentTessCallback(this, &TabFind::CommonWidth);
|
using namespace std::placeholders; // for _1
|
||||||
|
width_cb_ = std::bind(&TabFind::CommonWidth, this, _1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TabFind::~TabFind() {
|
TabFind::~TabFind() {
|
||||||
delete width_cb_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////// PUBLIC functions (mostly used by TabVector). //////////////
|
///////////////// PUBLIC functions (mostly used by TabVector). //////////////
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// File: tabfind.h
|
// File: tabfind.h
|
||||||
// Description: Subclass of BBGrid to find tabstops.
|
// Description: Subclass of BBGrid to find tabstops.
|
||||||
// Author: Ray Smith
|
// Author: Ray Smith
|
||||||
// Created: Fri Mar 21 15:03:01 PST 2008
|
|
||||||
//
|
//
|
||||||
// (C) Copyright 2008, Google Inc.
|
// (C) Copyright 2008, Google Inc.
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -20,8 +19,8 @@
|
|||||||
#ifndef TESSERACT_TEXTORD_TABFIND_H_
|
#ifndef TESSERACT_TEXTORD_TABFIND_H_
|
||||||
#define TESSERACT_TEXTORD_TABFIND_H_
|
#define TESSERACT_TEXTORD_TABFIND_H_
|
||||||
|
|
||||||
|
#include <functional> // for std::function
|
||||||
#include "alignedblob.h"
|
#include "alignedblob.h"
|
||||||
#include "tesscallback.h"
|
|
||||||
#include "tabvector.h"
|
#include "tabvector.h"
|
||||||
#include "linefind.h"
|
#include "linefind.h"
|
||||||
|
|
||||||
@ -33,7 +32,7 @@ struct Pix;
|
|||||||
|
|
||||||
namespace tesseract {
|
namespace tesseract {
|
||||||
|
|
||||||
using WidthCallback = TessResultCallback1<bool, int>;
|
using WidthCallback = std::function<bool(int)>;
|
||||||
|
|
||||||
struct AlignedBlobParams;
|
struct AlignedBlobParams;
|
||||||
class ColPartitionGrid;
|
class ColPartitionGrid;
|
||||||
@ -155,7 +154,7 @@ class TabFind : public AlignedBlob {
|
|||||||
/**
|
/**
|
||||||
* Return a callback for testing CommonWidth.
|
* Return a callback for testing CommonWidth.
|
||||||
*/
|
*/
|
||||||
WidthCallback* WidthCB() {
|
WidthCallback WidthCB() {
|
||||||
return width_cb_;
|
return width_cb_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,7 +373,7 @@ class TabFind : public AlignedBlob {
|
|||||||
// List of commonly occurring width ranges with x=min and y=max.
|
// List of commonly occurring width ranges with x=min and y=max.
|
||||||
ICOORDELT_LIST column_widths_; ///< List of commonly occurring width ranges.
|
ICOORDELT_LIST column_widths_; ///< List of commonly occurring width ranges.
|
||||||
/** Callback to test an int for being a common width. */
|
/** Callback to test an int for being a common width. */
|
||||||
WidthCallback* width_cb_;
|
WidthCallback width_cb_;
|
||||||
// Sets of bounding boxes that are candidate tab stops.
|
// Sets of bounding boxes that are candidate tab stops.
|
||||||
GenericVector<BLOBNBOX*> left_tab_boxes_;
|
GenericVector<BLOBNBOX*> left_tab_boxes_;
|
||||||
GenericVector<BLOBNBOX*> right_tab_boxes_;
|
GenericVector<BLOBNBOX*> right_tab_boxes_;
|
||||||
|
@ -258,7 +258,7 @@ void TableFinder::InsertCleanPartitions(ColPartitionGrid* grid,
|
|||||||
// High level function to perform table detection
|
// High level function to perform table detection
|
||||||
void TableFinder::LocateTables(ColPartitionGrid* grid,
|
void TableFinder::LocateTables(ColPartitionGrid* grid,
|
||||||
ColPartitionSet** all_columns,
|
ColPartitionSet** all_columns,
|
||||||
WidthCallback* width_cb,
|
WidthCallback width_cb,
|
||||||
const FCOORD& reskew) {
|
const FCOORD& reskew) {
|
||||||
// initialize spacing, neighbors, and columns
|
// initialize spacing, neighbors, and columns
|
||||||
InitializePartitions(all_columns);
|
InitializePartitions(all_columns);
|
||||||
@ -1996,7 +1996,7 @@ void TableFinder::DisplayColPartitionConnections(
|
|||||||
// assigned to any table to their original types.
|
// assigned to any table to their original types.
|
||||||
void TableFinder::MakeTableBlocks(ColPartitionGrid* grid,
|
void TableFinder::MakeTableBlocks(ColPartitionGrid* grid,
|
||||||
ColPartitionSet** all_columns,
|
ColPartitionSet** all_columns,
|
||||||
WidthCallback* width_cb) {
|
WidthCallback width_cb) {
|
||||||
// Since we have table blocks already, remove table tags from all
|
// Since we have table blocks already, remove table tags from all
|
||||||
// colpartitions
|
// colpartitions
|
||||||
GridSearch<ColPartition, ColPartition_CLIST, ColPartition_C_IT>
|
GridSearch<ColPartition, ColPartition_CLIST, ColPartition_C_IT>
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// File: tablefind.h
|
// File: tablefind.h
|
||||||
// Description: Helper classes to find tables from ColPartitions.
|
// Description: Helper classes to find tables from ColPartitions.
|
||||||
// Author: Faisal Shafait (faisal.shafait@dfki.de)
|
// Author: Faisal Shafait (faisal.shafait@dfki.de)
|
||||||
// Created: Tue Jan 06 11:13:01 PST 2009
|
|
||||||
//
|
//
|
||||||
// (C) Copyright 2009, Google Inc.
|
// (C) Copyright 2009, Google Inc.
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -156,7 +155,7 @@ class TableFinder {
|
|||||||
// if that feature is enabled.
|
// if that feature is enabled.
|
||||||
void LocateTables(ColPartitionGrid* grid,
|
void LocateTables(ColPartitionGrid* grid,
|
||||||
ColPartitionSet** columns,
|
ColPartitionSet** columns,
|
||||||
WidthCallback* width_cb,
|
WidthCallback width_cb,
|
||||||
const FCOORD& reskew);
|
const FCOORD& reskew);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -394,7 +393,7 @@ class TableFinder {
|
|||||||
// assigned to any table to their original types.
|
// assigned to any table to their original types.
|
||||||
void MakeTableBlocks(ColPartitionGrid* grid,
|
void MakeTableBlocks(ColPartitionGrid* grid,
|
||||||
ColPartitionSet** columns,
|
ColPartitionSet** columns,
|
||||||
WidthCallback* width_cb);
|
WidthCallback width_cb);
|
||||||
|
|
||||||
/////////////////////////////////////////////////
|
/////////////////////////////////////////////////
|
||||||
// Useful objects used during table find process.
|
// Useful objects used during table find process.
|
||||||
|
Loading…
Reference in New Issue
Block a user