Tesseract
3.02
|
#include <intfeaturespace.h>
Public Member Functions | |
IntFeatureSpace () | |
void | Init (uinT8 xbuckets, uinT8 ybuckets, uinT8 thetabuckets) |
bool | Serialize (FILE *fp) const |
bool | DeSerialize (bool swap, FILE *fp) |
int | Size () const |
INT_FEATURE_STRUCT | PositionFromIndex (int index) const |
int | Index (const INT_FEATURE_STRUCT &f) const |
void | IndexFeatures (const INT_FEATURE_STRUCT *features, int num_features, GenericVector< int > *mapped_features) const |
void | IndexAndSortFeatures (const INT_FEATURE_STRUCT *features, int num_features, GenericVector< int > *sorted_features) const |
int | XYToFeatureIndex (int x, int y) const |
Protected Member Functions | |
int | XBucket (int x) const |
int | YBucket (int y) const |
int | ThetaBucket (int theta) const |
INT_FEATURE_STRUCT | PositionFromBuckets (int x, int y, int theta) const |
Protected Attributes | |
uinT8 | x_buckets_ |
uinT8 | y_buckets_ |
uinT8 | theta_buckets_ |
Definition at line 38 of file intfeaturespace.h.
tesseract::IntFeatureSpace::IntFeatureSpace | ( | ) |
Definition at line 25 of file intfeaturespace.cpp.
: x_buckets_(0), y_buckets_(0), theta_buckets_(0) { }
bool tesseract::IntFeatureSpace::DeSerialize | ( | bool | swap, |
FILE * | fp | ||
) |
Definition at line 50 of file intfeaturespace.cpp.
{ if (fread(&x_buckets_, sizeof(x_buckets_), 1, fp) != 1) return false; if (fread(&y_buckets_, sizeof(y_buckets_), 1, fp) != 1) return false; if (fread(&theta_buckets_, sizeof(theta_buckets_), 1, fp) != 1) return false; return true; }
int tesseract::IntFeatureSpace::Index | ( | const INT_FEATURE_STRUCT & | f | ) | const [inline] |
Definition at line 65 of file intfeaturespace.h.
{ return (XBucket(f.X) * y_buckets_ + YBucket(f.Y)) * theta_buckets_ + ThetaBucket(f.Theta); }
void tesseract::IntFeatureSpace::IndexAndSortFeatures | ( | const INT_FEATURE_STRUCT * | features, |
int | num_features, | ||
GenericVector< int > * | sorted_features | ||
) | const |
void tesseract::IntFeatureSpace::IndexFeatures | ( | const INT_FEATURE_STRUCT * | features, |
int | num_features, | ||
GenericVector< int > * | mapped_features | ||
) | const |
Definition at line 29 of file intfeaturespace.cpp.
{ x_buckets_ = xbuckets; y_buckets_ = ybuckets; theta_buckets_ = thetabuckets; }
INT_FEATURE_STRUCT tesseract::IntFeatureSpace::PositionFromBuckets | ( | int | x, |
int | y, | ||
int | theta | ||
) | const [protected] |
Definition at line 127 of file intfeaturespace.cpp.
{ INT_FEATURE_STRUCT pos = { static_cast<uinT8>(ClipToRange( (x * kIntFeatureExtent + kIntFeatureExtent / 2) / x_buckets_, 0, MAX_UINT8)), static_cast<uinT8>(ClipToRange( (y * kIntFeatureExtent + kIntFeatureExtent / 2) / y_buckets_, 0, MAX_UINT8)), static_cast<uinT8>(ClipToRange( DivRounded(theta * kIntFeatureExtent, theta_buckets_), 0, MAX_UINT8))}; return pos; }
INT_FEATURE_STRUCT tesseract::IntFeatureSpace::PositionFromIndex | ( | int | index | ) | const |
Definition at line 62 of file intfeaturespace.cpp.
{ return PositionFromBuckets(index / (y_buckets_ * theta_buckets_), index / theta_buckets_ % y_buckets_, index % theta_buckets_); }
bool tesseract::IntFeatureSpace::Serialize | ( | FILE * | fp | ) | const |
Definition at line 37 of file intfeaturespace.cpp.
{ if (fwrite(&x_buckets_, sizeof(x_buckets_), 1, fp) != 1) return false; if (fwrite(&y_buckets_, sizeof(y_buckets_), 1, fp) != 1) return false; if (fwrite(&theta_buckets_, sizeof(theta_buckets_), 1, fp) != 1) return false; return true; }
int tesseract::IntFeatureSpace::Size | ( | ) | const [inline] |
Definition at line 56 of file intfeaturespace.h.
{ return static_cast<int>(x_buckets_) * y_buckets_ * theta_buckets_; }
int tesseract::IntFeatureSpace::ThetaBucket | ( | int | theta | ) | const [inline, protected] |
Definition at line 94 of file intfeaturespace.h.
{ int bucket = DivRounded(theta * theta_buckets_, kIntFeatureExtent); return Modulo(bucket, theta_buckets_); }
int tesseract::IntFeatureSpace::XBucket | ( | int | x | ) | const [inline, protected] |
Definition at line 84 of file intfeaturespace.h.
{ int bucket = x * x_buckets_ / kIntFeatureExtent; return ClipToRange(bucket, 0, static_cast<int>(x_buckets_) - 1); }
int tesseract::IntFeatureSpace::XYToFeatureIndex | ( | int | x, |
int | y | ||
) | const |
Definition at line 91 of file intfeaturespace.cpp.
{ // Round the x,y position to a feature. Search for a valid theta. INT_FEATURE_STRUCT feature = {static_cast<uinT8>(x), static_cast<uinT8>(y), 0, 0}; int index = -1; for (int theta = 0; theta <= MAX_UINT8 && index < 0; ++theta) { feature.Theta = theta; index = Index(feature); } if (index < 0) { tprintf("(%d,%d) does not exist in feature space!\n", x, y); return -1; } feature = PositionFromIndex(index); tprintf("Click at (%d, %d) ->(%d, %d), ->(%d, %d)\n", x, y, feature.X, feature.Y, x - feature.X, y - feature.Y); // Get the relative position of x,y from the rounded feature. x -= feature.X; y -= feature.Y; if (x != 0 || y != 0) { double angle = atan2(static_cast<double>(y), static_cast<double>(x)) + PI; angle *= kIntFeatureExtent / (2.0 * PI); feature.Theta = static_cast<uinT8>(angle + 0.5); index = Index(feature); if (index < 0) { tprintf("Feature failed to map to a valid index:"); feature.print(); return -1; } feature = PositionFromIndex(index); } feature.print(); return index; }
int tesseract::IntFeatureSpace::YBucket | ( | int | y | ) | const [inline, protected] |
Definition at line 88 of file intfeaturespace.h.
{ int bucket = y * y_buckets_ / kIntFeatureExtent; return ClipToRange(bucket, 0, static_cast<int>(y_buckets_) - 1); }
uinT8 tesseract::IntFeatureSpace::theta_buckets_ [protected] |
Definition at line 104 of file intfeaturespace.h.
uinT8 tesseract::IntFeatureSpace::x_buckets_ [protected] |
Definition at line 102 of file intfeaturespace.h.
uinT8 tesseract::IntFeatureSpace::y_buckets_ [protected] |
Definition at line 103 of file intfeaturespace.h.