mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-12-12 23:49:06 +08:00
Merge branch 'master' of https://github.com/tesseract-ocr/tesseract
This commit is contained in:
commit
140bfa43f0
@ -100,15 +100,15 @@ enum ColorationMode {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ScrollView* image_win;
|
static ScrollView* image_win;
|
||||||
ParamsEditor* pe;
|
static ParamsEditor* pe;
|
||||||
bool stillRunning = false;
|
static bool stillRunning = false;
|
||||||
|
|
||||||
ScrollView* bln_word_window = nullptr; // baseline norm words
|
static ScrollView* bln_word_window = nullptr; // baseline norm words
|
||||||
|
|
||||||
CMD_EVENTS mode = CHANGE_DISP_CMD_EVENT; // selected words op
|
static CMD_EVENTS mode = CHANGE_DISP_CMD_EVENT; // selected words op
|
||||||
|
|
||||||
bool recog_done = false; // recog_all_words was called
|
static bool recog_done = false; // recog_all_words was called
|
||||||
|
|
||||||
// These variables should remain global, since they are only used for the
|
// These variables should remain global, since they are only used for the
|
||||||
// debug mode (in which only a single Tesseract thread/instance will exist).
|
// debug mode (in which only a single Tesseract thread/instance will exist).
|
||||||
|
@ -365,7 +365,7 @@ class GENERIC_2D_ARRAY {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Accumulates the element-wise sums of squares of src into *this.
|
// Accumulates the element-wise sums of squares of src into *this.
|
||||||
void SumSquares(const GENERIC_2D_ARRAY<T>& src, T decay_factor) {
|
void SumSquares(const GENERIC_2D_ARRAY<T>& src, const T& decay_factor) {
|
||||||
T update_factor = 1.0 - decay_factor;
|
T update_factor = 1.0 - decay_factor;
|
||||||
int size = num_elements();
|
int size = num_elements();
|
||||||
for (int i = 0; i < size; ++i) {
|
for (int i = 0; i < size; ++i) {
|
||||||
@ -377,7 +377,7 @@ class GENERIC_2D_ARRAY {
|
|||||||
// Scales each element using the adam algorithm, ie array_[i] by
|
// Scales each element using the adam algorithm, ie array_[i] by
|
||||||
// sqrt(sqsum[i] + epsilon)).
|
// sqrt(sqsum[i] + epsilon)).
|
||||||
void AdamUpdate(const GENERIC_2D_ARRAY<T>& sum,
|
void AdamUpdate(const GENERIC_2D_ARRAY<T>& sum,
|
||||||
const GENERIC_2D_ARRAY<T>& sqsum, T epsilon) {
|
const GENERIC_2D_ARRAY<T>& sqsum, const T& epsilon) {
|
||||||
int size = num_elements();
|
int size = num_elements();
|
||||||
for (int i = 0; i < size; ++i) {
|
for (int i = 0; i < size; ++i) {
|
||||||
array_[i] += sum.array_[i] / (sqrt(sqsum.array_[i]) + epsilon);
|
array_[i] += sum.array_[i] / (sqrt(sqsum.array_[i]) + epsilon);
|
||||||
|
@ -363,10 +363,10 @@ class WERD_RES : public ELIST_LINK {
|
|||||||
blob_index >= best_choice->length())
|
blob_index >= best_choice->length())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
UNICHAR_ID id = best_choice->unichar_id(blob_index);
|
UNICHAR_ID id = best_choice->unichar_id(blob_index);
|
||||||
if (id < 0 || id >= uch_set->size() || id == INVALID_UNICHAR_ID)
|
if (id < 0 || id >= uch_set->size())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
UNICHAR_ID mirrored = uch_set->get_mirror(id);
|
UNICHAR_ID mirrored = uch_set->get_mirror(id);
|
||||||
if (in_rtl_context && mirrored > 0 && mirrored != INVALID_UNICHAR_ID)
|
if (in_rtl_context && mirrored > 0)
|
||||||
id = mirrored;
|
id = mirrored;
|
||||||
return uch_set->id_to_unichar_ext(id);
|
return uch_set->id_to_unichar_ext(id);
|
||||||
}
|
}
|
||||||
@ -375,7 +375,7 @@ class WERD_RES : public ELIST_LINK {
|
|||||||
if (blob_index < 0 || blob_index >= raw_choice->length())
|
if (blob_index < 0 || blob_index >= raw_choice->length())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
UNICHAR_ID id = raw_choice->unichar_id(blob_index);
|
UNICHAR_ID id = raw_choice->unichar_id(blob_index);
|
||||||
if (id < 0 || id >= uch_set->size() || id == INVALID_UNICHAR_ID)
|
if (id < 0 || id >= uch_set->size())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return uch_set->id_to_unichar(id);
|
return uch_set->id_to_unichar(id);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#define RECT_H
|
#define RECT_H
|
||||||
|
|
||||||
#include <algorithm> // for std::max, std::min
|
#include <algorithm> // for std::max, std::min
|
||||||
#include <cmath> // for ceil, floor
|
#include <cmath> // for std::ceil, std::floor
|
||||||
#include <cstdint> // for INT16_MAX
|
#include <cstdint> // for INT16_MAX
|
||||||
#include <cstdio> // for FILE
|
#include <cstdio> // for FILE
|
||||||
#include "platform.h" // for DLLSYM
|
#include "platform.h" // for DLLSYM
|
||||||
@ -162,29 +162,33 @@ class DLLSYM TBOX { // bounding box
|
|||||||
|
|
||||||
void move( // move box
|
void move( // move box
|
||||||
const FCOORD vec) { // by float vector
|
const FCOORD vec) { // by float vector
|
||||||
bot_left.set_x ((int16_t) floor (bot_left.x () + vec.x ()));
|
bot_left.set_x(static_cast<int16_t>(std::floor(bot_left.x() + vec.x())));
|
||||||
// round left
|
// round left
|
||||||
bot_left.set_y ((int16_t) floor (bot_left.y () + vec.y ()));
|
bot_left.set_y(static_cast<int16_t>(std::floor(bot_left.y() + vec.y())));
|
||||||
// round down
|
// round down
|
||||||
top_right.set_x ((int16_t) ceil (top_right.x () + vec.x ()));
|
top_right.set_x(static_cast<int16_t>(std::ceil(top_right.x() + vec.x())));
|
||||||
// round right
|
// round right
|
||||||
top_right.set_y ((int16_t) ceil (top_right.y () + vec.y ()));
|
top_right.set_y(static_cast<int16_t>(std::ceil(top_right.y() + vec.y())));
|
||||||
// round up
|
// round up
|
||||||
}
|
}
|
||||||
|
|
||||||
void scale( // scale box
|
void scale( // scale box
|
||||||
const float f) { // by multiplier
|
const float f) { // by multiplier
|
||||||
bot_left.set_x ((int16_t) floor (bot_left.x () * f)); // round left
|
// round left
|
||||||
bot_left.set_y ((int16_t) floor (bot_left.y () * f)); // round down
|
bot_left.set_x(static_cast<int16_t>(std::floor(bot_left.x() * f)));
|
||||||
top_right.set_x ((int16_t) ceil (top_right.x () * f)); // round right
|
// round down
|
||||||
top_right.set_y ((int16_t) ceil (top_right.y () * f)); // round up
|
bot_left.set_y(static_cast<int16_t>(std::floor(bot_left.y() * f)));
|
||||||
|
// round right
|
||||||
|
top_right.set_x(static_cast<int16_t>(std::ceil(top_right.x() * f)));
|
||||||
|
// round up
|
||||||
|
top_right.set_y(static_cast<int16_t>(std::ceil(top_right.y() * f)));
|
||||||
}
|
}
|
||||||
void scale( // scale box
|
void scale( // scale box
|
||||||
const FCOORD vec) { // by float vector
|
const FCOORD vec) { // by float vector
|
||||||
bot_left.set_x ((int16_t) floor (bot_left.x () * vec.x ()));
|
bot_left.set_x(static_cast<int16_t>(std::floor(bot_left.x() * vec.x())));
|
||||||
bot_left.set_y ((int16_t) floor (bot_left.y () * vec.y ()));
|
bot_left.set_y(static_cast<int16_t>(std::floor(bot_left.y() * vec.y())));
|
||||||
top_right.set_x ((int16_t) ceil (top_right.x () * vec.x ()));
|
top_right.set_x(static_cast<int16_t>(std::ceil(top_right.x() * vec.x())));
|
||||||
top_right.set_y ((int16_t) ceil (top_right.y () * vec.y ()));
|
top_right.set_y(static_cast<int16_t>(std::ceil(top_right.y() * vec.y())));
|
||||||
}
|
}
|
||||||
|
|
||||||
// rotate doesn't enlarge the box - it just rotates the bottom-left
|
// rotate doesn't enlarge the box - it just rotates the bottom-left
|
||||||
@ -314,8 +318,10 @@ class DLLSYM TBOX { // bounding box
|
|||||||
inline TBOX::TBOX( // constructor
|
inline TBOX::TBOX( // constructor
|
||||||
const FCOORD pt // floating centre
|
const FCOORD pt // floating centre
|
||||||
) {
|
) {
|
||||||
bot_left = ICOORD ((int16_t) floor (pt.x ()), (int16_t) floor (pt.y ()));
|
bot_left = ICOORD(static_cast<int16_t>(std::floor(pt.x())),
|
||||||
top_right = ICOORD ((int16_t) ceil (pt.x ()), (int16_t) ceil (pt.y ()));
|
static_cast<int16_t>(std::floor(pt.y())));
|
||||||
|
top_right = ICOORD(static_cast<int16_t>(std::ceil(pt.x())),
|
||||||
|
static_cast<int16_t>(std::ceil(pt.y())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ class GenericVector {
|
|||||||
GenericVector() {
|
GenericVector() {
|
||||||
init(kDefaultVectorSize);
|
init(kDefaultVectorSize);
|
||||||
}
|
}
|
||||||
GenericVector(int size, T init_val) {
|
GenericVector(int size, const T& init_val) {
|
||||||
init(size);
|
init(size);
|
||||||
init_to_size(size, init_val);
|
init_to_size(size, init_val);
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ class GenericVector {
|
|||||||
void double_the_size();
|
void double_the_size();
|
||||||
|
|
||||||
// Resizes to size and sets all values to t.
|
// Resizes to size and sets all values to t.
|
||||||
void init_to_size(int size, T t);
|
void init_to_size(int size, const T& t);
|
||||||
// Resizes to size without any initialization.
|
// Resizes to size without any initialization.
|
||||||
void resize_no_init(int size) {
|
void resize_no_init(int size) {
|
||||||
reserve(size);
|
reserve(size);
|
||||||
@ -101,31 +101,31 @@ class GenericVector {
|
|||||||
// Return the index of the T object.
|
// Return the index of the T object.
|
||||||
// This method NEEDS a compare_callback to be passed to
|
// This method NEEDS a compare_callback to be passed to
|
||||||
// set_compare_callback.
|
// set_compare_callback.
|
||||||
int get_index(T object) const;
|
int get_index(const T& object) const;
|
||||||
|
|
||||||
// Return true if T is in the array
|
// Return true if T is in the array
|
||||||
bool contains(T object) const;
|
bool contains(const T& object) const;
|
||||||
|
|
||||||
// Return true if the index is valid
|
// Return true if the index is valid
|
||||||
T contains_index(int index) const;
|
T contains_index(int index) const;
|
||||||
|
|
||||||
// Push an element in the end of the array
|
// Push an element in the end of the array
|
||||||
int push_back(T object);
|
int push_back(T object);
|
||||||
void operator+=(T t);
|
void operator+=(const T& t);
|
||||||
|
|
||||||
// Push an element in the end of the array if the same
|
// Push an element in the end of the array if the same
|
||||||
// element is not already contained in the array.
|
// element is not already contained in the array.
|
||||||
int push_back_new(T object);
|
int push_back_new(const T& object);
|
||||||
|
|
||||||
// Push an element in the front of the array
|
// Push an element in the front of the array
|
||||||
// Note: This function is O(n)
|
// Note: This function is O(n)
|
||||||
int push_front(T object);
|
int push_front(const T& object);
|
||||||
|
|
||||||
// Set the value at the given index
|
// Set the value at the given index
|
||||||
void set(T t, int index);
|
void set(const T& t, int index);
|
||||||
|
|
||||||
// Insert t at the given index, push other elements to the right.
|
// Insert t at the given index, push other elements to the right.
|
||||||
void insert(T t, int index);
|
void insert(const T& t, int index);
|
||||||
|
|
||||||
// Removes an element at the given index and
|
// Removes an element at the given index and
|
||||||
// shifts the remaining elements to the left.
|
// shifts the remaining elements to the left.
|
||||||
@ -705,7 +705,7 @@ void GenericVector<T>::double_the_size() {
|
|||||||
|
|
||||||
// Resizes to size and sets all values to t.
|
// Resizes to size and sets all values to t.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void GenericVector<T>::init_to_size(int size, T t) {
|
void GenericVector<T>::init_to_size(int size, const T& t) {
|
||||||
reserve(size);
|
reserve(size);
|
||||||
size_used_ = size;
|
size_used_ = size;
|
||||||
for (int i = 0; i < size; ++i)
|
for (int i = 0; i < size; ++i)
|
||||||
@ -740,7 +740,7 @@ T GenericVector<T>::pop_back() {
|
|||||||
|
|
||||||
// Return the object from an index.
|
// Return the object from an index.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void GenericVector<T>::set(T t, int index) {
|
void GenericVector<T>::set(const T& t, int index) {
|
||||||
assert(index >= 0 && index < size_used_);
|
assert(index >= 0 && index < size_used_);
|
||||||
data_[index] = t;
|
data_[index] = t;
|
||||||
}
|
}
|
||||||
@ -749,7 +749,7 @@ void GenericVector<T>::set(T t, int index) {
|
|||||||
// space for the new elements and inserts the given element
|
// space for the new elements and inserts the given element
|
||||||
// at the specified index.
|
// at the specified index.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void GenericVector<T>::insert(T t, int index) {
|
void GenericVector<T>::insert(const T& t, int index) {
|
||||||
assert(index >= 0 && index <= size_used_);
|
assert(index >= 0 && index <= size_used_);
|
||||||
if (size_reserved_ == size_used_)
|
if (size_reserved_ == size_used_)
|
||||||
double_the_size();
|
double_the_size();
|
||||||
@ -779,7 +779,7 @@ T GenericVector<T>::contains_index(int index) const {
|
|||||||
|
|
||||||
// Return the index of the T object.
|
// Return the index of the T object.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
int GenericVector<T>::get_index(T object) const {
|
int GenericVector<T>::get_index(const T& object) const {
|
||||||
for (int i = 0; i < size_used_; ++i) {
|
for (int i = 0; i < size_used_; ++i) {
|
||||||
assert(compare_cb_ != nullptr);
|
assert(compare_cb_ != nullptr);
|
||||||
if (compare_cb_->Run(object, data_[i]))
|
if (compare_cb_->Run(object, data_[i]))
|
||||||
@ -790,7 +790,7 @@ int GenericVector<T>::get_index(T object) const {
|
|||||||
|
|
||||||
// Return true if T is in the array
|
// Return true if T is in the array
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool GenericVector<T>::contains(T object) const {
|
bool GenericVector<T>::contains(const T& object) const {
|
||||||
return get_index(object) != -1;
|
return get_index(object) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -806,7 +806,7 @@ int GenericVector<T>::push_back(T object) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
int GenericVector<T>::push_back_new(T object) {
|
int GenericVector<T>::push_back_new(const T& object) {
|
||||||
int index = get_index(object);
|
int index = get_index(object);
|
||||||
if (index >= 0)
|
if (index >= 0)
|
||||||
return index;
|
return index;
|
||||||
@ -815,7 +815,7 @@ int GenericVector<T>::push_back_new(T object) {
|
|||||||
|
|
||||||
// Add an element in the array (front)
|
// Add an element in the array (front)
|
||||||
template <typename T>
|
template <typename T>
|
||||||
int GenericVector<T>::push_front(T object) {
|
int GenericVector<T>::push_front(const T& object) {
|
||||||
if (size_used_ == size_reserved_)
|
if (size_used_ == size_reserved_)
|
||||||
double_the_size();
|
double_the_size();
|
||||||
for (int i = size_used_; i > 0; --i)
|
for (int i = size_used_; i > 0; --i)
|
||||||
@ -826,7 +826,7 @@ int GenericVector<T>::push_front(T object) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void GenericVector<T>::operator+=(T t) {
|
void GenericVector<T>::operator+=(const T& t) {
|
||||||
push_back(t);
|
push_back(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,6 @@ int Wordrec::angle_change(EDGEPT *point1, EDGEPT *point2, EDGEPT *point3) {
|
|||||||
VECTOR vector2;
|
VECTOR vector2;
|
||||||
|
|
||||||
int angle;
|
int angle;
|
||||||
float length;
|
|
||||||
|
|
||||||
/* Compute angle */
|
/* Compute angle */
|
||||||
vector1.x = point2->pos.x - point1->pos.x;
|
vector1.x = point2->pos.x - point1->pos.x;
|
||||||
@ -97,7 +96,7 @@ int Wordrec::angle_change(EDGEPT *point1, EDGEPT *point2, EDGEPT *point3) {
|
|||||||
vector2.x = point3->pos.x - point2->pos.x;
|
vector2.x = point3->pos.x - point2->pos.x;
|
||||||
vector2.y = point3->pos.y - point2->pos.y;
|
vector2.y = point3->pos.y - point2->pos.y;
|
||||||
/* Use cross product */
|
/* Use cross product */
|
||||||
length = (float)sqrt((float)LENGTH(vector1) * LENGTH(vector2));
|
float length = std::sqrt(static_cast<float>(LENGTH(vector1)) * LENGTH(vector2));
|
||||||
if ((int) length == 0)
|
if ((int) length == 0)
|
||||||
return (0);
|
return (0);
|
||||||
angle = static_cast<int>(floor(asin(CROSS (vector1, vector2) /
|
angle = static_cast<int>(floor(asin(CROSS (vector1, vector2) /
|
||||||
|
Loading…
Reference in New Issue
Block a user