mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-11-24 02:59:07 +08:00
Merge branch 'master' into disable-legacy
This commit is contained in:
commit
62c7b796da
@ -2,3 +2,4 @@
|
||||
BasedOnStyle: Google
|
||||
# Enforce always the same pointer alignment.
|
||||
DerivePointerAlignment: false
|
||||
IndentPPDirectives: AfterHash
|
||||
|
@ -10,7 +10,6 @@ You need Leptonica 1.74.2 (minimum) for Tesseract 4.0x.
|
||||
|
||||
Known dependencies for training tools (excluding leptonica):
|
||||
* compiler with c++11 support
|
||||
* autoconf-archive
|
||||
* automake
|
||||
* pkg-config
|
||||
* pango-devel
|
||||
|
@ -113,13 +113,6 @@ automake --add-missing --copy --warnings=all || bail_out
|
||||
echo "Running autoconf"
|
||||
autoconf || bail_out
|
||||
|
||||
if grep -q AX_CHECK_COMPILE_FLAG configure; then
|
||||
# The generated configure is invalid because autoconf-archive is unavailable.
|
||||
rm configure
|
||||
echo "Missing autoconf-archive. Check the build requirements."
|
||||
bail_out
|
||||
fi
|
||||
|
||||
if grep -q PKG_CHECK_MODULES configure; then
|
||||
# The generated configure is invalid because pkg-config is unavailable.
|
||||
rm configure
|
||||
|
@ -43,8 +43,8 @@ OPTIONS
|
||||
'--user-words /path/to/file'::
|
||||
Specify the location of user words file
|
||||
|
||||
'--user-patterns /path/to/file specify'::
|
||||
The location of user patterns file
|
||||
'--user-patterns /path/to/file'::
|
||||
Specify the location of user patterns file
|
||||
|
||||
'-c configvar=value'::
|
||||
Set value for control parameter. Multiple -c arguments are allowed.
|
||||
|
@ -96,6 +96,10 @@ public class ScrollView {
|
||||
!socket.isOutputShutdown() &&
|
||||
socket.isConnected() && socket.isBound()) {
|
||||
inputLine = receiveMessage();
|
||||
if (inputLine == null) {
|
||||
// End of stream reached.
|
||||
break;
|
||||
}
|
||||
nrInputLines++;
|
||||
if (debugViewNetworkTraffic) {
|
||||
System.out.println("(c->S," + nrInputLines + ")" + inputLine);
|
||||
@ -380,7 +384,7 @@ public class ScrollView {
|
||||
System.out.println("Client connected");
|
||||
|
||||
// Setup the streams
|
||||
out = new PrintStream(socket.getOutputStream(), true);
|
||||
out = new PrintStream(socket.getOutputStream(), true, "UTF-8");
|
||||
in =
|
||||
new BufferedReader(new InputStreamReader(socket.getInputStream(),
|
||||
"UTF8"));
|
||||
|
@ -28,6 +28,7 @@ import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
import java.awt.Window;
|
||||
|
||||
import javax.swing.Timer;
|
||||
|
||||
@ -262,7 +263,10 @@ public class SVEventHandler extends PBasicInputEventHandler implements
|
||||
public void windowClosing(WindowEvent e) {
|
||||
processEvent(new SVEvent(SVEventType.SVET_DESTROY, svWindow, lastXMove,
|
||||
lastYMove, 0, 0, null));
|
||||
e.getWindow().dispose();
|
||||
Window w = e.getWindow();
|
||||
if (w != null) {
|
||||
w.dispose();
|
||||
}
|
||||
SVWindow.nrWindows--;
|
||||
if (SVWindow.nrWindows == 0) {
|
||||
processEvent(new SVEvent(SVEventType.SVET_EXIT, svWindow, lastXMove,
|
||||
|
@ -29,7 +29,6 @@ import javax.swing.JCheckBoxMenuItem;
|
||||
* Constructs a new menulistitem which possesses a flag that can be toggled.
|
||||
*/
|
||||
class SVCheckboxMenuItem extends SVAbstractMenuItem {
|
||||
public String value = null;
|
||||
public boolean bvalue;
|
||||
|
||||
SVCheckboxMenuItem(int id, String name, boolean val) {
|
||||
|
@ -606,6 +606,8 @@ public class SVWindow extends JFrame {
|
||||
* Shows a dialog presenting "Yes" and "No" as answers and returns either a
|
||||
* "y" or "n" to the client.
|
||||
*
|
||||
* Closing the dialog without answering is handled like "No".
|
||||
*
|
||||
* @param msg The text that is displayed in the dialog.
|
||||
*/
|
||||
public void showYesNoDialog(String msg) {
|
||||
@ -613,13 +615,9 @@ public class SVWindow extends JFrame {
|
||||
int res =
|
||||
JOptionPane.showOptionDialog(this, msg, "", JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE, null, null, null);
|
||||
SVEvent e = null;
|
||||
|
||||
if (res == 0) {
|
||||
e = new SVEvent(SVEventType.SVET_INPUT, this, 0, 0, 0, 0, "y");
|
||||
} else if (res == 1) {
|
||||
e = new SVEvent(SVEventType.SVET_INPUT, this, 0, 0, 0, 0, "n");
|
||||
}
|
||||
SVEvent e = new SVEvent(SVEventType.SVET_INPUT, this, 0, 0, 0, 0,
|
||||
res == 0 ? "y" : "n");
|
||||
ScrollView.addMessage(e);
|
||||
}
|
||||
|
||||
|
53
m4/ax_check_compile_flag.m4
Normal file
53
m4/ax_check_compile_flag.m4
Normal file
@ -0,0 +1,53 @@
|
||||
# ===========================================================================
|
||||
# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
|
||||
# ===========================================================================
|
||||
#
|
||||
# SYNOPSIS
|
||||
#
|
||||
# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# Check whether the given FLAG works with the current language's compiler
|
||||
# or gives an error. (Warnings, however, are ignored)
|
||||
#
|
||||
# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
|
||||
# success/failure.
|
||||
#
|
||||
# If EXTRA-FLAGS is defined, it is added to the current language's default
|
||||
# flags (e.g. CFLAGS) when the check is done. The check is thus made with
|
||||
# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to
|
||||
# force the compiler to issue an error when a bad flag is given.
|
||||
#
|
||||
# INPUT gives an alternative input source to AC_COMPILE_IFELSE.
|
||||
#
|
||||
# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
|
||||
# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
|
||||
#
|
||||
# LICENSE
|
||||
#
|
||||
# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
|
||||
# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty provided the copyright notice
|
||||
# and this notice are preserved. This file is offered as-is, without any
|
||||
# warranty.
|
||||
|
||||
#serial 6
|
||||
|
||||
AC_DEFUN([AX_CHECK_COMPILE_FLAG],
|
||||
[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
|
||||
AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
|
||||
AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
|
||||
ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
|
||||
_AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
|
||||
AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
|
||||
[AS_VAR_SET(CACHEVAR,[yes])],
|
||||
[AS_VAR_SET(CACHEVAR,[no])])
|
||||
_AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
|
||||
AS_VAR_IF(CACHEVAR,yes,
|
||||
[m4_default([$2], :)],
|
||||
[m4_default([$3], :)])
|
||||
AS_VAR_POPDEF([CACHEVAR])dnl
|
||||
])dnl AX_CHECK_COMPILE_FLAGS
|
38
m4/ax_split_version.m4
Normal file
38
m4/ax_split_version.m4
Normal file
@ -0,0 +1,38 @@
|
||||
# ===========================================================================
|
||||
# https://www.gnu.org/software/autoconf-archive/ax_split_version.html
|
||||
# ===========================================================================
|
||||
#
|
||||
# SYNOPSIS
|
||||
#
|
||||
# AX_SPLIT_VERSION
|
||||
#
|
||||
# DESCRIPTION
|
||||
#
|
||||
# Splits a version number in the format MAJOR.MINOR.POINT into its
|
||||
# separate components.
|
||||
#
|
||||
# Sets the variables.
|
||||
#
|
||||
# LICENSE
|
||||
#
|
||||
# Copyright (c) 2008 Tom Howard <tomhoward@users.sf.net>
|
||||
#
|
||||
# Copying and distribution of this file, with or without modification, are
|
||||
# permitted in any medium without royalty provided the copyright notice
|
||||
# and this notice are preserved. This file is offered as-is, without any
|
||||
# warranty.
|
||||
|
||||
#serial 10
|
||||
|
||||
AC_DEFUN([AX_SPLIT_VERSION],[
|
||||
AC_REQUIRE([AC_PROG_SED])
|
||||
AX_MAJOR_VERSION=`echo "$VERSION" | $SED 's/\([[^.]][[^.]]*\).*/\1/'`
|
||||
AX_MINOR_VERSION=`echo "$VERSION" | $SED 's/[[^.]][[^.]]*.\([[^.]][[^.]]*\).*/\1/'`
|
||||
AX_POINT_VERSION=`echo "$VERSION" | $SED 's/[[^.]][[^.]]*.[[^.]][[^.]]*.\(.*\)/\1/'`
|
||||
AC_MSG_CHECKING([Major version])
|
||||
AC_MSG_RESULT([$AX_MAJOR_VERSION])
|
||||
AC_MSG_CHECKING([Minor version])
|
||||
AC_MSG_RESULT([$AX_MINOR_VERSION])
|
||||
AC_MSG_CHECKING([Point version])
|
||||
AC_MSG_RESULT([$AX_POINT_VERSION])
|
||||
])
|
@ -19,7 +19,6 @@ parts:
|
||||
source: .
|
||||
plugin: autotools
|
||||
build-packages:
|
||||
- autoconf-archive
|
||||
- pkg-config
|
||||
- libpng12-dev
|
||||
- libjpeg8-dev
|
||||
|
@ -2026,39 +2026,39 @@ bool TessBaseAPI::AdaptToWordStr(PageSegMode mode, const char* wordstr) {
|
||||
WERD_RES* word_res = it.word();
|
||||
if (word_res != nullptr) {
|
||||
word_res->word->set_text(wordstr);
|
||||
// Check to see if text matches wordstr.
|
||||
int w = 0;
|
||||
int t;
|
||||
for (t = 0; text[t] != '\0'; ++t) {
|
||||
if (text[t] == '\n' || text[t] == ' ')
|
||||
continue;
|
||||
while (wordstr[w] == ' ') ++w;
|
||||
if (text[t] != wordstr[w])
|
||||
break;
|
||||
++w;
|
||||
}
|
||||
if (text[t] != '\0' || wordstr[w] != '\0') {
|
||||
// No match.
|
||||
delete page_res_;
|
||||
GenericVector<TBOX> boxes;
|
||||
page_res_ = tesseract_->SetupApplyBoxes(boxes, block_list_);
|
||||
tesseract_->ReSegmentByClassification(page_res_);
|
||||
tesseract_->TidyUp(page_res_);
|
||||
PAGE_RES_IT pr_it(page_res_);
|
||||
if (pr_it.word() == nullptr)
|
||||
success = false;
|
||||
else
|
||||
word_res = pr_it.word();
|
||||
} else {
|
||||
word_res->BestChoiceToCorrectText();
|
||||
}
|
||||
if (success) {
|
||||
tesseract_->EnableLearning = true;
|
||||
tesseract_->LearnWord(nullptr, word_res);
|
||||
}
|
||||
} else {
|
||||
success = false;
|
||||
}
|
||||
// Check to see if text matches wordstr.
|
||||
int w = 0;
|
||||
int t = 0;
|
||||
for (t = 0; text[t] != '\0'; ++t) {
|
||||
if (text[t] == '\n' || text[t] == ' ')
|
||||
continue;
|
||||
while (wordstr[w] == ' ') ++w;
|
||||
if (text[t] != wordstr[w])
|
||||
break;
|
||||
++w;
|
||||
}
|
||||
if (text[t] != '\0' || wordstr[w] != '\0') {
|
||||
// No match.
|
||||
delete page_res_;
|
||||
GenericVector<TBOX> boxes;
|
||||
page_res_ = tesseract_->SetupApplyBoxes(boxes, block_list_);
|
||||
tesseract_->ReSegmentByClassification(page_res_);
|
||||
tesseract_->TidyUp(page_res_);
|
||||
PAGE_RES_IT pr_it(page_res_);
|
||||
if (pr_it.word() == nullptr)
|
||||
success = false;
|
||||
else
|
||||
word_res = pr_it.word();
|
||||
} else {
|
||||
word_res->BestChoiceToCorrectText();
|
||||
}
|
||||
if (success) {
|
||||
tesseract_->EnableLearning = true;
|
||||
tesseract_->LearnWord(nullptr, word_res);
|
||||
}
|
||||
} else {
|
||||
success = false;
|
||||
}
|
||||
@ -2468,7 +2468,7 @@ void TessBaseAPI::GetBlockTextOrientations(int** block_orientation,
|
||||
float re_theta = re_rotation.angle();
|
||||
FCOORD classify_rotation = block_it.data()->classify_rotation();
|
||||
float classify_theta = classify_rotation.angle();
|
||||
double rot_theta = - (re_theta - classify_theta) * 2.0 / PI;
|
||||
double rot_theta = - (re_theta - classify_theta) * 2.0 / M_PI;
|
||||
if (rot_theta < 0) rot_theta += 4;
|
||||
int num_rotations = static_cast<int>(rot_theta + 0.5);
|
||||
(*block_orientation)[i] = num_rotations;
|
||||
@ -2537,7 +2537,7 @@ STRING HOcrEscape(const char* text) {
|
||||
|
||||
/** Find lines from the image making the BLOCK_LIST. */
|
||||
BLOCK_LIST* TessBaseAPI::FindLinesCreateBlockList() {
|
||||
FindLines();
|
||||
ASSERT_HOST(FindLines() == 0);
|
||||
BLOCK_LIST* result = block_list_;
|
||||
block_list_ = nullptr;
|
||||
return result;
|
||||
@ -2694,7 +2694,11 @@ struct TESS_CHAR : ELIST_LINK {
|
||||
strncpy(unicode_repr, repr, length);
|
||||
}
|
||||
|
||||
TESS_CHAR() { // Satisfies ELISTIZE.
|
||||
TESS_CHAR()
|
||||
: unicode_repr(nullptr),
|
||||
length(0),
|
||||
cost(0.0f)
|
||||
{ // Satisfies ELISTIZE.
|
||||
}
|
||||
~TESS_CHAR() {
|
||||
delete [] unicode_repr;
|
||||
|
@ -293,16 +293,16 @@ void AffineMatrix(int writing_direction,
|
||||
// these viewers. I chose this threshold large enough to absorb noise,
|
||||
// but small enough that lines probably won't cross each other if the
|
||||
// whole page is tilted at almost exactly the clipping threshold.
|
||||
void ClipBaseline(int ppi, int x1, int y1, int x2, int y2,
|
||||
int *line_x1, int *line_y1,
|
||||
int *line_x2, int *line_y2) {
|
||||
static void ClipBaseline(int ppi, int x1, int y1, int x2, int y2,
|
||||
int *line_x1, int *line_y1,
|
||||
int *line_x2, int *line_y2) {
|
||||
*line_x1 = x1;
|
||||
*line_y1 = y1;
|
||||
*line_x2 = x2;
|
||||
*line_y2 = y2;
|
||||
double rise = abs(y2 - y1) * 72 / ppi;
|
||||
double run = abs(x2 - x1) * 72 / ppi;
|
||||
if (rise < 2.0 && 2.0 < run)
|
||||
int rise = abs(y2 - y1) * 72;
|
||||
int run = abs(x2 - x1) * 72;
|
||||
if (rise < 2 * ppi && 2 * ppi < run)
|
||||
*line_y1 = *line_y2 = (y1 + y2) / 2;
|
||||
}
|
||||
|
||||
|
@ -321,11 +321,10 @@ void Tesseract::MaximallyChopWord(const GenericVector<TBOX>& boxes,
|
||||
/// miss metric gets the blob.
|
||||
static double BoxMissMetric(const TBOX& box1, const TBOX& box2) {
|
||||
const int overlap_area = box1.intersection(box2).area();
|
||||
double miss_metric = box1.area()- overlap_area;
|
||||
miss_metric /= box1.area();
|
||||
miss_metric *= box2.area() - overlap_area;
|
||||
miss_metric /= box2.area();
|
||||
return miss_metric;
|
||||
const int a = box1.area();
|
||||
const int b = box2.area();
|
||||
ASSERT_HOST(a != 0 && b != 0);
|
||||
return 1.0 * (a - overlap_area) * (b - overlap_area) / a / b;
|
||||
}
|
||||
|
||||
#ifndef DISABLED_LEGACY_ENGINE
|
||||
|
@ -1,8 +1,8 @@
|
||||
/******************************************************************
|
||||
* File: control.cpp (Formerly control.c)
|
||||
* Description: Module-independent matcher controller.
|
||||
* Author: Ray Smith
|
||||
* Created: Thu Apr 23 11:09:58 BST 1992
|
||||
* Author: Ray Smith
|
||||
* Created: Thu Apr 23 11:09:58 BST 1992
|
||||
* ReHacked: Tue Sep 22 08:42:49 BST 1992 Phil Cheatle
|
||||
*
|
||||
* (C) Copyright 1992, Hewlett-Packard Ltd.
|
||||
@ -599,9 +599,6 @@ void Tesseract::bigram_correction_pass(PAGE_RES *page_res) {
|
||||
WERD_CHOICE *p1 = overrides_word1[i];
|
||||
WERD_CHOICE *p2 = overrides_word2[i];
|
||||
bigrams_list += p1->unichar_string() + " " + p2->unichar_string();
|
||||
if (i == kMaxChoicesToPrint) {
|
||||
bigrams_list += " ...";
|
||||
}
|
||||
}
|
||||
choices_description = "There were many choices: {";
|
||||
choices_description += bigrams_list;
|
||||
@ -1248,6 +1245,7 @@ float Tesseract::ClassifyBlobPlusOutlines(
|
||||
#ifndef DISABLED_LEGACY_ENGINE
|
||||
C_OUTLINE_IT ol_it;
|
||||
C_OUTLINE* first_to_keep = nullptr;
|
||||
C_BLOB* local_blob = nullptr;
|
||||
if (blob != nullptr) {
|
||||
// Add the required outlines to the blob.
|
||||
ol_it.set_to_list(blob->out_list());
|
||||
@ -1257,7 +1255,8 @@ float Tesseract::ClassifyBlobPlusOutlines(
|
||||
if (ok_outlines[i]) {
|
||||
// This outline is to be added.
|
||||
if (blob == nullptr) {
|
||||
blob = new C_BLOB(outlines[i]);
|
||||
local_blob = new C_BLOB(outlines[i]);
|
||||
blob = local_blob;
|
||||
ol_it.set_to_list(blob->out_list());
|
||||
} else {
|
||||
ol_it.add_before_stay_put(outlines[i]);
|
||||
@ -1270,7 +1269,7 @@ float Tesseract::ClassifyBlobPlusOutlines(
|
||||
if (first_to_keep == nullptr) {
|
||||
// We created blob. Empty its outlines and delete it.
|
||||
for (; !ol_it.empty(); ol_it.forward()) ol_it.extract();
|
||||
delete blob;
|
||||
delete local_blob;
|
||||
cert = -c2;
|
||||
} else {
|
||||
// Remove the outlines that we put in.
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: fixxht.cpp (Formerly fixxht.c)
|
||||
* Description: Improve x_ht and look out for case inconsistencies
|
||||
* Author: Phil Cheatle
|
||||
* Created: Thu Aug 5 14:11:08 BST 1993
|
||||
* Author: Phil Cheatle
|
||||
* Created: Thu Aug 5 14:11:08 BST 1993
|
||||
*
|
||||
* (C) Copyright 1992, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -21,7 +21,6 @@
|
||||
|
||||
#include "boxread.h"
|
||||
#include "control.h"
|
||||
#include "cutil.h"
|
||||
#include "host.h"
|
||||
#include "ratngs.h"
|
||||
#include "reject.h"
|
||||
@ -45,7 +44,11 @@ FILE *Tesseract::init_recog_training(const STRING &fname) {
|
||||
const char *lastdot = strrchr(output_fname.string(), '.');
|
||||
if (lastdot != nullptr) output_fname[lastdot - output_fname.string()] = '\0';
|
||||
output_fname += ".txt";
|
||||
FILE *output_file = open_file(output_fname.string(), "a+");
|
||||
FILE *output_file = fopen(output_fname.string(), "a+");
|
||||
if (output_file == nullptr) {
|
||||
tprintf("Error: Could not open file %s\n", output_fname.string());
|
||||
ASSERT_HOST(output_file);
|
||||
}
|
||||
return output_file;
|
||||
}
|
||||
|
||||
@ -85,7 +88,11 @@ void Tesseract::recog_training_segmented(const STRING &fname,
|
||||
if (lastdot != nullptr) box_fname[lastdot - box_fname.string()] = '\0';
|
||||
box_fname += ".box";
|
||||
// ReadNextBox() will close box_file
|
||||
FILE *box_file = open_file(box_fname.string(), "r");
|
||||
FILE *box_file = fopen(box_fname.string(), "r");
|
||||
if (box_file == nullptr) {
|
||||
tprintf("Error: Could not open file %s\n", box_fname.string());
|
||||
ASSERT_HOST(box_file);
|
||||
}
|
||||
|
||||
PAGE_RES_IT page_res_it;
|
||||
page_res_it.page_res = page_res;
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include "control.h"
|
||||
#include "reject.h"
|
||||
#include "pageres.h"
|
||||
#include "nwmain.h"
|
||||
#include "pgedit.h"
|
||||
#include "tprintf.h"
|
||||
#include "tessedit.h"
|
||||
@ -38,8 +37,6 @@
|
||||
#include "intmatcher.h"
|
||||
#include "chop.h"
|
||||
#endif
|
||||
#include "efio.h"
|
||||
#include "danerror.h"
|
||||
#include "globals.h"
|
||||
#ifndef ANDROID_BUILD
|
||||
#include "lstmrecognizer.h"
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: tessvars.cpp (Formerly tessvars.c)
|
||||
* Description: Variables and other globals for tessedit.
|
||||
* Author: Ray Smith
|
||||
* Created: Mon Apr 13 13:13:23 BST 1992
|
||||
* Author: Ray Smith
|
||||
* Created: Mon Apr 13 13:13:23 BST 1992
|
||||
*
|
||||
* (C) Copyright 1992, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: tessvars.h (Formerly tessvars.h)
|
||||
* Description: Variables and other globals for tessedit.
|
||||
* Author: Ray Smith
|
||||
* Created: Mon Apr 13 13:13:23 BST 1992
|
||||
* Author: Ray Smith
|
||||
* Created: Mon Apr 13 13:13:23 BST 1992
|
||||
*
|
||||
* (C) Copyright 1992, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -17,11 +17,11 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef TESSVARS_H
|
||||
#define TESSVARS_H
|
||||
#ifndef TESSVARS_H
|
||||
#define TESSVARS_H
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
extern FILE *debug_fp; // write debug stuff here
|
||||
|
||||
#endif
|
||||
|
@ -12,8 +12,9 @@ endif
|
||||
|
||||
pkginclude_HEADERS = publictypes.h
|
||||
noinst_HEADERS = \
|
||||
blamer.h blckerr.h blobbox.h blobs.h blread.h boxread.h boxword.h ccstruct.h coutln.h crakedge.h \
|
||||
debugpixa.h detlinefit.h dppoint.h fontinfo.h genblob.h hpdsizes.h \
|
||||
blamer.h blobbox.h blobs.h blread.h boxread.h boxword.h \
|
||||
ccstruct.h coutln.h crakedge.h \
|
||||
debugpixa.h detlinefit.h dppoint.h fontinfo.h genblob.h \
|
||||
imagedata.h \
|
||||
ipoints.h \
|
||||
linlsq.h matrix.h mod128.h normalis.h \
|
||||
|
@ -1,29 +0,0 @@
|
||||
/**********************************************************************
|
||||
* File: blckerr.h (Formerly blockerr.h)
|
||||
* Description: Error codes for the page block classes.
|
||||
* Author: Ray Smith
|
||||
* Created: Tue Mar 19 17:43:30 GMT 1991
|
||||
*
|
||||
* (C) Copyright 1991, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
** http://www.apache.org/licenses/LICENSE-2.0
|
||||
** Unless required by applicable law or agreed to in writing, software
|
||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef BLCKERR_H
|
||||
#define BLCKERR_H
|
||||
|
||||
#include "errcode.h"
|
||||
|
||||
const ERRCODE BADBLOCKLINE = "Y coordinate in block out of bounds";
|
||||
const ERRCODE LOSTBLOCKLINE = "Can't find rectangle for line";
|
||||
const ERRCODE ILLEGAL_GRADIENT = "Gradient wrong side of edge step!";
|
||||
const ERRCODE WRONG_WORD = "Word doesn't have blobs of that type";
|
||||
#endif
|
@ -34,7 +34,6 @@
|
||||
#include "blobs.h"
|
||||
#include "ccstruct.h"
|
||||
#include "clst.h"
|
||||
#include "cutil.h"
|
||||
#include "emalloc.h"
|
||||
#include "helpers.h"
|
||||
#include "linlsq.h"
|
||||
@ -108,16 +107,15 @@ TESSLINE* TESSLINE::BuildFromOutlineList(EDGEPT* outline) {
|
||||
if (outline->src_outline != nullptr) {
|
||||
// ASSUMPTION: This function is only ever called from ApproximateOutline
|
||||
// and therefore either all points have a src_outline or all do not.
|
||||
// Just as SetupFromPos sets the vectors from the vertices, setup the
|
||||
// step_count members to indicate the (positive) number of original
|
||||
// C_OUTLINE steps to the next vertex.
|
||||
EDGEPT* pt = outline;
|
||||
do {
|
||||
pt->step_count = pt->next->start_step - pt->start_step;
|
||||
if (pt->step_count < 0)
|
||||
pt->step_count += pt->src_outline->pathlength();
|
||||
pt = pt->next;
|
||||
} while (pt != outline);
|
||||
// Just as SetupFromPos sets the vectors from the vertices, setup the
|
||||
// step_count members to indicate the (positive) number of original
|
||||
// C_OUTLINE steps to the next vertex.
|
||||
EDGEPT* pt = outline;
|
||||
do {
|
||||
pt->step_count = pt->next->start_step - pt->start_step;
|
||||
if (pt->step_count < 0) pt->step_count += pt->src_outline->pathlength();
|
||||
pt = pt->next;
|
||||
} while (pt != outline);
|
||||
}
|
||||
result->SetupFromPos();
|
||||
return result;
|
||||
@ -152,8 +150,7 @@ void TESSLINE::CopyFrom(const TESSLINE& src) {
|
||||
|
||||
// Deletes owned data.
|
||||
void TESSLINE::Clear() {
|
||||
if (loop == nullptr)
|
||||
return;
|
||||
if (loop == nullptr) return;
|
||||
|
||||
EDGEPT* this_edge = loop;
|
||||
do {
|
||||
@ -178,10 +175,10 @@ void TESSLINE::Normalize(const DENORM& denorm) {
|
||||
void TESSLINE::Rotate(const FCOORD rot) {
|
||||
EDGEPT* pt = loop;
|
||||
do {
|
||||
int tmp = static_cast<int>(floor(pt->pos.x * rot.x() -
|
||||
pt->pos.y * rot.y() + 0.5));
|
||||
pt->pos.y = static_cast<int>(floor(pt->pos.y * rot.x() +
|
||||
pt->pos.x * rot.y() + 0.5));
|
||||
int tmp = static_cast<int>(
|
||||
floor(pt->pos.x * rot.x() - pt->pos.y * rot.y() + 0.5));
|
||||
pt->pos.y = static_cast<int>(
|
||||
floor(pt->pos.y * rot.x() + pt->pos.x * rot.y() + 0.5));
|
||||
pt->pos.x = tmp;
|
||||
pt = pt->next;
|
||||
} while (pt != loop);
|
||||
@ -234,14 +231,10 @@ void TESSLINE::ComputeBoundingBox() {
|
||||
EDGEPT* this_edge = loop;
|
||||
do {
|
||||
if (!this_edge->IsHidden() || !this_edge->prev->IsHidden()) {
|
||||
if (this_edge->pos.x < minx)
|
||||
minx = this_edge->pos.x;
|
||||
if (this_edge->pos.y < miny)
|
||||
miny = this_edge->pos.y;
|
||||
if (this_edge->pos.x > maxx)
|
||||
maxx = this_edge->pos.x;
|
||||
if (this_edge->pos.y > maxy)
|
||||
maxy = this_edge->pos.y;
|
||||
if (this_edge->pos.x < minx) minx = this_edge->pos.x;
|
||||
if (this_edge->pos.y < miny) miny = this_edge->pos.y;
|
||||
if (this_edge->pos.x > maxx) maxx = this_edge->pos.x;
|
||||
if (this_edge->pos.y > maxy) maxy = this_edge->pos.y;
|
||||
}
|
||||
this_edge = this_edge->next;
|
||||
} while (this_edge != loop);
|
||||
@ -257,8 +250,8 @@ void TESSLINE::ComputeBoundingBox() {
|
||||
// this is the left and right edge of the outline perpendicular to the
|
||||
// given direction, but to get the distance units correct, you would
|
||||
// have to divide by the modulus of vec.
|
||||
void TESSLINE::MinMaxCrossProduct(const TPOINT vec,
|
||||
int* min_xp, int* max_xp) const {
|
||||
void TESSLINE::MinMaxCrossProduct(const TPOINT vec, int* min_xp,
|
||||
int* max_xp) const {
|
||||
*min_xp = INT32_MAX;
|
||||
*max_xp = INT32_MIN;
|
||||
EDGEPT* this_edge = loop;
|
||||
@ -319,8 +312,7 @@ EDGEPT* TESSLINE::FindBestStartPt() const {
|
||||
// of the resulting list of TESSLINEs.
|
||||
static TESSLINE** ApproximateOutlineList(bool allow_detailed_fx,
|
||||
C_OUTLINE_LIST* outlines,
|
||||
bool children,
|
||||
TESSLINE** tail) {
|
||||
bool children, TESSLINE** tail) {
|
||||
C_OUTLINE_IT ol_it(outlines);
|
||||
for (ol_it.mark_cycle_pt(); !ol_it.cycled_list(); ol_it.forward()) {
|
||||
C_OUTLINE* outline = ol_it.data();
|
||||
@ -374,11 +366,12 @@ TBLOB* TBLOB::ClassifyNormalizeIfNeeded() const {
|
||||
const FCOORD& rotation = denorm_.block()->classify_rotation();
|
||||
// Move the rotated blob back to the same y-position so that we
|
||||
// can still distinguish similar glyphs with differeny y-position.
|
||||
float target_y = kBlnBaselineOffset +
|
||||
float target_y =
|
||||
kBlnBaselineOffset +
|
||||
(rotation.y() > 0 ? x_middle - box.left() : box.right() - x_middle);
|
||||
rotated_blob->Normalize(nullptr, &rotation, &denorm_, x_middle, y_middle,
|
||||
1.0f, 1.0f, 0.0f, target_y,
|
||||
denorm_.inverse(), denorm_.pix());
|
||||
1.0f, 1.0f, 0.0f, target_y, denorm_.inverse(),
|
||||
denorm_.pix());
|
||||
}
|
||||
return rotated_blob;
|
||||
}
|
||||
@ -411,13 +404,10 @@ void TBLOB::Clear() {
|
||||
// Sets up the built-in DENORM and normalizes the blob in-place.
|
||||
// For parameters see DENORM::SetupNormalization, plus the inverse flag for
|
||||
// this blob and the Pix for the full image.
|
||||
void TBLOB::Normalize(const BLOCK* block,
|
||||
const FCOORD* rotation,
|
||||
const DENORM* predecessor,
|
||||
float x_origin, float y_origin,
|
||||
float x_scale, float y_scale,
|
||||
float final_xshift, float final_yshift,
|
||||
bool inverse, Pix* pix) {
|
||||
void TBLOB::Normalize(const BLOCK* block, const FCOORD* rotation,
|
||||
const DENORM* predecessor, float x_origin, float y_origin,
|
||||
float x_scale, float y_scale, float final_xshift,
|
||||
float final_yshift, bool inverse, Pix* pix) {
|
||||
denorm_.SetupNormalization(block, rotation, predecessor, x_origin, y_origin,
|
||||
x_scale, y_scale, final_xshift, final_yshift);
|
||||
denorm_.set_inverse(inverse);
|
||||
@ -440,28 +430,32 @@ void TBLOB::Normalize(const BLOCK* block,
|
||||
|
||||
// Rotates by the given rotation in place.
|
||||
void TBLOB::Rotate(const FCOORD rotation) {
|
||||
for (TESSLINE* outline = outlines; outline != nullptr; outline = outline->next) {
|
||||
for (TESSLINE* outline = outlines; outline != nullptr;
|
||||
outline = outline->next) {
|
||||
outline->Rotate(rotation);
|
||||
}
|
||||
}
|
||||
|
||||
// Moves by the given vec in place.
|
||||
void TBLOB::Move(const ICOORD vec) {
|
||||
for (TESSLINE* outline = outlines; outline != nullptr; outline = outline->next) {
|
||||
for (TESSLINE* outline = outlines; outline != nullptr;
|
||||
outline = outline->next) {
|
||||
outline->Move(vec);
|
||||
}
|
||||
}
|
||||
|
||||
// Scales by the given factor in place.
|
||||
void TBLOB::Scale(float factor) {
|
||||
for (TESSLINE* outline = outlines; outline != nullptr; outline = outline->next) {
|
||||
for (TESSLINE* outline = outlines; outline != nullptr;
|
||||
outline = outline->next) {
|
||||
outline->Scale(factor);
|
||||
}
|
||||
}
|
||||
|
||||
// Recomputes the bounding boxes of the outlines.
|
||||
void TBLOB::ComputeBoundingBoxes() {
|
||||
for (TESSLINE* outline = outlines; outline != nullptr; outline = outline->next) {
|
||||
for (TESSLINE* outline = outlines; outline != nullptr;
|
||||
outline = outline->next) {
|
||||
outline->ComputeBoundingBox();
|
||||
}
|
||||
}
|
||||
@ -469,7 +463,8 @@ void TBLOB::ComputeBoundingBoxes() {
|
||||
// Returns the number of outlines.
|
||||
int TBLOB::NumOutlines() const {
|
||||
int result = 0;
|
||||
for (TESSLINE* outline = outlines; outline != nullptr; outline = outline->next)
|
||||
for (TESSLINE* outline = outlines; outline != nullptr;
|
||||
outline = outline->next)
|
||||
++result;
|
||||
return result;
|
||||
}
|
||||
@ -481,9 +476,8 @@ int TBLOB::NumOutlines() const {
|
||||
* bounding box of the union of all top-level outlines in the blob.
|
||||
**********************************************************************/
|
||||
TBOX TBLOB::bounding_box() const {
|
||||
if (outlines == nullptr)
|
||||
return TBOX(0, 0, 0, 0);
|
||||
TESSLINE *outline = outlines;
|
||||
if (outlines == nullptr) return TBOX(0, 0, 0, 0);
|
||||
TESSLINE* outline = outlines;
|
||||
TBOX box = outline->bounding_box();
|
||||
for (outline = outline->next; outline != nullptr; outline = outline->next) {
|
||||
box += outline->bounding_box();
|
||||
@ -494,7 +488,8 @@ TBOX TBLOB::bounding_box() const {
|
||||
// Finds and deletes any duplicate outlines in this blob, without deleting
|
||||
// their EDGEPTs.
|
||||
void TBLOB::EliminateDuplicateOutlines() {
|
||||
for (TESSLINE* outline = outlines; outline != nullptr; outline = outline->next) {
|
||||
for (TESSLINE* outline = outlines; outline != nullptr;
|
||||
outline = outline->next) {
|
||||
TESSLINE* last_outline = outline;
|
||||
for (TESSLINE* other_outline = outline->next; other_outline != nullptr;
|
||||
last_outline = other_outline, other_outline = other_outline->next) {
|
||||
@ -524,7 +519,8 @@ void TBLOB::CorrectBlobOrder(TBLOB* next) {
|
||||
#ifndef GRAPHICS_DISABLED
|
||||
void TBLOB::plot(ScrollView* window, ScrollView::Color color,
|
||||
ScrollView::Color child_color) {
|
||||
for (TESSLINE* outline = outlines; outline != nullptr; outline = outline->next)
|
||||
for (TESSLINE* outline = outlines; outline != nullptr;
|
||||
outline = outline->next)
|
||||
outline->plot(window, color, child_color);
|
||||
}
|
||||
#endif // GRAPHICS_DISABLED
|
||||
@ -576,10 +572,8 @@ void TBLOB::GetEdgeCoords(const TBOX& box,
|
||||
y_coords->init_to_size(box.width(), empty);
|
||||
CollectEdges(box, nullptr, nullptr, x_coords, y_coords);
|
||||
// Sort the output vectors.
|
||||
for (int i = 0; i < x_coords->size(); ++i)
|
||||
(*x_coords)[i].sort();
|
||||
for (int i = 0; i < y_coords->size(); ++i)
|
||||
(*y_coords)[i].sort();
|
||||
for (int i = 0; i < x_coords->size(); ++i) (*x_coords)[i].sort();
|
||||
for (int i = 0; i < y_coords->size(); ++i) (*y_coords)[i].sort();
|
||||
}
|
||||
|
||||
// Accumulates the segment between pt1 and pt2 in the LLSQ, quantizing over
|
||||
@ -611,13 +605,14 @@ static void SegmentLLSQ(const FCOORD& pt1, const FCOORD& pt2,
|
||||
// bottom-left of the bounding box, hence indices to x_coords, y_coords
|
||||
// are clipped to ([0,x_limit], [0,y_limit]).
|
||||
// See GetEdgeCoords above for a description of x_coords, y_coords.
|
||||
static void SegmentCoords(const FCOORD& pt1, const FCOORD& pt2,
|
||||
int x_limit, int y_limit,
|
||||
static void SegmentCoords(const FCOORD& pt1, const FCOORD& pt2, int x_limit,
|
||||
int y_limit,
|
||||
GenericVector<GenericVector<int> >* x_coords,
|
||||
GenericVector<GenericVector<int> >* y_coords) {
|
||||
FCOORD step(pt2);
|
||||
step -= pt1;
|
||||
int start = ClipToRange(IntCastRounded(std::min(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());
|
||||
@ -640,20 +635,20 @@ static void SegmentBBox(const FCOORD& pt1, const FCOORD& pt2, TBOX* bbox) {
|
||||
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());
|
||||
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, std::min(y1, y2), x2, std::max(y1, y2));
|
||||
*bbox += point;
|
||||
}
|
||||
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());
|
||||
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(std::min(x1, x2), y1, std::max(x1, x2), y2);
|
||||
*bbox += point;
|
||||
}
|
||||
@ -671,10 +666,9 @@ static void SegmentBBox(const FCOORD& pt1, const FCOORD& pt2, TBOX* bbox) {
|
||||
// indices into x_coords, y_coords are offset by box.botleft().
|
||||
static void CollectEdgesOfRun(const EDGEPT* startpt, const EDGEPT* lastpt,
|
||||
const DENORM& denorm, const TBOX& box,
|
||||
TBOX* bounding_box,
|
||||
LLSQ* accumulator,
|
||||
GenericVector<GenericVector<int> > *x_coords,
|
||||
GenericVector<GenericVector<int> > *y_coords) {
|
||||
TBOX* bounding_box, LLSQ* accumulator,
|
||||
GenericVector<GenericVector<int> >* x_coords,
|
||||
GenericVector<GenericVector<int> >* y_coords) {
|
||||
const C_OUTLINE* outline = startpt->src_outline;
|
||||
int x_limit = box.width() - 1;
|
||||
int y_limit = box.height() - 1;
|
||||
@ -693,8 +687,7 @@ static void CollectEdgesOfRun(const EDGEPT* startpt, const EDGEPT* lastpt,
|
||||
// bounds of the outline steps/ due to wrap-around, so we use % step_length
|
||||
// everywhere, except for start_index.
|
||||
int end_index = lastpt->start_step + lastpt->step_count;
|
||||
if (end_index <= start_index)
|
||||
end_index += step_length;
|
||||
if (end_index <= start_index) end_index += step_length;
|
||||
// pos is the integer coordinates of the binary image steps.
|
||||
ICOORD pos = outline->position_at_index(start_index);
|
||||
FCOORD origin(box.left(), box.bottom());
|
||||
@ -717,8 +710,8 @@ static void CollectEdgesOfRun(const EDGEPT* startpt, const EDGEPT* lastpt,
|
||||
// with a greyscale image, the positioning of the edge there may be a
|
||||
// fictitious extrapolation, so previous processing has eliminated it.
|
||||
if (outline->edge_strength_at_index(index % step_length) > 0) {
|
||||
FCOORD f_pos = outline->sub_pixel_pos_at_index(pos,
|
||||
index % step_length);
|
||||
FCOORD f_pos =
|
||||
outline->sub_pixel_pos_at_index(pos, index % step_length);
|
||||
FCOORD pos_normed;
|
||||
denorm.NormTransform(root_denorm, f_pos, &pos_normed);
|
||||
pos_normed -= origin;
|
||||
@ -730,8 +723,8 @@ static void CollectEdgesOfRun(const EDGEPT* startpt, const EDGEPT* lastpt,
|
||||
SegmentLLSQ(pos_normed, prev_normed, accumulator);
|
||||
}
|
||||
if (x_coords != nullptr && y_coords != nullptr) {
|
||||
SegmentCoords(pos_normed, prev_normed, x_limit, y_limit,
|
||||
x_coords, y_coords);
|
||||
SegmentCoords(pos_normed, prev_normed, x_limit, y_limit, x_coords,
|
||||
y_coords);
|
||||
}
|
||||
prev_normed = pos_normed;
|
||||
}
|
||||
@ -763,8 +756,7 @@ static void CollectEdgesOfRun(const EDGEPT* startpt, const EDGEPT* lastpt,
|
||||
// llsq and/or the x_coords/y_coords. Both are used in different kinds of
|
||||
// normalization.
|
||||
// For a description of x_coords, y_coords, see GetEdgeCoords above.
|
||||
void TBLOB::CollectEdges(const TBOX& box,
|
||||
TBOX* bounding_box, LLSQ* llsq,
|
||||
void TBLOB::CollectEdges(const TBOX& box, TBOX* bounding_box, LLSQ* llsq,
|
||||
GenericVector<GenericVector<int> >* x_coords,
|
||||
GenericVector<GenericVector<int> >* y_coords) const {
|
||||
// Iterate the outlines.
|
||||
@ -782,8 +774,8 @@ void TBLOB::CollectEdges(const TBOX& box,
|
||||
} while (last_pt != loop_pt && !last_pt->IsHidden() &&
|
||||
last_pt->src_outline == pt->src_outline);
|
||||
last_pt = last_pt->prev;
|
||||
CollectEdgesOfRun(pt, last_pt, denorm_, box,
|
||||
bounding_box, llsq, x_coords, y_coords);
|
||||
CollectEdgesOfRun(pt, last_pt, denorm_, box, bounding_box, llsq, x_coords,
|
||||
y_coords);
|
||||
pt = last_pt;
|
||||
} while ((pt = pt->next) != loop_pt);
|
||||
}
|
||||
@ -808,8 +800,7 @@ TWERD* TWERD::PolygonalCopy(bool allow_detailed_fx, WERD* src) {
|
||||
void TWERD::BLNormalize(const BLOCK* block, const ROW* row, Pix* pix,
|
||||
bool inverse, float x_height, float baseline_shift,
|
||||
bool numeric_mode, tesseract::OcrEngineMode hint,
|
||||
const TBOX* norm_box,
|
||||
DENORM* word_denorm) {
|
||||
const TBOX* norm_box, DENORM* word_denorm) {
|
||||
TBOX word_box = bounding_box();
|
||||
if (norm_box != nullptr) word_box = *norm_box;
|
||||
float word_middle = (word_box.left() + word_box.right()) / 2.0f;
|
||||
@ -847,8 +838,8 @@ void TWERD::BLNormalize(const BLOCK* block, const ROW* row, Pix* pix,
|
||||
}
|
||||
if (word_denorm != nullptr) {
|
||||
word_denorm->SetupNormalization(block, nullptr, nullptr, word_middle,
|
||||
input_y_offset, scale, scale,
|
||||
0.0f, final_y_offset);
|
||||
input_y_offset, scale, scale, 0.0f,
|
||||
final_y_offset);
|
||||
word_denorm->set_inverse(inverse);
|
||||
word_denorm->set_pix(pix);
|
||||
}
|
||||
@ -889,7 +880,7 @@ TBOX TWERD::bounding_box() const {
|
||||
// Merges the blobs from start to end, not including end, and deletes
|
||||
// the blobs between start and end.
|
||||
void TWERD::MergeBlobs(int start, int end) {
|
||||
if (start >= blobs.size() - 1) return; // Nothing to do.
|
||||
if (start >= blobs.size() - 1) return; // Nothing to do.
|
||||
TESSLINE* outline = blobs[start]->outlines;
|
||||
for (int i = start + 1; i < end && i < blobs.size(); ++i) {
|
||||
TBLOB* next_blob = blobs[i];
|
||||
@ -898,8 +889,7 @@ void TWERD::MergeBlobs(int start, int end) {
|
||||
blobs[start]->outlines = next_blob->outlines;
|
||||
outline = blobs[start]->outlines;
|
||||
} else {
|
||||
while (outline->next != nullptr)
|
||||
outline = outline->next;
|
||||
while (outline->next != nullptr) outline = outline->next;
|
||||
outline->next = next_blob->outlines;
|
||||
next_blob->outlines = nullptr;
|
||||
}
|
||||
@ -930,34 +920,34 @@ void TWERD::plot(ScrollView* window) {
|
||||
* separated using divide_blobs. Sets the location to be used in the
|
||||
* call to divide_blobs.
|
||||
**********************************************************************/
|
||||
bool divisible_blob(TBLOB *blob, bool italic_blob, TPOINT* location) {
|
||||
bool divisible_blob(TBLOB* blob, bool italic_blob, TPOINT* location) {
|
||||
if (blob->outlines == nullptr || blob->outlines->next == nullptr)
|
||||
return false; // Need at least 2 outlines for it to be possible.
|
||||
int max_gap = 0;
|
||||
TPOINT vertical = italic_blob ? kDivisibleVerticalItalic
|
||||
: kDivisibleVerticalUpright;
|
||||
TPOINT vertical =
|
||||
italic_blob ? kDivisibleVerticalItalic : kDivisibleVerticalUpright;
|
||||
for (TESSLINE* outline1 = blob->outlines; outline1 != nullptr;
|
||||
outline1 = outline1->next) {
|
||||
if (outline1->is_hole)
|
||||
continue; // Holes do not count as separable.
|
||||
if (outline1->is_hole) continue; // Holes do not count as separable.
|
||||
TPOINT mid_pt1(
|
||||
static_cast<int16_t>((outline1->topleft.x + outline1->botright.x) / 2),
|
||||
static_cast<int16_t>((outline1->topleft.y + outline1->botright.y) / 2));
|
||||
static_cast<int16_t>((outline1->topleft.x + outline1->botright.x) / 2),
|
||||
static_cast<int16_t>((outline1->topleft.y + outline1->botright.y) / 2));
|
||||
int mid_prod1 = CROSS(mid_pt1, vertical);
|
||||
int min_prod1, max_prod1;
|
||||
outline1->MinMaxCrossProduct(vertical, &min_prod1, &max_prod1);
|
||||
for (TESSLINE* outline2 = outline1->next; outline2 != nullptr;
|
||||
outline2 = outline2->next) {
|
||||
if (outline2->is_hole)
|
||||
continue; // Holes do not count as separable.
|
||||
TPOINT mid_pt2(
|
||||
static_cast<int16_t>((outline2->topleft.x + outline2->botright.x) / 2),
|
||||
static_cast<int16_t>((outline2->topleft.y + outline2->botright.y) / 2));
|
||||
if (outline2->is_hole) continue; // Holes do not count as separable.
|
||||
TPOINT mid_pt2(static_cast<int16_t>(
|
||||
(outline2->topleft.x + outline2->botright.x) / 2),
|
||||
static_cast<int16_t>(
|
||||
(outline2->topleft.y + outline2->botright.y) / 2));
|
||||
int mid_prod2 = CROSS(mid_pt2, vertical);
|
||||
int min_prod2, max_prod2;
|
||||
outline2->MinMaxCrossProduct(vertical, &min_prod2, &max_prod2);
|
||||
int mid_gap = abs(mid_prod2 - mid_prod1);
|
||||
int overlap = std::min(max_prod1, max_prod2) - std::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;
|
||||
@ -979,21 +969,21 @@ bool divisible_blob(TBLOB *blob, bool italic_blob, TPOINT* location) {
|
||||
* other blob. The ones whose x location is less than that point are
|
||||
* retained in the original blob.
|
||||
**********************************************************************/
|
||||
void divide_blobs(TBLOB *blob, TBLOB *other_blob, bool italic_blob,
|
||||
void divide_blobs(TBLOB* blob, TBLOB* other_blob, bool italic_blob,
|
||||
const TPOINT& location) {
|
||||
TPOINT vertical = italic_blob ? kDivisibleVerticalItalic
|
||||
: kDivisibleVerticalUpright;
|
||||
TESSLINE *outline1 = nullptr;
|
||||
TESSLINE *outline2 = nullptr;
|
||||
TPOINT vertical =
|
||||
italic_blob ? kDivisibleVerticalItalic : kDivisibleVerticalUpright;
|
||||
TESSLINE* outline1 = nullptr;
|
||||
TESSLINE* outline2 = nullptr;
|
||||
|
||||
TESSLINE *outline = blob->outlines;
|
||||
TESSLINE* outline = blob->outlines;
|
||||
blob->outlines = nullptr;
|
||||
int location_prod = CROSS(location, vertical);
|
||||
|
||||
while (outline != nullptr) {
|
||||
TPOINT mid_pt(
|
||||
static_cast<int16_t>((outline->topleft.x + outline->botright.x) / 2),
|
||||
static_cast<int16_t>((outline->topleft.y + outline->botright.y) / 2));
|
||||
static_cast<int16_t>((outline->topleft.x + outline->botright.x) / 2),
|
||||
static_cast<int16_t>((outline->topleft.y + outline->botright.y) / 2));
|
||||
int mid_prod = CROSS(mid_pt, vertical);
|
||||
if (mid_prod < location_prod) {
|
||||
// Outline is in left blob.
|
||||
@ -1013,8 +1003,6 @@ void divide_blobs(TBLOB *blob, TBLOB *other_blob, bool italic_blob,
|
||||
outline = outline->next;
|
||||
}
|
||||
|
||||
if (outline1)
|
||||
outline1->next = nullptr;
|
||||
if (outline2)
|
||||
outline2->next = nullptr;
|
||||
if (outline1) outline1->next = nullptr;
|
||||
if (outline2) outline2->next = nullptr;
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: crakedge.h (Formerly: crkedge.h)
|
||||
* File: crakedge.h (Formerly: crkedge.h)
|
||||
* Description: Structures for the Crack following edge detector.
|
||||
* Author: Ray Smith
|
||||
* Created: Fri Mar 22 16:06:38 GMT 1991
|
||||
* Author: Ray Smith
|
||||
* Created: Fri Mar 22 16:06:38 GMT 1991
|
||||
*
|
||||
* (C) Copyright 1991, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -17,11 +17,11 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef CRAKEDGE_H
|
||||
#define CRAKEDGE_H
|
||||
#ifndef CRAKEDGE_H
|
||||
#define CRAKEDGE_H
|
||||
|
||||
#include "points.h"
|
||||
#include "mod128.h"
|
||||
#include "points.h"
|
||||
#include "mod128.h"
|
||||
|
||||
class CRACKEDGE {
|
||||
public:
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "tprintf.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cfloat> // for FLT_MAX
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
@ -190,8 +191,7 @@ double DetLineFit::ConstrainedFit(double m, float* c) {
|
||||
double cos = 1.0 / sqrt(1.0 + m * m);
|
||||
FCOORD direction(cos, m * cos);
|
||||
ICOORD line_pt;
|
||||
double error = ConstrainedFit(direction, -MAX_FLOAT32, MAX_FLOAT32, false,
|
||||
&line_pt);
|
||||
double error = ConstrainedFit(direction, -FLT_MAX, FLT_MAX, false, &line_pt);
|
||||
*c = line_pt.y() - line_pt.x() * m;
|
||||
return error;
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef HPDSIZES_H
|
||||
#define HPDSIZES_H
|
||||
|
||||
#define NUM_TEXT_ATTR 10
|
||||
#define NUM_BLOCK_ATTR 7
|
||||
#define MAXLENGTH 128
|
||||
#define NUM_BACKGROUNDS 8
|
||||
#endif
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: linlsq.cpp (Formerly llsq.c)
|
||||
* Description: Linear Least squares fitting code.
|
||||
* Author: Ray Smith
|
||||
* Created: Thu Sep 12 08:44:51 BST 1991
|
||||
* Author: Ray Smith
|
||||
* Created: Thu Sep 12 08:44:51 BST 1991
|
||||
*
|
||||
* (C) Copyright 1991, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -17,10 +17,10 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "errcode.h"
|
||||
#include "linlsq.h"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "errcode.h"
|
||||
#include "linlsq.h"
|
||||
|
||||
const ERRCODE EMPTY_LLSQ = "Can't delete from an empty LLSQ";
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "normalis.h"
|
||||
|
||||
#include <cfloat> // for FLT_MAX
|
||||
#include <cstdlib>
|
||||
|
||||
#include "allheaders.h"
|
||||
@ -431,7 +432,7 @@ void DENORM::XHeightRange(int unichar_id, const UNICHARSET& unicharset,
|
||||
// Default return -- accept anything.
|
||||
*yshift = 0.0f;
|
||||
*min_xht = 0.0f;
|
||||
*max_xht = MAX_FLOAT32;
|
||||
*max_xht = FLT_MAX;
|
||||
|
||||
if (!unicharset.top_bottom_useful())
|
||||
return;
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: ocrblock.cpp (Formerly block.c)
|
||||
* Description: BLOCK member functions and iterator functions.
|
||||
* Author: Ray Smith
|
||||
* Created: Fri Mar 15 09:41:28 GMT 1991
|
||||
* Author: Ray Smith
|
||||
* Created: Fri Mar 15 09:41:28 GMT 1991
|
||||
*
|
||||
* (C) Copyright 1991, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -20,7 +20,6 @@
|
||||
#include "ocrblock.h"
|
||||
#include <cstdlib>
|
||||
#include <memory> // std::unique_ptr
|
||||
#include "blckerr.h"
|
||||
#include "stepblob.h"
|
||||
#include "tprintf.h"
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: ocrblock.h (Formerly block.h)
|
||||
* Description: Page block class definition.
|
||||
* Author: Ray Smith
|
||||
* Created: Thu Mar 14 17:32:01 GMT 1991
|
||||
* Author: Ray Smith
|
||||
* Created: Thu Mar 14 17:32:01 GMT 1991
|
||||
*
|
||||
* (C) Copyright 1991, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -17,12 +17,12 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef OCRBLOCK_H
|
||||
#define OCRBLOCK_H
|
||||
#ifndef OCRBLOCK_H
|
||||
#define OCRBLOCK_H
|
||||
|
||||
#include "ocrpara.h"
|
||||
#include "ocrrow.h"
|
||||
#include "pdblock.h"
|
||||
#include "ocrpara.h"
|
||||
#include "ocrrow.h"
|
||||
#include "pdblock.h"
|
||||
|
||||
class BLOCK; //forward decl
|
||||
|
||||
@ -208,7 +208,7 @@ class BLOCK:public ELIST_LINK
|
||||
FCOORD re_rotation_; //< How to transform coords back to image.
|
||||
FCOORD classify_rotation_; //< Apply this before classifying.
|
||||
FCOORD skew_; //< Direction of true horizontal.
|
||||
ICOORD median_size_; //< Median size of blobs.
|
||||
ICOORD median_size_; //< Median size of blobs.
|
||||
};
|
||||
|
||||
int decreasing_top_order(const void *row1, const void *row2);
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: ocrrow.cpp (Formerly row.c)
|
||||
* Description: Code for the ROW class.
|
||||
* Author: Ray Smith
|
||||
* Created: Tue Oct 08 15:58:04 BST 1991
|
||||
* Author: Ray Smith
|
||||
* Created: Tue Oct 08 15:58:04 BST 1991
|
||||
*
|
||||
* (C) Copyright 1991, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -17,8 +17,8 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#include "ocrrow.h"
|
||||
#include "blobbox.h"
|
||||
#include "ocrrow.h"
|
||||
#include "blobbox.h"
|
||||
|
||||
// Include automatically generated configuration file if running autoconf.
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
@ -58,7 +58,7 @@ int OtsuThreshold(Pix* src_pix, int left, int top, int width, int height,
|
||||
OpenclDevice od;
|
||||
if (od.selectedDeviceIsOpenCL() && (num_channels == 1 || num_channels == 4) &&
|
||||
top == 0 && left == 0) {
|
||||
od.HistogramRectOCL((unsigned char*)pixGetData(src_pix), num_channels,
|
||||
od.HistogramRectOCL(pixGetData(src_pix), num_channels,
|
||||
pixGetWpl(src_pix) * 4, left, top, width, height,
|
||||
kHistogramSize, histogramAllChannels);
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: pdblock.cpp (Formerly pdblk.c)
|
||||
* File: pdblock.cpp
|
||||
* Description: PDBLK member functions and iterator functions.
|
||||
* Author: Ray Smith
|
||||
* Created: Fri Mar 15 09:41:28 GMT 1991
|
||||
* Author: Ray Smith
|
||||
* Created: Fri Mar 15 09:41:28 GMT 1991
|
||||
*
|
||||
* (C) Copyright 1991, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -21,7 +21,6 @@
|
||||
#include <cstdlib>
|
||||
#include <memory> // std::unique_ptr
|
||||
#include "allheaders.h"
|
||||
#include "blckerr.h"
|
||||
|
||||
// Include automatically generated configuration file if running autoconf.
|
||||
#ifdef HAVE_CONFIG_H
|
||||
@ -30,6 +29,9 @@
|
||||
|
||||
#define BLOCK_LABEL_HEIGHT 150 //char height of block id
|
||||
|
||||
const ERRCODE BADBLOCKLINE = "Y coordinate in block out of bounds";
|
||||
const ERRCODE LOSTBLOCKLINE = "Can't find rectangle for line";
|
||||
|
||||
CLISTIZE (PDBLK)
|
||||
/**********************************************************************
|
||||
* PDBLK::PDBLK
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: points.cpp (Formerly coords.c)
|
||||
* Description: Member functions for coordinate classes.
|
||||
* Author: Ray Smith
|
||||
* Created: Fri Mar 15 08:58:17 GMT 1991
|
||||
* Author: Ray Smith
|
||||
* Created: Fri Mar 15 08:58:17 GMT 1991
|
||||
*
|
||||
* (C) Copyright 1991, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: polyaprx.h (Formerly polygon.h)
|
||||
* Description: Code for polygonal approximation from old edgeprog.
|
||||
* Author: Ray Smith
|
||||
* Created: Thu Nov 25 11:42:04 GMT 1993
|
||||
* Author: Ray Smith
|
||||
* Created: Thu Nov 25 11:42:04 GMT 1993
|
||||
*
|
||||
* (C) Copyright 1993, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -17,11 +17,11 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef POLYAPRX_H
|
||||
#define POLYAPRX_H
|
||||
#ifndef POLYAPRX_H
|
||||
#define POLYAPRX_H
|
||||
|
||||
#include "blobs.h"
|
||||
#include "coutln.h"
|
||||
#include "blobs.h"
|
||||
#include "coutln.h"
|
||||
|
||||
// convert a chain-coded input to the old OUTLINE approximation
|
||||
TESSLINE* ApproximateOutline(bool allow_detailed_fx, C_OUTLINE *c_outline);
|
||||
|
@ -1,8 +1,6 @@
|
||||
/**********************************************************************
|
||||
* File: polyblk.h (Formerly poly_block.h)
|
||||
* Description: Polygonal blocks
|
||||
* Author: Sheelagh Lloyd?
|
||||
* Created:
|
||||
*
|
||||
* (C) Copyright 1993, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -16,8 +14,9 @@
|
||||
** limitations under the License.
|
||||
*
|
||||
**********************************************************************/
|
||||
#ifndef POLYBLK_H
|
||||
#define POLYBLK_H
|
||||
|
||||
#ifndef POLYBLK_H
|
||||
#define POLYBLK_H
|
||||
|
||||
#include "publictypes.h"
|
||||
#include "elst.h"
|
||||
|
@ -278,7 +278,7 @@ enum OcrEngineMode {
|
||||
// command-line configs, or if not specified
|
||||
// in any of the above should be set to the
|
||||
// default OEM_TESSERACT_ONLY.
|
||||
OEM_COUNT // Number of OEMs
|
||||
OEM_COUNT // Number of OEMs
|
||||
};
|
||||
|
||||
} // namespace tesseract.
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: quadlsq.cpp (Formerly qlsq.c)
|
||||
* Description: Code for least squares approximation of quadratics.
|
||||
* Author: Ray Smith
|
||||
* Created: Wed Oct 6 15:14:23 BST 1993
|
||||
* Author: Ray Smith
|
||||
* Created: Wed Oct 6 15:14:23 BST 1993
|
||||
*
|
||||
* (C) Copyright 1993, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: quadlsq.h (Formerly qlsq.h)
|
||||
* Description: Code for least squares approximation of quadratics.
|
||||
* Author: Ray Smith
|
||||
* Created: Wed Oct 6 15:14:23 BST 1993
|
||||
* Author: Ray Smith
|
||||
* Created: Wed Oct 6 15:14:23 BST 1993
|
||||
*
|
||||
* (C) Copyright 1993, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -17,10 +17,10 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef QUADLSQ_H
|
||||
#define QUADLSQ_H
|
||||
#ifndef QUADLSQ_H
|
||||
#define QUADLSQ_H
|
||||
|
||||
#include "points.h"
|
||||
#include "points.h"
|
||||
|
||||
class QLSQ
|
||||
{
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: quadratc.h (Formerly quadrtic.h)
|
||||
* Description: Code for the QUAD_COEFFS class.
|
||||
* Author: Ray Smith
|
||||
* Created: Tue Oct 08 17:24:40 BST 1991
|
||||
* Author: Ray Smith
|
||||
* Created: Tue Oct 08 17:24:40 BST 1991
|
||||
*
|
||||
* (C) Copyright 1991, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -17,10 +17,10 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef QUADRATC_H
|
||||
#define QUADRATC_H
|
||||
#ifndef QUADRATC_H
|
||||
#define QUADRATC_H
|
||||
|
||||
#include "points.h"
|
||||
#include "points.h"
|
||||
|
||||
class QUAD_COEFFS
|
||||
{
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define RATNGS_H
|
||||
|
||||
#include <cassert>
|
||||
#include <cfloat> // for FLT_MAX
|
||||
|
||||
#include "clst.h"
|
||||
#include "elst.h"
|
||||
@ -418,9 +419,9 @@ class WERD_CHOICE : public ELIST_LINK {
|
||||
length_ = 0;
|
||||
adjust_factor_ = 1.0f;
|
||||
rating_ = 0.0;
|
||||
certainty_ = MAX_FLOAT32;
|
||||
certainty_ = FLT_MAX;
|
||||
min_x_height_ = 0.0f;
|
||||
max_x_height_ = MAX_FLOAT32;
|
||||
max_x_height_ = FLT_MAX;
|
||||
permuter_ = NO_PERM;
|
||||
unichars_in_script_order_ = false; // Tesseract is strict left-to-right.
|
||||
dangerous_ambig_found_ = false;
|
||||
@ -439,7 +440,7 @@ class WERD_CHOICE : public ELIST_LINK {
|
||||
inline void make_bad() {
|
||||
length_ = 0;
|
||||
rating_ = kBadRating;
|
||||
certainty_ = -MAX_FLOAT32;
|
||||
certainty_ = -FLT_MAX;
|
||||
}
|
||||
|
||||
/// This function assumes that there is enough space reserved
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: rejctmap.cpp (Formerly rejmap.c)
|
||||
* Description: REJ and REJMAP class functions.
|
||||
* Author: Phil Cheatle
|
||||
* Created: Thu Jun 9 13:46:38 BST 1994
|
||||
* Author: Phil Cheatle
|
||||
* Created: Thu Jun 9 13:46:38 BST 1994
|
||||
*
|
||||
* (C) Copyright 1994, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -17,9 +17,9 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#include "host.h"
|
||||
#include "rejctmap.h"
|
||||
#include "params.h"
|
||||
#include "host.h"
|
||||
#include "rejctmap.h"
|
||||
#include "params.h"
|
||||
|
||||
bool REJ::perm_rejected() { //Is char perm reject?
|
||||
return (flag (R_TESS_FAILURE) ||
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: statistc.h (Formerly stats.h)
|
||||
* Description: Class description for STATS class.
|
||||
* Author: Ray Smith
|
||||
* Created: Mon Feb 04 16:19:07 GMT 1991
|
||||
* Author: Ray Smith
|
||||
* Created: Mon Feb 04 16:19:07 GMT 1991
|
||||
*
|
||||
* (C) Copyright 1991, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: stepblob.cpp (Formerly cblob.c)
|
||||
* Description: Code for C_BLOB class.
|
||||
* Author: Ray Smith
|
||||
* Created: Tue Oct 08 10:41:13 BST 1991
|
||||
* Author: Ray Smith
|
||||
* Created: Tue Oct 08 10:41:13 BST 1991
|
||||
*
|
||||
* (C) Copyright 1991, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: stepblob.h (Formerly cblob.h)
|
||||
* Description: Code for C_BLOB class.
|
||||
* Author: Ray Smith
|
||||
* Created: Tue Oct 08 10:41:13 BST 1991
|
||||
* Author: Ray Smith
|
||||
* Created: Tue Oct 08 10:41:13 BST 1991
|
||||
*
|
||||
* (C) Copyright 1991, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -17,11 +17,11 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef STEPBLOB_H
|
||||
#define STEPBLOB_H
|
||||
#ifndef STEPBLOB_H
|
||||
#define STEPBLOB_H
|
||||
|
||||
#include "coutln.h"
|
||||
#include "rect.h"
|
||||
#include "coutln.h"
|
||||
#include "rect.h"
|
||||
|
||||
class C_BLOB;
|
||||
struct Pix;
|
||||
|
@ -41,7 +41,7 @@ struct EDGEPT;
|
||||
|
||||
#define point_diff(p,p1,p2) \
|
||||
((p).x = (p1).x - (p2).x, \
|
||||
(p).y = (p1).y - (p2).y)
|
||||
(p).y = (p1).y - (p2).y)
|
||||
|
||||
/**********************************************************************
|
||||
* CROSS
|
||||
|
@ -17,7 +17,6 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#include "blckerr.h"
|
||||
#include "helpers.h"
|
||||
#include "linlsq.h"
|
||||
#include "werd.h"
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: word.h
|
||||
* File: werd.h
|
||||
* Description: Code for the WERD class.
|
||||
* Author: Ray Smith
|
||||
* Created: Tue Oct 08 14:32:12 BST 1991
|
||||
* Author: Ray Smith
|
||||
* Created: Tue Oct 08 14:32:12 BST 1991
|
||||
*
|
||||
* (C) Copyright 1991, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -17,15 +17,14 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef WERD_H
|
||||
#define WERD_H
|
||||
#ifndef WERD_H
|
||||
#define WERD_H
|
||||
|
||||
#include "params.h"
|
||||
#include "bits16.h"
|
||||
#include "elst2.h"
|
||||
#include "strngs.h"
|
||||
#include "blckerr.h"
|
||||
#include "stepblob.h"
|
||||
#include "params.h"
|
||||
#include "bits16.h"
|
||||
#include "elst2.h"
|
||||
#include "strngs.h"
|
||||
#include "stepblob.h"
|
||||
|
||||
enum WERD_FLAGS
|
||||
{
|
||||
|
@ -20,7 +20,7 @@ noinst_HEADERS = \
|
||||
ambigs.h basedir.h bits16.h bitvector.h ccutil.h clst.h doubleptr.h elst2.h \
|
||||
elst.h errcode.h fileerr.h genericheap.h globaloc.h \
|
||||
indexmapbidi.h kdpair.h lsterr.h \
|
||||
nwmain.h object_cache.h params.h qrsequence.h sorthelper.h \
|
||||
object_cache.h params.h qrsequence.h sorthelper.h \
|
||||
scanutils.h tessdatamanager.h tprintf.h \
|
||||
unicharcompress.h unicharmap.h unicharset.h unicity_table.h unicodes.h \
|
||||
universalambigs.h
|
||||
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: bits16.h (Formerly bits8.h)
|
||||
* Description: Code for 8 bit field class.
|
||||
* Author: Phil Cheatle
|
||||
* Created: Thu Oct 17 10:10:05 BST 1991
|
||||
* Author: Phil Cheatle
|
||||
* Created: Thu Oct 17 10:10:05 BST 1991
|
||||
*
|
||||
* (C) Copyright 1991, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -17,8 +17,8 @@
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef BITS16_H
|
||||
#define BITS16_H
|
||||
#ifndef BITS16_H
|
||||
#define BITS16_H
|
||||
|
||||
#include "host.h"
|
||||
|
||||
|
@ -31,8 +31,6 @@
|
||||
#include <cstdint> // int32_t, ...
|
||||
|
||||
// definitions of portable data types (numbers and characters)
|
||||
using FLOAT32 = float;
|
||||
using FLOAT64 = double;
|
||||
using BOOL8 = unsigned char;
|
||||
|
||||
#if defined(_WIN32)
|
||||
@ -49,11 +47,6 @@ using BOOL8 = unsigned char;
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#define MAX_FLOAT32 std::numeric_limits<float>::max()
|
||||
|
||||
// Minimum positive value ie 1e-37ish.
|
||||
#define MIN_FLOAT32 std::numeric_limits<float>::min()
|
||||
|
||||
// Defines
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
|
@ -1,175 +0,0 @@
|
||||
/**********************************************************************
|
||||
* File: nwmain.h
|
||||
* Description: Tool to declare main, making windows invisible.
|
||||
* Author: Ray Smith
|
||||
* Created: Fri Sep 07 13:27:50 MDT 1995
|
||||
*
|
||||
* (C) Copyright 1995, Hewlett-Packard Co.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
** http://www.apache.org/licenses/LICENSE-2.0
|
||||
** Unless required by applicable law or agreed to in writing, software
|
||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef RUNMAIN_H
|
||||
#define RUNMAIN_H
|
||||
|
||||
#include "host.h"
|
||||
#include "params.h"
|
||||
|
||||
#define DECLARE_MAIN(ARGC,ARGV)\
|
||||
STRING_VAR(init_config_file,"config","Config file to read on startup");\
|
||||
REALLY_DECLARE_MAIN(ARGC,ARGV)
|
||||
|
||||
#define DECLARE_MAIN_CONFIG(ARGC,ARGV,NAME)\
|
||||
STRING_VAR(init_config_file,NAME,"Config file to read on startup");\
|
||||
REALLY_DECLARE_MAIN(ARGC,ARGV)
|
||||
|
||||
#ifndef __UNIX__
|
||||
|
||||
#define REALLY_DECLARE_MAIN(ARGC,ARGV)\
|
||||
\
|
||||
/**********************************************************************\
|
||||
* parse_args\
|
||||
*\
|
||||
* Turn a list of args into a new list of args with each separate\
|
||||
* whitespace spaced string being an arg.\
|
||||
**********************************************************************/\
|
||||
\
|
||||
int32_t parse_args( /*refine arg list*/\
|
||||
int32_t argc, /*no of input args*/\
|
||||
char *argv[], /*input args*/\
|
||||
char *arglist[] /*output args*/\
|
||||
)\
|
||||
{\
|
||||
int32_t argcount; /*converted argc*/\
|
||||
char *testchar; /*char in option string*/\
|
||||
int32_t arg; /*current argument*/\
|
||||
\
|
||||
argcount=0; /*no of options*/\
|
||||
for (arg=0;arg<argc;arg++)\
|
||||
{\
|
||||
testchar=argv[arg]; /*start of arg*/\
|
||||
do\
|
||||
{\
|
||||
while (*testchar\
|
||||
&& (*testchar==' ' || *testchar=='"' || *testchar=='\n' || *testchar=='\t'))\
|
||||
testchar++; /*skip white space*/\
|
||||
if (*testchar)\
|
||||
{\
|
||||
arglist[argcount++]=testchar; /*new arg*/\
|
||||
do\
|
||||
{\
|
||||
for (testchar++;*testchar\
|
||||
&& *testchar!=' ' && *testchar!='"' && *testchar!='\n' && *testchar!='\t';\
|
||||
testchar++); /*skip to white space*/\
|
||||
}\
|
||||
while (*testchar=='"' && testchar[1]!=' ' && testchar[1]!='\0' && testchar[1]!='\n' && testchar[1]!='\t');\
|
||||
if (*testchar)\
|
||||
*testchar++='\0'; /*turn to separate args*/\
|
||||
}\
|
||||
}\
|
||||
while (*testchar);\
|
||||
}\
|
||||
return argcount; /*new number of args*/\
|
||||
}\
|
||||
\
|
||||
int32_t global_exit_code;\
|
||||
int32_t real_main(int32_t,const char**);\
|
||||
\
|
||||
int32_t run_main( /*the main thread*/\
|
||||
CWinApp* theapp /*arguments*/\
|
||||
)\
|
||||
{\
|
||||
char **argv;\
|
||||
char *argsin[2];\
|
||||
int32_t argc;\
|
||||
int32_t exit_code;\
|
||||
\
|
||||
argsin[0]=strdup(theapp->m_pszExeName);\
|
||||
argsin[1]=strdup(theapp->m_lpCmdLine);\
|
||||
/*allocate memory for the args. There can never be more than half*/\
|
||||
/*the total number of characters in the arguments.*/\
|
||||
argv=(char**)malloc(((strlen(argsin[0])+strlen(argsin[1]))/2+1)*sizeof(char*));\
|
||||
\
|
||||
/*now construct argv as it should be for C.*/\
|
||||
argc=parse_args(2,argsin,argv);\
|
||||
\
|
||||
/*call main(argc,argv) here*/\
|
||||
exit_code=real_main(argc,(const char **)argv);\
|
||||
\
|
||||
\
|
||||
/*now get rid of the main app window*/\
|
||||
if (theapp!=nullptr && theapp->m_pMainWnd!=nullptr)\
|
||||
PostMessage(theapp->m_pMainWnd->m_hWnd,WM_QUIT,0,0);\
|
||||
free(argsin[0]);\
|
||||
free(argsin[1]);\
|
||||
free(argv);\
|
||||
global_exit_code=exit_code;\
|
||||
return exit_code;\
|
||||
}\
|
||||
\
|
||||
int32_t real_main(int32_t ARGC,const char* ARGV[])\
|
||||
|
||||
#else
|
||||
|
||||
#define REALLY_DECLARE_MAIN(ARGC,ARGV)\
|
||||
\
|
||||
/**********************************************************************\
|
||||
* parse_args\
|
||||
*\
|
||||
* Turn a list of args into a new list of args with each separate\
|
||||
* whitespace spaced string being an arg.\
|
||||
**********************************************************************/\
|
||||
\
|
||||
int32_t parse_args( /*refine arg list*/\
|
||||
int32_t argc, /*no of input args*/\
|
||||
char *argv[], /*input args*/\
|
||||
char *arglist[] /*output args*/\
|
||||
)\
|
||||
{\
|
||||
int32_t argcount; /*converted argc*/\
|
||||
char *testchar; /*char in option string*/\
|
||||
int32_t arg; /*current argument*/\
|
||||
\
|
||||
argcount=0; /*no of options*/\
|
||||
for (arg=0;arg<argc;arg++)\
|
||||
{\
|
||||
testchar=argv[arg]; /*start of arg*/\
|
||||
do\
|
||||
{\
|
||||
while (*testchar\
|
||||
&& (*testchar==' ' || *testchar=='"' || *testchar=='\n' || *testchar=='\t'))\
|
||||
testchar++; /*skip white space*/\
|
||||
if (*testchar)\
|
||||
{\
|
||||
arglist[argcount++]=testchar; /*new arg*/\
|
||||
do\
|
||||
{\
|
||||
for (testchar++;*testchar\
|
||||
&& *testchar!=' ' && *testchar!='"' && *testchar!='\n' && *testchar!='\t';\
|
||||
testchar++); /*skip to white space*/\
|
||||
}\
|
||||
while (*testchar=='"' && testchar[1]!=' ' && testchar[1]!='\0' && testchar[1]!='\n' && testchar[1]!='\t');\
|
||||
if (*testchar)\
|
||||
*testchar++='\0'; /*turn to separate args*/\
|
||||
}\
|
||||
}\
|
||||
while (*testchar);\
|
||||
}\
|
||||
return argcount; /*new number of args*/\
|
||||
}\
|
||||
\
|
||||
int32_t main(int32_t ARGC,const char* ARGV[])\
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error "NOT allowed to include nwmain.h or runmain.h twice!!"
|
||||
#endif
|
@ -1,8 +1,8 @@
|
||||
/**********************************************************************
|
||||
* File: strngs.h (Formerly strings.h)
|
||||
* Description: STRING class definition.
|
||||
* Author: Ray Smith
|
||||
* Created: Fri Feb 15 09:15:01 GMT 1991
|
||||
* Author: Ray Smith
|
||||
* Created: Fri Feb 15 09:15:01 GMT 1991
|
||||
*
|
||||
* (C) Copyright 1991, Hewlett-Packard Ltd.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -44,8 +44,6 @@ using tesseract::TFile;
|
||||
* @param ClassId class id to associate with new class
|
||||
*
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Mar 14 13:06:09 1991, DSJ, Created.
|
||||
*/
|
||||
void AddAdaptedClass(ADAPT_TEMPLATES Templates,
|
||||
ADAPT_CLASS Class,
|
||||
@ -75,8 +73,6 @@ void AddAdaptedClass(ADAPT_TEMPLATES Templates,
|
||||
* @param Config config to be freed
|
||||
*
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Mar 14 13:34:23 1991, DSJ, Created.
|
||||
*/
|
||||
void FreeTempConfig(TEMP_CONFIG Config) {
|
||||
assert (Config != nullptr);
|
||||
@ -105,8 +101,6 @@ void FreePermConfig(PERM_CONFIG Config) {
|
||||
* @return Ptr to new class data structure.
|
||||
*
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Mar 14 12:58:13 1991, DSJ, Created.
|
||||
*/
|
||||
ADAPT_CLASS NewAdaptedClass() {
|
||||
ADAPT_CLASS Class;
|
||||
@ -156,8 +150,6 @@ namespace tesseract {
|
||||
* @return Ptr to new adapted templates.
|
||||
*
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Fri Mar 8 10:15:28 1991, DSJ, Created.
|
||||
*/
|
||||
ADAPT_TEMPLATES Classify::NewAdaptedTemplates(bool InitFromUnicharset) {
|
||||
ADAPT_TEMPLATES Templates;
|
||||
@ -210,8 +202,6 @@ void free_adapted_templates(ADAPT_TEMPLATES templates) {
|
||||
* @return Ptr to new temp config.
|
||||
*
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Mar 14 13:28:21 1991, DSJ, Created.
|
||||
*/
|
||||
TEMP_CONFIG NewTempConfig(int MaxProtoId, int FontinfoId) {
|
||||
int NumProtos = MaxProtoId + 1;
|
||||
@ -237,8 +227,6 @@ TEMP_CONFIG NewTempConfig(int MaxProtoId, int FontinfoId) {
|
||||
* @return Ptr to new temporary proto.
|
||||
*
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Mar 14 13:31:31 1991, DSJ, Created.
|
||||
*/
|
||||
TEMP_PROTO NewTempProto() {
|
||||
return (TEMP_PROTO)malloc(sizeof(TEMP_PROTO_STRUCT));
|
||||
@ -255,8 +243,6 @@ namespace tesseract {
|
||||
* @param Templates adapted templates to print to File
|
||||
*
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed Mar 20 13:35:29 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::PrintAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates) {
|
||||
INT_CLASS IClass;
|
||||
@ -294,8 +280,6 @@ void Classify::PrintAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates) {
|
||||
* @return Ptr to new adapted class.
|
||||
*
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Mar 19 14:11:01 1991, DSJ, Created.
|
||||
*/
|
||||
ADAPT_CLASS ReadAdaptedClass(TFile *fp) {
|
||||
int NumTempProtos;
|
||||
@ -347,8 +331,6 @@ namespace tesseract {
|
||||
* @return Ptr to adapted templates read from file.
|
||||
*
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Mon Mar 18 15:18:10 1991, DSJ, Created.
|
||||
*/
|
||||
ADAPT_TEMPLATES Classify::ReadAdaptedTemplates(TFile *fp) {
|
||||
ADAPT_TEMPLATES Templates;
|
||||
@ -379,8 +361,6 @@ ADAPT_TEMPLATES Classify::ReadAdaptedTemplates(TFile *fp) {
|
||||
* @return Ptr to new permanent configuration description.
|
||||
*
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Mar 19 14:25:26 1991, DSJ, Created.
|
||||
*/
|
||||
PERM_CONFIG ReadPermConfig(TFile *fp) {
|
||||
PERM_CONFIG Config = (PERM_CONFIG)malloc(sizeof(PERM_CONFIG_STRUCT));
|
||||
@ -405,8 +385,6 @@ PERM_CONFIG ReadPermConfig(TFile *fp) {
|
||||
* @return Ptr to new temporary configuration description.
|
||||
*
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Mar 19 14:29:59 1991, DSJ, Created.
|
||||
*/
|
||||
TEMP_CONFIG ReadTempConfig(TFile *fp) {
|
||||
TEMP_CONFIG Config = (TEMP_CONFIG)malloc(sizeof(TEMP_CONFIG_STRUCT));
|
||||
@ -430,8 +408,6 @@ TEMP_CONFIG ReadTempConfig(TFile *fp) {
|
||||
* @param NumConfigs number of configs in Class
|
||||
*
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Mar 19 13:33:51 1991, DSJ, Created.
|
||||
*/
|
||||
void WriteAdaptedClass(FILE *File, ADAPT_CLASS Class, int NumConfigs) {
|
||||
int NumTempProtos;
|
||||
@ -476,8 +452,6 @@ namespace tesseract {
|
||||
* @param Templates set of adapted templates to write to File
|
||||
*
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Mon Mar 18 15:07:32 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::WriteAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates) {
|
||||
int i;
|
||||
@ -506,8 +480,6 @@ void Classify::WriteAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates) {
|
||||
* @param Config permanent config to write to File
|
||||
*
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Mar 19 13:55:44 1991, DSJ, Created.
|
||||
*/
|
||||
void WritePermConfig(FILE *File, PERM_CONFIG Config) {
|
||||
uint8_t NumAmbigs = 0;
|
||||
@ -530,8 +502,6 @@ void WritePermConfig(FILE *File, PERM_CONFIG Config) {
|
||||
* @param Config temporary config to write to File
|
||||
*
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Mar 19 14:00:28 1991, DSJ, Created.
|
||||
*/
|
||||
void WriteTempConfig(FILE *File, TEMP_CONFIG Config) {
|
||||
assert (Config != nullptr);
|
||||
|
@ -1,10 +1,10 @@
|
||||
/******************************************************************************
|
||||
** Filename: adaptive.h
|
||||
** Purpose: Interface to adaptive matcher.
|
||||
** Author: Dan Johnson
|
||||
** History: Fri Mar 8 10:00:49 1991, DSJ, Created.
|
||||
** Filename: adaptive.h
|
||||
** Purpose: Interface to adaptive matcher.
|
||||
** Author: Dan Johnson
|
||||
** History: Fri Mar 8 10:00:49 1991, DSJ, Created.
|
||||
**
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
@ -89,22 +89,22 @@ typedef ADAPT_TEMPLATES_STRUCT *ADAPT_TEMPLATES;
|
||||
#define IsEmptyAdaptedClass(Class) ((Class)->NumPermConfigs == 0 && \
|
||||
(Class)->TempProtos == NIL_LIST)
|
||||
|
||||
#define ConfigIsPermanent(Class,ConfigId) \
|
||||
#define ConfigIsPermanent(Class,ConfigId) \
|
||||
(test_bit ((Class)->PermConfigs, ConfigId))
|
||||
|
||||
#define MakeConfigPermanent(Class,ConfigId) \
|
||||
#define MakeConfigPermanent(Class,ConfigId) \
|
||||
(SET_BIT ((Class)->PermConfigs, ConfigId))
|
||||
|
||||
#define MakeProtoPermanent(Class,ProtoId) \
|
||||
#define MakeProtoPermanent(Class,ProtoId) \
|
||||
(SET_BIT ((Class)->PermProtos, ProtoId))
|
||||
|
||||
#define TempConfigFor(Class,ConfigId) \
|
||||
#define TempConfigFor(Class,ConfigId) \
|
||||
((Class)->Config[ConfigId].Temp)
|
||||
|
||||
#define PermConfigFor(Class,ConfigId) \
|
||||
#define PermConfigFor(Class,ConfigId) \
|
||||
((Class)->Config[ConfigId].Perm)
|
||||
|
||||
#define IncreaseConfidence(TempConfig) \
|
||||
#define IncreaseConfidence(TempConfig) \
|
||||
((TempConfig)->NumTimesSeen++)
|
||||
|
||||
void AddAdaptedClass(ADAPT_TEMPLATES Templates,
|
||||
|
@ -2,7 +2,6 @@
|
||||
** Filename: adaptmatch.cpp
|
||||
** Purpose: High level adaptive matcher.
|
||||
** Author: Dan Johnson
|
||||
** History: Mon Mar 11 10:00:10 1991, DSJ, Created.
|
||||
**
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -43,7 +42,7 @@
|
||||
#include "fontinfo.h" // for ScoredFont, FontSet
|
||||
#include "genericvector.h" // for GenericVector
|
||||
#include "helpers.h" // for IntCastRounded, ClipToRange
|
||||
#include "host.h" // for FLOAT32, FALSE, MAX_FLOAT32, TRUE
|
||||
#include "host.h" // for FALSE, TRUE
|
||||
#include "intfx.h" // for BlobToTrainingSample, INT_FX_RESULT_S...
|
||||
#include "intmatcher.h" // for CP_RESULT_STRUCT, IntegerMatcher
|
||||
#include "intproto.h" // for INT_FEATURE_STRUCT, (anonymous), Clas...
|
||||
@ -95,7 +94,7 @@ struct ADAPT_RESULTS {
|
||||
bool HasNonfragment;
|
||||
UNICHAR_ID best_unichar_id;
|
||||
int best_match_index;
|
||||
FLOAT32 best_rating;
|
||||
float best_rating;
|
||||
GenericVector<UnicharRating> match;
|
||||
GenericVector<CP_RESULT_STRUCT> CPResults;
|
||||
|
||||
@ -155,11 +154,11 @@ static float ScoredUnichar(UNICHAR_ID id, const ADAPT_RESULTS& results) {
|
||||
return results.match[index].rating;
|
||||
}
|
||||
|
||||
void InitMatcherRatings(FLOAT32 *Rating);
|
||||
void InitMatcherRatings(float *Rating);
|
||||
|
||||
int MakeTempProtoPerm(void *item1, void *item2);
|
||||
|
||||
void SetAdaptiveThreshold(FLOAT32 Threshold);
|
||||
void SetAdaptiveThreshold(float Threshold);
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
@ -183,9 +182,6 @@ namespace tesseract {
|
||||
* This routine also performs some simple speckle
|
||||
* filtering.
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Mon Mar 11 10:00:58 1991, DSJ, Created.
|
||||
*
|
||||
* @param Blob blob to be classified
|
||||
* @param[out] Choices List of choices found by adaptive matcher.
|
||||
* filled on return with the choices found by the
|
||||
@ -460,9 +456,6 @@ void Classify::LearnPieces(const char* fontname, int start, int length,
|
||||
* - #AdaptedTemplates current set of adapted templates
|
||||
* - #classify_save_adapted_templates TRUE if templates should be saved
|
||||
* - #classify_enable_adaptive_matcher TRUE if adaptive matcher is enabled
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Mar 19 14:37:06 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::EndAdaptiveClassifier() {
|
||||
STRING Filename;
|
||||
@ -531,7 +524,6 @@ void Classify::EndAdaptiveClassifier() {
|
||||
* BuiltInCutoffsFile file to get avg. feat per class from
|
||||
* classify_use_pre_adapted_templates
|
||||
* enables use of pre-adapted templates
|
||||
* @note History: Mon Mar 11 12:49:34 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::InitAdaptiveClassifier(TessdataManager* mgr) {
|
||||
if (!classify_enable_adaptive_matcher)
|
||||
@ -658,9 +650,6 @@ void Classify::StartBackupAdaptiveClassifier() {
|
||||
* Globals:
|
||||
* - #EnableLearning
|
||||
* set to TRUE by this routine
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Mon Apr 15 16:39:29 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::SettupPass1() {
|
||||
EnableLearning = classify_enable_learning;
|
||||
@ -678,9 +667,6 @@ void Classify::SettupPass1() {
|
||||
*
|
||||
* Globals:
|
||||
* - #EnableLearning set to FALSE by this routine
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Mon Apr 15 16:39:29 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::SettupPass2() {
|
||||
EnableLearning = FALSE;
|
||||
@ -705,9 +691,6 @@ void Classify::SettupPass2() {
|
||||
* - #AllProtosOn dummy mask with all 1's
|
||||
* - BaselineCutoffs kludge needed to get cutoffs
|
||||
* - #PreTrainedTemplates kludge needed to get cutoffs
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Mar 14 12:49:39 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::InitAdaptedClass(TBLOB *Blob,
|
||||
CLASS_ID ClassId,
|
||||
@ -801,8 +784,6 @@ void Classify::InitAdaptedClass(TBLOB *Blob,
|
||||
*
|
||||
* @return Number of pico-features returned (0 if
|
||||
* an error occurred)
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Mar 12 17:55:18 1991, DSJ, Created.
|
||||
*/
|
||||
int Classify::GetAdaptiveFeatures(TBLOB *Blob,
|
||||
INT_FEATURE_ARRAY IntFeatures,
|
||||
@ -838,9 +819,7 @@ int Classify::GetAdaptiveFeatures(TBLOB *Blob,
|
||||
*
|
||||
* @param word current word
|
||||
*
|
||||
* @return TRUE or FALSE
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu May 30 14:25:06 1991, DSJ, Created.
|
||||
* @return true or false
|
||||
*/
|
||||
bool Classify::AdaptableWord(WERD_RES* word) {
|
||||
if (word->best_choice == nullptr) return false;
|
||||
@ -875,11 +854,9 @@ bool Classify::AdaptableWord(WERD_RES* word) {
|
||||
* - AllConfigsOn dummy mask to match against all configs
|
||||
*
|
||||
* @return none
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Mar 14 09:36:03 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::AdaptToChar(TBLOB* Blob, CLASS_ID ClassId, int FontinfoId,
|
||||
FLOAT32 Threshold,
|
||||
float Threshold,
|
||||
ADAPT_TEMPLATES adaptive_templates) {
|
||||
int NumFeatures;
|
||||
INT_FEATURE_ARRAY IntFeatures;
|
||||
@ -1018,9 +995,6 @@ void Classify::DisplayAdaptedChar(TBLOB* blob, INT_CLASS_STRUCT* int_class) {
|
||||
*
|
||||
* @param new_result new result to add
|
||||
* @param[out] results results to add new result to
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Mar 12 18:19:29 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::AddNewResult(const UnicharRating& new_result,
|
||||
ADAPT_RESULTS *results) {
|
||||
@ -1072,9 +1046,6 @@ void Classify::AddNewResult(const UnicharRating& new_result,
|
||||
* @param[out] results place to put match results
|
||||
* @param int_features
|
||||
* @param fx_info
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Mar 12 19:40:36 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::AmbigClassifier(
|
||||
const GenericVector<INT_FEATURE_STRUCT>& int_features,
|
||||
@ -1295,8 +1266,6 @@ double Classify::ComputeCorrectedRating(bool debug, int unichar_id,
|
||||
* @param fx_info
|
||||
*
|
||||
* @return Array of possible ambiguous chars that should be checked.
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Mar 12 19:38:03 1991, DSJ, Created.
|
||||
*/
|
||||
UNICHAR_ID *Classify::BaselineClassifier(
|
||||
TBLOB *Blob, const GenericVector<INT_FEATURE_STRUCT>& int_features,
|
||||
@ -1343,9 +1312,6 @@ UNICHAR_ID *Classify::BaselineClassifier(
|
||||
* - CharNormCutoffs expected num features for each class
|
||||
* - AllProtosOn mask that enables all protos
|
||||
* - AllConfigsOn mask that enables all configs
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Mar 12 16:02:52 1991, DSJ, Created.
|
||||
*/
|
||||
int Classify::CharNormClassifier(TBLOB *blob,
|
||||
const TrainingSample& sample,
|
||||
@ -1434,9 +1400,6 @@ int Classify::CharNormTrainingSample(bool pruner_only,
|
||||
*
|
||||
* Globals:
|
||||
* - matcher_avg_noise_size avg. length of a noise blob
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Mar 12 18:36:52 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::ClassifyAsNoise(ADAPT_RESULTS *results) {
|
||||
float rating = results->BlobLength / matcher_avg_noise_size;
|
||||
@ -1456,8 +1419,8 @@ void Classify::ConvertMatchesToChoices(const DENORM& denorm, const TBOX& box,
|
||||
ADAPT_RESULTS *Results,
|
||||
BLOB_CHOICE_LIST *Choices) {
|
||||
assert(Choices != nullptr);
|
||||
FLOAT32 Rating;
|
||||
FLOAT32 Certainty;
|
||||
float Rating;
|
||||
float Certainty;
|
||||
BLOB_CHOICE_IT temp_it;
|
||||
bool contains_nonfrag = false;
|
||||
temp_it.set_to_list(Choices);
|
||||
@ -1474,7 +1437,7 @@ void Classify::ConvertMatchesToChoices(const DENORM& denorm, const TBOX& box,
|
||||
max_matches = MAX_MATCHES;
|
||||
}
|
||||
|
||||
float best_certainty = -MAX_FLOAT32;
|
||||
float best_certainty = -FLT_MAX;
|
||||
for (int i = 0; i < Results->match.size(); i++) {
|
||||
const UnicharRating& result = Results->match[i];
|
||||
bool adapted = result.adapted;
|
||||
@ -1535,9 +1498,6 @@ void Classify::ConvertMatchesToChoices(const DENORM& denorm, const TBOX& box,
|
||||
* @param Results results of match being debugged
|
||||
*
|
||||
* Globals: none
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed Mar 13 16:44:41 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::DebugAdaptiveClassifier(TBLOB *blob,
|
||||
ADAPT_RESULTS *Results) {
|
||||
@ -1571,9 +1531,6 @@ void Classify::DebugAdaptiveClassifier(TBLOB *blob,
|
||||
* - PreTrainedTemplates built-in training templates
|
||||
* - AdaptedTemplates templates adapted for this page
|
||||
* - matcher_reliable_adaptive_result rating limit for a great match
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Mar 12 08:50:11 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::DoAdaptiveMatch(TBLOB *Blob, ADAPT_RESULTS *Results) {
|
||||
UNICHAR_ID *Ambiguities;
|
||||
@ -1629,8 +1586,6 @@ void Classify::DoAdaptiveMatch(TBLOB *Blob, ADAPT_RESULTS *Results) {
|
||||
* - PreTrainedTemplates built-in templates
|
||||
*
|
||||
* @return String containing all possible ambiguous classes.
|
||||
* @note Exceptions: none
|
||||
* @note History: Fri Mar 15 08:08:22 1991, DSJ, Created.
|
||||
*/
|
||||
UNICHAR_ID *Classify::GetAmbiguities(TBLOB *Blob,
|
||||
CLASS_ID CorrectClass) {
|
||||
@ -1717,8 +1672,6 @@ bool Classify::LooksLikeGarbage(TBLOB *blob) {
|
||||
* Globals:
|
||||
*
|
||||
* @return Number of features extracted or 0 if an error occurred.
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue May 28 10:40:52 1991, DSJ, Created.
|
||||
*/
|
||||
int Classify::GetCharNormFeature(const INT_FX_RESULT_STRUCT& fx_info,
|
||||
INT_TEMPLATES templates,
|
||||
@ -1781,8 +1734,6 @@ void Classify::ComputeCharNormArrays(FEATURE_STRUCT* norm_feature,
|
||||
*
|
||||
* @return The id of the new config created, a negative integer in
|
||||
* case of error.
|
||||
* @note Exceptions: none
|
||||
* @note History: Fri Mar 15 08:49:46 1991, DSJ, Created.
|
||||
*/
|
||||
int Classify::MakeNewTemporaryConfig(ADAPT_TEMPLATES Templates,
|
||||
CLASS_ID ClassId,
|
||||
@ -1878,8 +1829,6 @@ int Classify::MakeNewTemporaryConfig(ADAPT_TEMPLATES Templates,
|
||||
* Globals: none
|
||||
*
|
||||
* @return Max proto id in class after all protos have been added.
|
||||
* Exceptions: none
|
||||
* History: Fri Mar 15 11:39:38 1991, DSJ, Created.
|
||||
*/
|
||||
PROTO_ID Classify::MakeNewTempProtos(FEATURE_SET Features,
|
||||
int NumBadFeat,
|
||||
@ -1893,9 +1842,9 @@ PROTO_ID Classify::MakeNewTempProtos(FEATURE_SET Features,
|
||||
TEMP_PROTO TempProto;
|
||||
PROTO Proto;
|
||||
FEATURE F1, F2;
|
||||
FLOAT32 X1, X2, Y1, Y2;
|
||||
FLOAT32 A1, A2, AngleDelta;
|
||||
FLOAT32 SegmentLength;
|
||||
float X1, X2, Y1, Y2;
|
||||
float A1, A2, AngleDelta;
|
||||
float SegmentLength;
|
||||
PROTO_ID Pid;
|
||||
|
||||
for (ProtoStart = BadFeat, LastBad = ProtoStart + NumBadFeat;
|
||||
@ -1966,9 +1915,6 @@ PROTO_ID Classify::MakeNewTempProtos(FEATURE_SET Features,
|
||||
* @param Blob current blob being adapted to
|
||||
*
|
||||
* Globals: none
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Mar 14 15:54:08 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::MakePermanent(ADAPT_TEMPLATES Templates,
|
||||
CLASS_ID ClassId,
|
||||
@ -2029,8 +1975,6 @@ void Classify::MakePermanent(ADAPT_TEMPLATES Templates,
|
||||
* Globals: none
|
||||
*
|
||||
* @return TRUE if TempProto is converted, FALSE otherwise
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Mar 14 18:49:54 1991, DSJ, Created.
|
||||
*/
|
||||
int MakeTempProtoPerm(void *item1, void *item2) {
|
||||
ADAPT_CLASS Class;
|
||||
@ -2064,9 +2008,6 @@ namespace tesseract {
|
||||
* @param results match results to write to File
|
||||
*
|
||||
* Globals: none
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Mon Mar 18 09:24:53 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::PrintAdaptiveMatchResults(const ADAPT_RESULTS& results) {
|
||||
for (int i = 0; i < results.match.size(); ++i) {
|
||||
@ -2087,13 +2028,10 @@ void Classify::PrintAdaptiveMatchResults(const ADAPT_RESULTS& results) {
|
||||
*
|
||||
* Globals:
|
||||
* - matcher_bad_match_pad defines a "bad match"
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Mar 12 13:51:03 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::RemoveBadMatches(ADAPT_RESULTS *Results) {
|
||||
int Next, NextGood;
|
||||
FLOAT32 BadMatchThreshold;
|
||||
float BadMatchThreshold;
|
||||
static const char* romans = "i v x I V X";
|
||||
BadMatchThreshold = Results->best_rating - matcher_bad_match_pad;
|
||||
|
||||
@ -2150,8 +2088,6 @@ void Classify::RemoveBadMatches(ADAPT_RESULTS *Results) {
|
||||
* present.
|
||||
*
|
||||
* @param Results contains matches to be filtered
|
||||
*
|
||||
* @note History: Tue Mar 12 13:51:03 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::RemoveExtraPuncs(ADAPT_RESULTS *Results) {
|
||||
int Next, NextGood;
|
||||
@ -2200,11 +2136,8 @@ void Classify::RemoveExtraPuncs(ADAPT_RESULTS *Results) {
|
||||
*
|
||||
* Globals:
|
||||
* - matcher_good_threshold default good match rating
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Apr 9 08:33:13 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::SetAdaptiveThreshold(FLOAT32 Threshold) {
|
||||
void Classify::SetAdaptiveThreshold(float Threshold) {
|
||||
Threshold = (Threshold == matcher_good_threshold) ? 0.9: (1.0 - Threshold);
|
||||
classify_adapt_proto_threshold.set_value(
|
||||
ClipToRange<int>(255 * Threshold, 0, 255));
|
||||
@ -2220,9 +2153,6 @@ void Classify::SetAdaptiveThreshold(FLOAT32 Threshold) {
|
||||
* @param shape_id classifier id to work with
|
||||
* @param features features of the unknown character
|
||||
* @param num_features Number of features in the features array.
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Fri Mar 22 08:43:52 1991, DSJ, Created.
|
||||
*/
|
||||
|
||||
void Classify::ShowBestMatchFor(int shape_id,
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
#include "classify.h"
|
||||
#ifndef DISABLED_LEGACY_ENGINE
|
||||
#include "efio.h"
|
||||
#include "featdefs.h"
|
||||
#include "mf.h"
|
||||
#include "normfeat.h"
|
||||
@ -101,12 +100,15 @@ void Classify::LearnBlob(const STRING& fontname, TBLOB* blob,
|
||||
// Writes stored training data to a .tr file based on the given filename.
|
||||
// Returns false on error.
|
||||
bool Classify::WriteTRFile(const STRING& filename) {
|
||||
bool result = false;
|
||||
STRING tr_filename = filename + ".tr";
|
||||
FILE* fp = Efopen(tr_filename.string(), "wb");
|
||||
const size_t len = tr_file_data_.length();
|
||||
const bool result =
|
||||
fwrite(&tr_file_data_[0], sizeof(tr_file_data_[0]), len, fp) == len;
|
||||
fclose(fp);
|
||||
FILE* fp = fopen(tr_filename.string(), "wb");
|
||||
if (fp) {
|
||||
const size_t len = tr_file_data_.length();
|
||||
result =
|
||||
fwrite(&tr_file_data_[0], sizeof(tr_file_data_[0]), len, fp) == len;
|
||||
fclose(fp);
|
||||
}
|
||||
tr_file_data_.truncate_at(0);
|
||||
return result;
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ void Classify::AddLargeSpeckleTo(int blob_length, BLOB_CHOICE_LIST *choices) {
|
||||
(rating_scale * blob_length);
|
||||
}
|
||||
BLOB_CHOICE* blob_choice = new BLOB_CHOICE(UNICHAR_SPACE, rating, certainty,
|
||||
-1, 0.0f, MAX_FLOAT32, 0,
|
||||
-1, 0.0f, FLT_MAX, 0,
|
||||
BCC_SPECKLE_CLASSIFIER);
|
||||
bc_it.add_to_end(blob_choice);
|
||||
}
|
||||
|
@ -150,8 +150,8 @@ class Classify : public CCStruct {
|
||||
void WriteAdaptedTemplates(FILE *File, ADAPT_TEMPLATES Templates);
|
||||
ADAPT_TEMPLATES ReadAdaptedTemplates(TFile* File);
|
||||
/* normmatch.cpp ************************************************************/
|
||||
FLOAT32 ComputeNormMatch(CLASS_ID ClassId,
|
||||
const FEATURE_STRUCT& feature, bool DebugMatch);
|
||||
float ComputeNormMatch(CLASS_ID ClassId,
|
||||
const FEATURE_STRUCT& feature, bool DebugMatch);
|
||||
void FreeNormProtos();
|
||||
NORM_PROTOS* ReadNormProtos(TFile* fp);
|
||||
/* protos.cpp ***************************************************************/
|
||||
@ -256,7 +256,7 @@ class Classify : public CCStruct {
|
||||
void PrintAdaptiveMatchResults(const ADAPT_RESULTS& results);
|
||||
void RemoveExtraPuncs(ADAPT_RESULTS *Results);
|
||||
void RemoveBadMatches(ADAPT_RESULTS *Results);
|
||||
void SetAdaptiveThreshold(FLOAT32 Threshold);
|
||||
void SetAdaptiveThreshold(float Threshold);
|
||||
void ShowBestMatchFor(int shape_id,
|
||||
const INT_FEATURE_STRUCT* features,
|
||||
int num_features);
|
||||
@ -295,7 +295,7 @@ class Classify : public CCStruct {
|
||||
UNICHAR_ID *GetAmbiguities(TBLOB *Blob, CLASS_ID CorrectClass);
|
||||
void DoAdaptiveMatch(TBLOB *Blob, ADAPT_RESULTS *Results);
|
||||
void AdaptToChar(TBLOB* Blob, CLASS_ID ClassId, int FontinfoId,
|
||||
FLOAT32 Threshold, ADAPT_TEMPLATES adaptive_templates);
|
||||
float Threshold, ADAPT_TEMPLATES adaptive_templates);
|
||||
void DisplayAdaptedChar(TBLOB* blob, INT_CLASS_STRUCT* int_class);
|
||||
bool AdaptableWord(WERD_RES* word);
|
||||
void EndAdaptiveClassifier();
|
||||
@ -393,7 +393,7 @@ class Classify : public CCStruct {
|
||||
return fontset_table_;
|
||||
}
|
||||
/* mfoutline.cpp ***********************************************************/
|
||||
void NormalizeOutlines(LIST Outlines, FLOAT32 *XScale, FLOAT32 *YScale);
|
||||
void NormalizeOutlines(LIST Outlines, float *XScale, float *YScale);
|
||||
/* outfeat.cpp ***********************************************************/
|
||||
FEATURE_SET ExtractOutlineFeatures(TBLOB *Blob);
|
||||
/* picofeat.cpp ***********************************************************/
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,10 +1,9 @@
|
||||
/******************************************************************************
|
||||
** Filename: cluster.h
|
||||
** Purpose: Definition of feature space clustering routines
|
||||
** Author: Dan Johnson
|
||||
** History: 5/29/89, DSJ, Created.
|
||||
** Filename: cluster.h
|
||||
** Purpose: Definition of feature space clustering routines
|
||||
** Author: Dan Johnson
|
||||
**
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
@ -14,9 +13,10 @@
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
******************************************************************************/
|
||||
#ifndef CLUSTER_H
|
||||
#define CLUSTER_H
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef CLUSTER_H
|
||||
#define CLUSTER_H
|
||||
|
||||
#include "kdtree.h"
|
||||
#include "oldlist.h"
|
||||
@ -30,13 +30,13 @@ struct BUCKETS;
|
||||
Types
|
||||
----------------------------------------------------------------------*/
|
||||
typedef struct sample {
|
||||
unsigned Clustered:1; // TRUE if included in a higher cluster
|
||||
unsigned Prototype:1; // TRUE if cluster represented by a proto
|
||||
unsigned SampleCount:30; // number of samples in this cluster
|
||||
struct sample *Left; // ptr to left sub-cluster
|
||||
struct sample *Right; // ptr to right sub-cluster
|
||||
int32_t CharID; // identifier of char sample came from
|
||||
FLOAT32 Mean[1]; // mean of cluster - SampleSize floats
|
||||
unsigned Clustered:1; // TRUE if included in a higher cluster
|
||||
unsigned Prototype:1; // TRUE if cluster represented by a proto
|
||||
unsigned SampleCount:30; // number of samples in this cluster
|
||||
struct sample *Left; // ptr to left sub-cluster
|
||||
struct sample *Right; // ptr to right sub-cluster
|
||||
int32_t CharID; // identifier of char sample came from
|
||||
float Mean[1]; // mean of cluster - SampleSize floats
|
||||
} CLUSTER;
|
||||
|
||||
typedef CLUSTER SAMPLE; // can refer to as either sample or cluster
|
||||
@ -45,14 +45,14 @@ typedef enum {
|
||||
spherical, elliptical, mixed, automatic
|
||||
} PROTOSTYLE;
|
||||
|
||||
typedef struct { // parameters to control clustering
|
||||
PROTOSTYLE ProtoStyle; // specifies types of protos to be made
|
||||
FLOAT32 MinSamples; // min # of samples per proto - % of total
|
||||
FLOAT32 MaxIllegal; // max percentage of samples in a cluster which have
|
||||
// more than 1 feature in that cluster
|
||||
FLOAT32 Independence; // desired independence between dimensions
|
||||
FLOAT64 Confidence; // desired confidence in prototypes created
|
||||
int MagicSamples; // Ideal number of samples in a cluster.
|
||||
typedef struct { // parameters to control clustering
|
||||
PROTOSTYLE ProtoStyle; // specifies types of protos to be made
|
||||
float MinSamples; // min # of samples per proto - % of total
|
||||
float MaxIllegal; // max percentage of samples in a cluster which
|
||||
// have more than 1 feature in that cluster
|
||||
float Independence; // desired independence between dimensions
|
||||
double Confidence; // desired confidence in prototypes created
|
||||
int MagicSamples; // Ideal number of samples in a cluster.
|
||||
} CLUSTERCONFIG;
|
||||
|
||||
typedef enum {
|
||||
@ -60,8 +60,8 @@ typedef enum {
|
||||
} DISTRIBUTION;
|
||||
|
||||
typedef union {
|
||||
FLOAT32 Spherical;
|
||||
FLOAT32 *Elliptical;
|
||||
float Spherical;
|
||||
float *Elliptical;
|
||||
} FLOATUNION;
|
||||
|
||||
typedef struct {
|
||||
@ -75,29 +75,29 @@ typedef struct {
|
||||
unsigned NumSamples:28; // number of samples in the cluster
|
||||
CLUSTER *Cluster; // ptr to cluster which made prototype
|
||||
DISTRIBUTION *Distrib; // different distribution for each dimension
|
||||
FLOAT32 *Mean; // prototype mean
|
||||
FLOAT32 TotalMagnitude; // total magnitude over all dimensions
|
||||
FLOAT32 LogMagnitude; // log base e of TotalMagnitude
|
||||
float *Mean; // prototype mean
|
||||
float TotalMagnitude; // total magnitude over all dimensions
|
||||
float LogMagnitude; // log base e of TotalMagnitude
|
||||
FLOATUNION Variance; // prototype variance
|
||||
FLOATUNION Magnitude; // magnitude of density function
|
||||
FLOATUNION Weight; // weight of density function
|
||||
} PROTOTYPE;
|
||||
|
||||
typedef struct {
|
||||
int16_t SampleSize; // number of parameters per sample
|
||||
int16_t SampleSize; // number of parameters per sample
|
||||
PARAM_DESC *ParamDesc; // description of each parameter
|
||||
int32_t NumberOfSamples; // total number of samples being clustered
|
||||
int32_t NumberOfSamples; // total number of samples being clustered
|
||||
KDTREE *KDTree; // for optimal nearest neighbor searching
|
||||
CLUSTER *Root; // ptr to root cluster of cluster tree
|
||||
LIST ProtoList; // list of prototypes
|
||||
int32_t NumChar; // # of characters represented by samples
|
||||
int32_t NumChar; // # of characters represented by samples
|
||||
// cache of reusable histograms by distribution type and number of buckets.
|
||||
BUCKETS* bucket_cache[DISTRIBUTION_COUNT][MAXBUCKETS + 1 - MINBUCKETS];
|
||||
} CLUSTERER;
|
||||
|
||||
typedef struct {
|
||||
int32_t NumSamples; // number of samples in list
|
||||
int32_t MaxNumSamples; // maximum size of list
|
||||
int32_t NumSamples; // number of samples in list
|
||||
int32_t MaxNumSamples; // maximum size of list
|
||||
SAMPLE *Sample[1]; // array of ptrs to sample data structures
|
||||
} SAMPLELIST;
|
||||
|
||||
@ -109,7 +109,7 @@ typedef struct {
|
||||
--------------------------------------------------------------------------*/
|
||||
CLUSTERER *MakeClusterer (int16_t SampleSize, const PARAM_DESC ParamDesc[]);
|
||||
|
||||
SAMPLE *MakeSample(CLUSTERER * Clusterer, const FLOAT32* Feature, int32_t CharID);
|
||||
SAMPLE *MakeSample(CLUSTERER* Clusterer, const float* Feature, int32_t CharID);
|
||||
|
||||
LIST ClusterSamples(CLUSTERER *Clusterer, CLUSTERCONFIG *Config);
|
||||
|
||||
@ -121,14 +121,11 @@ void FreePrototype(void *arg); // PROTOTYPE *Prototype);
|
||||
|
||||
CLUSTER *NextSample(LIST *SearchState);
|
||||
|
||||
FLOAT32 Mean(PROTOTYPE *Proto, uint16_t Dimension);
|
||||
float Mean(PROTOTYPE *Proto, uint16_t Dimension);
|
||||
|
||||
FLOAT32 StandardDeviation(PROTOTYPE *Proto, uint16_t Dimension);
|
||||
float StandardDeviation(PROTOTYPE *Proto, uint16_t Dimension);
|
||||
|
||||
int32_t MergeClusters(int16_t N, PARAM_DESC ParamDesc[], int32_t n1, int32_t n2,
|
||||
FLOAT32 m[], FLOAT32 m1[], FLOAT32 m2[]);
|
||||
float m[], float m1[], float m2[]);
|
||||
|
||||
//--------------Global Data Definitions and Declarations---------------------------
|
||||
// define errors that can be trapped
|
||||
#define ALREADYCLUSTERED 4000
|
||||
#endif
|
||||
|
@ -2,7 +2,6 @@
|
||||
** Filename: clustertool.c
|
||||
** Purpose: Misc. tools for use with the clustering routines
|
||||
** Author: Dan Johnson
|
||||
** History: 6/6/89, DSJ, Created.
|
||||
**
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -14,12 +13,10 @@
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
******************************************************************************/
|
||||
*****************************************************************************/
|
||||
|
||||
//--------------------------Include Files----------------------------------
|
||||
#include "clusttool.h"
|
||||
#include "const.h"
|
||||
#include "danerror.h"
|
||||
#include "emalloc.h"
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
@ -40,34 +37,26 @@ using tesseract::TFile;
|
||||
* @param fp open text file to read sample size from
|
||||
* @return Sample size
|
||||
* @note Globals: None
|
||||
* @note Exceptions: ILLEGALSAMPLESIZE illegal format or range
|
||||
* @note History: 6/6/89, DSJ, Created.
|
||||
*/
|
||||
uint16_t ReadSampleSize(TFile *fp) {
|
||||
int SampleSize = 0;
|
||||
|
||||
const int kMaxLineSize = 100;
|
||||
char line[kMaxLineSize];
|
||||
if (fp->FGets(line, kMaxLineSize) == nullptr ||
|
||||
sscanf(line, "%d", &SampleSize) != 1 || (SampleSize < 0) ||
|
||||
(SampleSize > MAXSAMPLESIZE))
|
||||
DoError (ILLEGALSAMPLESIZE, "Illegal sample size");
|
||||
return (SampleSize);
|
||||
ASSERT_HOST(fp->FGets(line, kMaxLineSize) != nullptr);
|
||||
ASSERT_HOST(sscanf(line, "%d", &SampleSize) == 1);
|
||||
ASSERT_HOST(SampleSize >= 0 && SampleSize <= MAXSAMPLESIZE);
|
||||
return SampleSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine reads textual descriptions of sets of parameters
|
||||
* which describe the characteristics of feature dimensions.
|
||||
*
|
||||
* Exceptions:
|
||||
* - ILLEGALCIRCULARSPEC
|
||||
* - ILLEGALESSENTIALSPEC
|
||||
* - ILLEGALMINMAXSPEC
|
||||
* @param fp open text file to read N parameter descriptions from
|
||||
* @param N number of parameter descriptions to read
|
||||
* @return Pointer to an array of parameter descriptors.
|
||||
* @note Globals: None
|
||||
* @note History: 6/6/89, DSJ, Created.
|
||||
*/
|
||||
PARAM_DESC *ReadParamDesc(TFile *fp, uint16_t N) {
|
||||
PARAM_DESC *ParamDesc;
|
||||
@ -77,11 +66,11 @@ PARAM_DESC *ReadParamDesc(TFile *fp, uint16_t N) {
|
||||
for (int i = 0; i < N; i++) {
|
||||
const int kMaxLineSize = TOKENSIZE * 4;
|
||||
char line[kMaxLineSize];
|
||||
if (fp->FGets(line, kMaxLineSize) == nullptr ||
|
||||
sscanf(line, "%" QUOTED_TOKENSIZE "s %" QUOTED_TOKENSIZE "s %f %f",
|
||||
linear_token, essential_token, &ParamDesc[i].Min,
|
||||
&ParamDesc[i].Max) != 4)
|
||||
DoError(ILLEGALCIRCULARSPEC, "Illegal Parameter specification");
|
||||
ASSERT_HOST(fp->FGets(line, kMaxLineSize) != nullptr);
|
||||
ASSERT_HOST(sscanf(line,
|
||||
"%" QUOTED_TOKENSIZE "s %" QUOTED_TOKENSIZE "s %f %f",
|
||||
linear_token, essential_token, &ParamDesc[i].Min,
|
||||
&ParamDesc[i].Max) == 4);
|
||||
if (linear_token[0] == 'c')
|
||||
ParamDesc[i].Circular = TRUE;
|
||||
else
|
||||
@ -102,17 +91,10 @@ PARAM_DESC *ReadParamDesc(TFile *fp, uint16_t N) {
|
||||
* This routine reads a textual description of a prototype from
|
||||
* the specified file.
|
||||
*
|
||||
* Exceptions:
|
||||
* - ILLEGALSIGNIFICANCESPEC
|
||||
* - ILLEGALSAMPLECOUNT
|
||||
* - ILLEGALMEANSPEC
|
||||
* - ILLEGALVARIANCESPEC
|
||||
* - ILLEGALDISTRIBUTION
|
||||
* @param fp open text file to read prototype from
|
||||
* @param N number of dimensions used in prototype
|
||||
* @return List of prototypes
|
||||
* @note Globals: None
|
||||
* @note History: 6/6/89, DSJ, Created.
|
||||
*/
|
||||
PROTOTYPE *ReadPrototype(TFile *fp, uint16_t N) {
|
||||
char sig_token[TOKENSIZE], shape_token[TOKENSIZE];
|
||||
@ -150,18 +132,17 @@ PROTOTYPE *ReadPrototype(TFile *fp, uint16_t N) {
|
||||
Proto->Style = elliptical;
|
||||
}
|
||||
|
||||
if (SampleCount < 0) DoError(ILLEGALSAMPLECOUNT, "Illegal sample count");
|
||||
ASSERT_HOST(SampleCount >= 0);
|
||||
Proto->NumSamples = SampleCount;
|
||||
|
||||
Proto->Mean = ReadNFloats(fp, N, nullptr);
|
||||
if (Proto->Mean == nullptr) DoError(ILLEGALMEANSPEC, "Illegal prototype mean");
|
||||
ASSERT_HOST(Proto->Mean != nullptr);
|
||||
|
||||
switch (Proto->Style) {
|
||||
case spherical:
|
||||
if (ReadNFloats(fp, 1, &(Proto->Variance.Spherical)) == nullptr)
|
||||
DoError(ILLEGALVARIANCESPEC, "Illegal prototype variance");
|
||||
ASSERT_HOST(ReadNFloats(fp, 1, &(Proto->Variance.Spherical)) != nullptr);
|
||||
Proto->Magnitude.Spherical =
|
||||
1.0 / sqrt((double)(2.0 * PI * Proto->Variance.Spherical));
|
||||
1.0 / sqrt(2.0 * M_PI * Proto->Variance.Spherical);
|
||||
Proto->TotalMagnitude = pow(Proto->Magnitude.Spherical, (float)N);
|
||||
Proto->LogMagnitude = log((double)Proto->TotalMagnitude);
|
||||
Proto->Weight.Spherical = 1.0 / Proto->Variance.Spherical;
|
||||
@ -169,14 +150,13 @@ PROTOTYPE *ReadPrototype(TFile *fp, uint16_t N) {
|
||||
break;
|
||||
case elliptical:
|
||||
Proto->Variance.Elliptical = ReadNFloats(fp, N, nullptr);
|
||||
if (Proto->Variance.Elliptical == nullptr)
|
||||
DoError(ILLEGALVARIANCESPEC, "Illegal prototype variance");
|
||||
Proto->Magnitude.Elliptical = (FLOAT32 *)Emalloc(N * sizeof(FLOAT32));
|
||||
Proto->Weight.Elliptical = (FLOAT32 *)Emalloc(N * sizeof(FLOAT32));
|
||||
ASSERT_HOST(Proto->Variance.Elliptical != nullptr);
|
||||
Proto->Magnitude.Elliptical = (float *)Emalloc(N * sizeof(float));
|
||||
Proto->Weight.Elliptical = (float *)Emalloc(N * sizeof(float));
|
||||
Proto->TotalMagnitude = 1.0;
|
||||
for (i = 0; i < N; i++) {
|
||||
Proto->Magnitude.Elliptical[i] =
|
||||
1.0 / sqrt((double)(2.0 * PI * Proto->Variance.Elliptical[i]));
|
||||
1.0 / sqrt(2.0 * M_PI * Proto->Variance.Elliptical[i]);
|
||||
Proto->Weight.Elliptical[i] = 1.0 / Proto->Variance.Elliptical[i];
|
||||
Proto->TotalMagnitude *= Proto->Magnitude.Elliptical[i];
|
||||
}
|
||||
@ -202,10 +182,8 @@ PROTOTYPE *ReadPrototype(TFile *fp, uint16_t N) {
|
||||
* @param Buffer pointer to buffer to place floats into
|
||||
* @return Pointer to buffer holding floats or nullptr if EOF
|
||||
* @note Globals: None
|
||||
* @note Exceptions: ILLEGALFLOAT
|
||||
* @note History: 6/6/89, DSJ, Created.
|
||||
*/
|
||||
FLOAT32 *ReadNFloats(TFile *fp, uint16_t N, FLOAT32 Buffer[]) {
|
||||
float *ReadNFloats(TFile *fp, uint16_t N, float Buffer[]) {
|
||||
const int kMaxLineSize = 1024;
|
||||
char line[kMaxLineSize];
|
||||
if (fp->FGets(line, kMaxLineSize) == nullptr) {
|
||||
@ -215,7 +193,7 @@ FLOAT32 *ReadNFloats(TFile *fp, uint16_t N, FLOAT32 Buffer[]) {
|
||||
bool needs_free = false;
|
||||
|
||||
if (Buffer == nullptr) {
|
||||
Buffer = static_cast<FLOAT32 *>(Emalloc(N * sizeof(FLOAT32)));
|
||||
Buffer = static_cast<float *>(Emalloc(N * sizeof(float)));
|
||||
needs_free = true;
|
||||
}
|
||||
|
||||
@ -241,8 +219,6 @@ FLOAT32 *ReadNFloats(TFile *fp, uint16_t N, FLOAT32 Buffer[]) {
|
||||
* @param ParamDesc array of param descriptors to write
|
||||
* @return None
|
||||
* @note Globals: None
|
||||
* @note Exceptions: None
|
||||
* @note History: 6/6/89, DSJ, Created.
|
||||
*/
|
||||
void WriteParamDesc(FILE *File, uint16_t N, const PARAM_DESC ParamDesc[]) {
|
||||
int i;
|
||||
@ -270,8 +246,6 @@ void WriteParamDesc(FILE *File, uint16_t N, const PARAM_DESC ParamDesc[]) {
|
||||
* @param Proto prototype to write out
|
||||
* @return None
|
||||
* @note Globals: None
|
||||
* @note Exceptions: None
|
||||
* @note History: 6/12/89, DSJ, Created.
|
||||
*/
|
||||
void WritePrototype(FILE *File, uint16_t N, PROTOTYPE *Proto) {
|
||||
int i;
|
||||
@ -320,10 +294,8 @@ void WritePrototype(FILE *File, uint16_t N, PROTOTYPE *Proto) {
|
||||
* @param Array array of floats to write
|
||||
* @return None
|
||||
* @note Globals: None
|
||||
* @note Exceptions: None
|
||||
* @note History: 6/6/89, DSJ, Created.
|
||||
*/
|
||||
void WriteNFloats(FILE * File, uint16_t N, FLOAT32 Array[]) {
|
||||
void WriteNFloats(FILE * File, uint16_t N, float Array[]) {
|
||||
for (int i = 0; i < N; i++)
|
||||
fprintf(File, " %9.6f", Array[i]);
|
||||
fprintf(File, "\n");
|
||||
@ -337,8 +309,6 @@ void WriteNFloats(FILE * File, uint16_t N, FLOAT32 Array[]) {
|
||||
* @param ProtoStyle prototype style to write
|
||||
* @return None
|
||||
* @note Globals: None
|
||||
* @note Exceptions: None
|
||||
* @note History: 6/8/89, DSJ, Created.
|
||||
*/
|
||||
void WriteProtoStyle(FILE *File, PROTOSTYLE ProtoStyle) {
|
||||
switch (ProtoStyle) {
|
||||
@ -370,9 +340,7 @@ void WriteProtoStyle(FILE *File, PROTOSTYLE ProtoStyle) {
|
||||
* @param WriteInsigProtos TRUE to write out insignificants
|
||||
* @note Globals: None
|
||||
* @return None
|
||||
* @note Exceptions: None
|
||||
* @note History: 6/12/89, DSJ, Created.
|
||||
*/
|
||||
*/
|
||||
|
||||
void WriteProtoList(FILE* File, uint16_t N, PARAM_DESC* ParamDesc,
|
||||
LIST ProtoList, bool WriteSigProtos,
|
||||
|
@ -2,7 +2,6 @@
|
||||
** Filename: clusttool.h
|
||||
** Purpose: Definition of clustering utility tools
|
||||
** Author: Dan Johnson
|
||||
** History: 6/6/89, DSJ, Created.
|
||||
**
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -34,13 +33,13 @@ PARAM_DESC *ReadParamDesc(tesseract::TFile *fp, uint16_t N);
|
||||
|
||||
PROTOTYPE *ReadPrototype(tesseract::TFile *fp, uint16_t N);
|
||||
|
||||
FLOAT32 *ReadNFloats(tesseract::TFile *fp, uint16_t N, FLOAT32 Buffer[]);
|
||||
float *ReadNFloats(tesseract::TFile *fp, uint16_t N, float Buffer[]);
|
||||
|
||||
void WriteParamDesc(FILE *File, uint16_t N, const PARAM_DESC ParamDesc[]);
|
||||
|
||||
void WritePrototype(FILE *File, uint16_t N, PROTOTYPE *Proto);
|
||||
|
||||
void WriteNFloats (FILE * File, uint16_t N, FLOAT32 Array[]);
|
||||
void WriteNFloats (FILE * File, uint16_t N, float Array[]);
|
||||
|
||||
void WriteProtoStyle(FILE *File, PROTOSTYLE ProtoStyle);
|
||||
|
||||
@ -48,17 +47,4 @@ void WriteProtoList(FILE* File, uint16_t N, PARAM_DESC* ParamDesc,
|
||||
LIST ProtoList, bool WriteSigProtos,
|
||||
bool WriteInsigProtos);
|
||||
|
||||
//--------------Global Data Definitions and Declarations---------------------
|
||||
// define errors that can be trapped
|
||||
#define ILLEGALSAMPLESIZE 5000
|
||||
#define ILLEGALCIRCULARSPEC 5001
|
||||
#define ILLEGALMINMAXSPEC 5002
|
||||
#define ILLEGALSIGNIFICANCESPEC 5003
|
||||
#define ILLEGALSTYLESPEC 5004
|
||||
#define ILLEGALSAMPLECOUNT 5005
|
||||
#define ILLEGALMEANSPEC 5006
|
||||
#define ILLEGALVARIANCESPEC 5007
|
||||
#define ILLEGALDISTRIBUTION 5008
|
||||
#define ILLEGALFLOAT 5009
|
||||
#define ILLEGALESSENTIALSPEC 5013
|
||||
#endif // TESSERACT_CLASSIFY_CLUSTTOOL_H_
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include <cstdio>
|
||||
|
||||
#include "classify.h"
|
||||
#include "efio.h"
|
||||
#include "globals.h"
|
||||
#include "helpers.h"
|
||||
#include "serialis.h"
|
||||
@ -43,8 +42,6 @@ namespace tesseract {
|
||||
* @param Cutoffs array to put cutoffs into
|
||||
* @return none
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed Feb 20 09:38:26 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::ReadNewCutoffs(TFile* fp, CLASS_CUTOFF_ARRAY Cutoffs) {
|
||||
char Class[UNICHAR_LEN + 1];
|
||||
|
@ -1,8 +1,7 @@
|
||||
/******************************************************************************
|
||||
** Filename: featdefs.c
|
||||
** Filename: featdefs.cpp
|
||||
** Purpose: Definitions of currently defined feature types.
|
||||
** Author: Dan Johnson
|
||||
** History: Mon May 21 10:26:21 1990, DSJ, Created.
|
||||
**
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -20,15 +19,11 @@
|
||||
-----------------------------------------------------------------------------*/
|
||||
#include "featdefs.h"
|
||||
#include "emalloc.h"
|
||||
#include "danerror.h"
|
||||
#include "scanutils.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
|
||||
/** define errors triggered by this module */
|
||||
#define ILLEGAL_NUM_SETS 3001
|
||||
|
||||
#define PICO_FEATURE_LENGTH 0.05
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
@ -84,7 +79,7 @@ DefineFeature(GeoFeatDesc, 3, 0, kGeoFeatureType, GeoFeatParams)
|
||||
|
||||
// Define all of the parameters for the PicoFeature type
|
||||
// define knob that can be used to adjust pico-feature length.
|
||||
FLOAT32 PicoFeatureLength = PICO_FEATURE_LENGTH;
|
||||
float PicoFeatureLength = PICO_FEATURE_LENGTH;
|
||||
StartParamDesc(PicoFeatParams)
|
||||
DefineParam(0, 0, -0.25, 0.75)
|
||||
DefineParam(1, 0, 0.0, 1.0)
|
||||
@ -130,9 +125,6 @@ void InitFeatureDefs(FEATURE_DEFS_STRUCT *featuredefs) {
|
||||
*
|
||||
* Globals:
|
||||
* - none
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed May 23 13:52:19 1990, DSJ, Created.
|
||||
*/
|
||||
void FreeCharDescription(CHAR_DESC CharDesc) {
|
||||
if (CharDesc) {
|
||||
@ -152,8 +144,6 @@ void FreeCharDescription(CHAR_DESC CharDesc) {
|
||||
* - none
|
||||
*
|
||||
* @return New character description structure.
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed May 23 15:27:10 1990, DSJ, Created.
|
||||
*/
|
||||
CHAR_DESC NewCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs) {
|
||||
CHAR_DESC CharDesc;
|
||||
@ -164,10 +154,8 @@ CHAR_DESC NewCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs) {
|
||||
CharDesc->FeatureSets[i] = nullptr;
|
||||
|
||||
return (CharDesc);
|
||||
|
||||
} /* NewCharDescription */
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Appends a textual representation of CharDesc to str.
|
||||
@ -182,9 +170,6 @@ CHAR_DESC NewCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs) {
|
||||
* @param FeatureDefs definitions of feature types/extractors
|
||||
* @param str string to append CharDesc to
|
||||
* @param CharDesc character description to write to File
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed May 23 17:21:18 1990, DSJ, Created.
|
||||
*/
|
||||
void WriteCharDescription(const FEATURE_DEFS_STRUCT& FeatureDefs,
|
||||
CHAR_DESC CharDesc, STRING* str) {
|
||||
@ -247,9 +232,6 @@ bool ValidCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs,
|
||||
* @param FeatureDefs definitions of feature types/extractors
|
||||
* @param File open text file to read character description from
|
||||
* @return Character description read from File.
|
||||
* @note Exceptions:
|
||||
* - ILLEGAL_NUM_SETS
|
||||
* @note History: Wed May 23 17:32:48 1990, DSJ, Created.
|
||||
*/
|
||||
CHAR_DESC ReadCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs,
|
||||
FILE *File) {
|
||||
@ -258,9 +240,9 @@ CHAR_DESC ReadCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs,
|
||||
CHAR_DESC CharDesc;
|
||||
int Type;
|
||||
|
||||
if (tfscanf(File, "%d", &NumSetsToRead) != 1 ||
|
||||
NumSetsToRead < 0 || NumSetsToRead > FeatureDefs.NumFeatureTypes)
|
||||
DoError (ILLEGAL_NUM_SETS, "Illegal number of feature sets");
|
||||
ASSERT_HOST(tfscanf(File, "%d", &NumSetsToRead) == 1);
|
||||
ASSERT_HOST(NumSetsToRead >= 0);
|
||||
ASSERT_HOST(NumSetsToRead <= FeatureDefs.NumFeatureTypes);
|
||||
|
||||
CharDesc = NewCharDescription(FeatureDefs);
|
||||
for (; NumSetsToRead > 0; NumSetsToRead--) {
|
||||
@ -269,10 +251,8 @@ CHAR_DESC ReadCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs,
|
||||
CharDesc->FeatureSets[Type] =
|
||||
ReadFeatureSet (File, FeatureDefs.FeatureDesc[Type]);
|
||||
}
|
||||
return (CharDesc);
|
||||
|
||||
} // ReadCharDescription
|
||||
|
||||
return CharDesc;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
@ -286,18 +266,12 @@ CHAR_DESC ReadCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs,
|
||||
* @param FeatureDefs definitions of feature types/extractors
|
||||
* @param ShortName short name of a feature type
|
||||
* @return Feature type which corresponds to ShortName.
|
||||
* @note Exceptions:
|
||||
* - ILLEGAL_SHORT_NAME
|
||||
* @note History: Wed May 23 15:36:05 1990, DSJ, Created.
|
||||
*/
|
||||
uint32_t ShortNameToFeatureType(const FEATURE_DEFS_STRUCT &FeatureDefs,
|
||||
const char *ShortName) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < FeatureDefs.NumFeatureTypes; i++)
|
||||
for (int i = 0; i < FeatureDefs.NumFeatureTypes; i++)
|
||||
if (!strcmp ((FeatureDefs.FeatureDesc[i]->ShortName), ShortName))
|
||||
return static_cast<uint32_t>(i);
|
||||
DoError (ILLEGAL_SHORT_NAME, "Illegal short name for a feature");
|
||||
ASSERT_HOST(!"Illegal short name for a feature");
|
||||
return 0;
|
||||
|
||||
} // ShortNameToFeatureType
|
||||
}
|
||||
|
@ -30,9 +30,6 @@ extern const char* kCNFeatureType;
|
||||
extern const char* kIntFeatureType;
|
||||
extern const char* kGeoFeatureType;
|
||||
|
||||
/* define error traps which can be triggered by this module.*/
|
||||
#define ILLEGAL_SHORT_NAME 2000
|
||||
|
||||
/* A character is described by multiple sets of extracted features. Each
|
||||
set contains a number of features of a particular type, for example, a
|
||||
set of bays, or a set of closures, or a set of microfeatures. Each
|
||||
|
@ -1,10 +1,9 @@
|
||||
/******************************************************************************
|
||||
** Filename: float2int.c
|
||||
** Purpose: Routines for converting float features to int features
|
||||
** Author: Dan Johnson
|
||||
** History: Wed Mar 13 07:47:48 1991, DSJ, Created.
|
||||
** Filename: float2int.cpp
|
||||
** Purpose: Routines for converting float features to int features
|
||||
** Author: Dan Johnson
|
||||
**
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
@ -41,9 +40,6 @@ namespace tesseract {
|
||||
* - none
|
||||
*
|
||||
* @param char_norm_array array to be cleared
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed Feb 20 11:20:54 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::ClearCharNormArray(uint8_t* char_norm_array) {
|
||||
memset(char_norm_array, 0, sizeof(*char_norm_array) * unicharset.size());
|
||||
@ -62,9 +58,6 @@ void Classify::ClearCharNormArray(uint8_t* char_norm_array) {
|
||||
*
|
||||
* @param norm_feature character normalization feature
|
||||
* @param[out] char_norm_array place to put results of size unicharset.size()
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed Feb 20 11:20:54 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::ComputeIntCharNormArray(const FEATURE_STRUCT& norm_feature,
|
||||
uint8_t* char_norm_array) {
|
||||
@ -93,14 +86,10 @@ void Classify::ComputeIntCharNormArray(const FEATURE_STRUCT& norm_feature,
|
||||
*
|
||||
* @param Features floating point pico-features to be converted
|
||||
* @param[out] IntFeatures array to put converted features into
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed Feb 20 10:58:45 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::ComputeIntFeatures(FEATURE_SET Features,
|
||||
INT_FEATURE_ARRAY IntFeatures) {
|
||||
FEATURE Feature;
|
||||
FLOAT32 YShift;
|
||||
float YShift;
|
||||
|
||||
if (classify_norm_method == baseline)
|
||||
YShift = BASELINE_Y_SHIFT;
|
||||
@ -108,7 +97,7 @@ void Classify::ComputeIntFeatures(FEATURE_SET Features,
|
||||
YShift = Y_SHIFT;
|
||||
|
||||
for (int Fid = 0; Fid < Features->NumFeatures; Fid++) {
|
||||
Feature = Features->Features[Fid];
|
||||
FEATURE Feature = Features->Features[Fid];
|
||||
|
||||
IntFeatures[Fid].X =
|
||||
Bucket8For(Feature->Params[PicoFeatX], X_SHIFT, INT_FEAT_RANGE);
|
||||
|
@ -1,8 +1,7 @@
|
||||
/******************************************************************************
|
||||
** Filename: fpoint.c
|
||||
** Filename: fpoint.cpp
|
||||
** Purpose: Abstract data type for a 2D point (floating point coords)
|
||||
** Author: Dan Johnson
|
||||
** History: Thu Apr 12 10:44:15 1990, DSJ, Created.
|
||||
**
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -18,7 +17,6 @@
|
||||
/*----------------------------------------------------------------------------
|
||||
Include Files and Type Defines
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "const.h"
|
||||
#include "fpoint.h"
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
@ -27,7 +25,7 @@
|
||||
Public Code
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
FLOAT32 DistanceBetween(FPOINT A, FPOINT B) {
|
||||
float DistanceBetween(FPOINT A, FPOINT B) {
|
||||
const double xd = XDelta(A, B);
|
||||
const double yd = YDelta(A, B);
|
||||
return sqrt(static_cast<double>(xd * xd + yd * yd));
|
||||
@ -42,16 +40,11 @@ FLOAT32 DistanceBetween(FPOINT A, FPOINT B) {
|
||||
* @param FullScale value to associate with 2*pi
|
||||
* @return none
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed Mar 28 14:27:25 1990, DSJ, Created.
|
||||
*/
|
||||
FLOAT32 NormalizedAngleFrom(FPOINT *Point1,
|
||||
FPOINT *Point2,
|
||||
FLOAT32 FullScale) {
|
||||
FLOAT32 Angle;
|
||||
FLOAT32 NumRadsInCircle = 2.0 * PI;
|
||||
float NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, float FullScale) {
|
||||
float NumRadsInCircle = 2.0 * M_PI;
|
||||
|
||||
Angle = AngleFrom (*Point1, *Point2);
|
||||
float Angle = AngleFrom (*Point1, *Point2);
|
||||
if (Angle < 0.0)
|
||||
Angle += NumRadsInCircle;
|
||||
Angle *= FullScale / NumRadsInCircle;
|
||||
|
@ -1,10 +1,10 @@
|
||||
/******************************************************************************
|
||||
** Filename: fpoint.h
|
||||
** Purpose: Abstract data type for 2D points (floating point coords)
|
||||
** Author: Dan Johnson
|
||||
** History: Thu Apr 12 10:50:01 1990, DSJ, Created.
|
||||
** Filename: fpoint.h
|
||||
** Purpose: Abstract data type for 2D points (floating point coords)
|
||||
** Author: Dan Johnson
|
||||
**
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
@ -15,20 +15,20 @@
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
******************************************************************************/
|
||||
#ifndef FPOINT_H
|
||||
#define FPOINT_H
|
||||
|
||||
#ifndef FPOINT_H
|
||||
#define FPOINT_H
|
||||
|
||||
/**----------------------------------------------------------------------------
|
||||
Include Files and Type Defines
|
||||
----------------------------------------------------------------------------**/
|
||||
#include "host.h"
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include "host.h"
|
||||
|
||||
/* define data structure to hold 2D points or vectors using floating point */
|
||||
typedef struct
|
||||
{
|
||||
FLOAT32 x, y;
|
||||
typedef struct {
|
||||
float x, y;
|
||||
} FPOINT;
|
||||
using FVECTOR = FPOINT;
|
||||
|
||||
@ -36,19 +36,19 @@ using FVECTOR = FPOINT;
|
||||
Macros
|
||||
----------------------------------------------------------------------------**/
|
||||
/* macros for computing miscellaneous functions of 2 points */
|
||||
#define XDelta(A,B) ( (B).x - (A).x )
|
||||
#define YDelta(A,B) ( (B).y - (A).y )
|
||||
#define SlopeFrom(A,B) ( YDelta(A,B) / XDelta(A,B) )
|
||||
#define AngleFrom(A,B) ( atan2((double) YDelta(A,B), \
|
||||
(double) XDelta(A,B) ) )
|
||||
#define XDelta(A, B) ((B).x - (A).x)
|
||||
#define YDelta(A, B) ((B).y - (A).y)
|
||||
#define SlopeFrom(A, B) (YDelta(A, B) / XDelta(A, B))
|
||||
#define AngleFrom(A, B) (atan2((double)YDelta(A, B), (double)XDelta(A, B)))
|
||||
|
||||
#define XIntersectionOf(A,B,X) ( SlopeFrom(A,B) * ((X) - A.x) + A.y)
|
||||
#define XIntersectionOf(A, B, X) (SlopeFrom(A, B) * ((X)-A.x) + A.y)
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
Public Function Prototypes
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
FLOAT32 DistanceBetween(FPOINT A, FPOINT B);
|
||||
float DistanceBetween(FPOINT A, FPOINT B);
|
||||
|
||||
float NormalizedAngleFrom(FPOINT* Point1, FPOINT* Point2, float FullScale);
|
||||
|
||||
FLOAT32 NormalizedAngleFrom(FPOINT *Point1, FPOINT *Point2, FLOAT32 FullScale);
|
||||
#endif
|
||||
|
@ -107,8 +107,8 @@ int IntFeatureSpace::XYToFeatureIndex(int x, int y) const {
|
||||
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);
|
||||
double angle = atan2(static_cast<double>(y), static_cast<double>(x)) + M_PI;
|
||||
angle *= kIntFeatureExtent / (2.0 * M_PI);
|
||||
feature.Theta = static_cast<uint8_t>(angle + 0.5);
|
||||
index = Index(feature);
|
||||
if (index < 0) {
|
||||
|
@ -17,7 +17,7 @@
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
******************************************************************************/
|
||||
*****************************************************************************/
|
||||
/**----------------------------------------------------------------------------
|
||||
Include Files and Type Defines
|
||||
----------------------------------------------------------------------------**/
|
||||
@ -25,7 +25,6 @@
|
||||
#include "allheaders.h"
|
||||
#include "ccutil.h"
|
||||
#include "classify.h"
|
||||
#include "const.h"
|
||||
#include "helpers.h"
|
||||
#include "intmatcher.h"
|
||||
#include "linlsq.h"
|
||||
@ -56,8 +55,8 @@ void InitIntegerFX() {
|
||||
atan_table_mutex.Lock();
|
||||
if (!atan_table_init) {
|
||||
for (int i = 0; i < INT_CHAR_NORM_RANGE; ++i) {
|
||||
cos_table[i] = cos(i * 2 * PI / INT_CHAR_NORM_RANGE + PI);
|
||||
sin_table[i] = sin(i * 2 * PI / INT_CHAR_NORM_RANGE + PI);
|
||||
cos_table[i] = cos(i * 2 * M_PI / INT_CHAR_NORM_RANGE + M_PI);
|
||||
sin_table[i] = sin(i * 2 * M_PI / INT_CHAR_NORM_RANGE + M_PI);
|
||||
}
|
||||
atan_table_init = true;
|
||||
}
|
||||
|
@ -1,11 +1,8 @@
|
||||
/******************************************************************************
|
||||
** Filename: intmatcher.c
|
||||
** Purpose: Generic high level classification routines.
|
||||
** Author: Robert Moss
|
||||
** History: Wed Feb 13 17:35:28 MST 1991, RWM, Created.
|
||||
** Mon Mar 11 16:33:02 MST 1991, RWM, Modified to add
|
||||
** support for adaptive matching.
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** Filename: intmatcher.cpp
|
||||
** Purpose: Generic high level classification routines.
|
||||
** Author: Robert Moss
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
@ -469,8 +466,6 @@ int Classify::PruneClasses(const INT_TEMPLATES_STRUCT* int_templates,
|
||||
* param Result Class rating & configuration: (0.0 -> 1.0), 0=bad, 1=good
|
||||
* param Debug Debugger flag: 1=debugger on
|
||||
* @return none
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Feb 19 16:36:23 MST 1991, RWM, Created.
|
||||
*/
|
||||
void IntegerMatcher::Match(INT_CLASS ClassTemplate,
|
||||
BIT_VECTOR ProtoMask,
|
||||
@ -550,8 +545,6 @@ void IntegerMatcher::Match(INT_CLASS ClassTemplate,
|
||||
* param AdaptProtoThreshold Threshold for good protos
|
||||
* param Debug Debugger flag: 1=debugger on
|
||||
* @return Number of good protos in ProtoArray.
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Mar 12 17:09:26 MST 1991, RWM, Created
|
||||
*/
|
||||
int IntegerMatcher::FindGoodProtos(
|
||||
INT_CLASS ClassTemplate,
|
||||
@ -621,7 +614,6 @@ int IntegerMatcher::FindGoodProtos(
|
||||
* @param AdaptFeatureThreshold Threshold for bad features
|
||||
* @param Debug Debugger flag: 1=debugger on
|
||||
* @return Number of bad features in FeatureArray.
|
||||
* @note History: Tue Mar 12 17:09:26 MST 1991, RWM, Created
|
||||
*/
|
||||
int IntegerMatcher::FindBadFeatures(
|
||||
INT_CLASS ClassTemplate,
|
||||
@ -720,8 +712,6 @@ void ScratchEvidence::ClearFeatureEvidence(const INT_CLASS class_template) {
|
||||
/**
|
||||
* Print debugging information for Configurations
|
||||
* @return none
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed Feb 27 14:12:28 MST 1991, RWM, Created.
|
||||
*/
|
||||
void IMDebugConfiguration(int FeatureNum,
|
||||
uint16_t ActualProtoNum,
|
||||
@ -743,8 +733,6 @@ void IMDebugConfiguration(int FeatureNum,
|
||||
/**
|
||||
* Print debugging information for Configurations
|
||||
* @return none
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed Feb 27 14:12:28 MST 1991, RWM, Created.
|
||||
*/
|
||||
void IMDebugConfigurationSum(int FeatureNum,
|
||||
uint8_t *FeatureEvidence,
|
||||
@ -916,8 +904,6 @@ int IntegerMatcher::UpdateTablesForFeature(
|
||||
/**
|
||||
* Print debugging information for Configurations
|
||||
* @return none
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed Feb 27 14:12:28 MST 1991, RWM, Created.
|
||||
*/
|
||||
#ifndef GRAPHICS_DISABLED
|
||||
void IntegerMatcher::DebugFeatureProtoError(
|
||||
@ -927,7 +913,7 @@ void IntegerMatcher::DebugFeatureProtoError(
|
||||
const ScratchEvidence& tables,
|
||||
int16_t NumFeatures,
|
||||
int Debug) {
|
||||
FLOAT32 ProtoConfigs[MAX_NUM_CONFIGS];
|
||||
float ProtoConfigs[MAX_NUM_CONFIGS];
|
||||
int ConfigNum;
|
||||
uint32_t ConfigWord;
|
||||
int ProtoSetIndex;
|
||||
@ -946,8 +932,7 @@ void IntegerMatcher::DebugFeatureProtoError(
|
||||
for (ConfigNum = 0; ConfigNum < ClassTemplate->NumConfigs; ConfigNum++) {
|
||||
cprintf(
|
||||
" %5.1f",
|
||||
100.0 * (1.0 -
|
||||
(FLOAT32) tables.sum_feature_evidence_[ConfigNum]
|
||||
100.0 * (1.0 - (float)tables.sum_feature_evidence_[ConfigNum]
|
||||
/ NumFeatures / 256.0));
|
||||
}
|
||||
cprintf("\n\n\n");
|
||||
@ -1178,8 +1163,6 @@ void ScratchEvidence::NormalizeSums(
|
||||
* Find the best match for the current class and update the Result
|
||||
* with the configuration and match rating.
|
||||
* @return The best normalized sum of evidences
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed Feb 27 14:12:28 MST 1991, RWM, Created.
|
||||
*/
|
||||
int IntegerMatcher::FindBestMatch(
|
||||
INT_CLASS class_template,
|
||||
@ -1228,8 +1211,6 @@ float IntegerMatcher::ApplyCNCorrection(float rating, int blob_length,
|
||||
* @param ra Key array [1..n]
|
||||
* @param rb Index array [1..n]
|
||||
* @return none
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Feb 19 10:24:24 MST 1991, RWM, Created.
|
||||
*/
|
||||
void
|
||||
HeapSort (int n, int ra[], int rb[]) {
|
||||
|
@ -45,7 +45,7 @@ struct UnicharRating;
|
||||
struct CP_RESULT_STRUCT {
|
||||
CP_RESULT_STRUCT() : Rating(0.0f), Class(0) {}
|
||||
|
||||
FLOAT32 Rating;
|
||||
float Rating;
|
||||
CLASS_ID Class;
|
||||
};
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
#endif
|
||||
|
||||
#include "classify.h"
|
||||
#include "const.h"
|
||||
#include "callcpp.h" // for cprintf
|
||||
#include "emalloc.h"
|
||||
#include "fontinfo.h"
|
||||
#include "genericvector.h"
|
||||
@ -125,9 +125,9 @@ FILL_SPEC;
|
||||
/*---------------------------------------------------------------------------
|
||||
Private Function Prototypes
|
||||
----------------------------------------------------------------------------*/
|
||||
FLOAT32 BucketStart(int Bucket, FLOAT32 Offset, int NumBuckets);
|
||||
float BucketStart(int Bucket, float Offset, int NumBuckets);
|
||||
|
||||
FLOAT32 BucketEnd(int Bucket, FLOAT32 Offset, int NumBuckets);
|
||||
float BucketEnd(int Bucket, float Offset, int NumBuckets);
|
||||
|
||||
void DoFill(FILL_SPEC *FillSpec,
|
||||
CLASS_PRUNER_STRUCT* Pruner,
|
||||
@ -139,23 +139,23 @@ bool FillerDone(TABLE_FILLER* Filler);
|
||||
|
||||
void FillPPCircularBits(uint32_t
|
||||
ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR],
|
||||
int Bit, FLOAT32 Center, FLOAT32 Spread, bool debug);
|
||||
int Bit, float Center, float Spread, bool debug);
|
||||
|
||||
void FillPPLinearBits(uint32_t ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR],
|
||||
int Bit, FLOAT32 Center, FLOAT32 Spread, bool debug);
|
||||
int Bit, float Center, float Spread, bool debug);
|
||||
|
||||
void GetCPPadsForLevel(int Level,
|
||||
FLOAT32 *EndPad,
|
||||
FLOAT32 *SidePad,
|
||||
FLOAT32 *AnglePad);
|
||||
float *EndPad,
|
||||
float *SidePad,
|
||||
float *AnglePad);
|
||||
|
||||
ScrollView::Color GetMatchColorFor(FLOAT32 Evidence);
|
||||
ScrollView::Color GetMatchColorFor(float Evidence);
|
||||
|
||||
void GetNextFill(TABLE_FILLER *Filler, FILL_SPEC *Fill);
|
||||
|
||||
void InitTableFiller(FLOAT32 EndPad,
|
||||
FLOAT32 SidePad,
|
||||
FLOAT32 AnglePad,
|
||||
void InitTableFiller(float EndPad,
|
||||
float SidePad,
|
||||
float AnglePad,
|
||||
PROTO Proto,
|
||||
TABLE_FILLER *Filler);
|
||||
|
||||
@ -169,7 +169,7 @@ void RenderIntProto(ScrollView *window,
|
||||
ScrollView::Color color);
|
||||
#endif // GRAPHICS_DISABLED
|
||||
|
||||
int TruncateParam(FLOAT32 Param, int Min, int Max, char *Id);
|
||||
int TruncateParam(float Param, int Min, int Max, char *Id);
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
Global Data Definitions and Declarations
|
||||
@ -231,9 +231,6 @@ INT_FEATURE_STRUCT::INT_FEATURE_STRUCT(int x, int y, int theta)
|
||||
* @param Class class data structure to add to templates
|
||||
*
|
||||
* Globals: none
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Mon Feb 11 11:52:08 1991, DSJ, Created.
|
||||
*/
|
||||
void AddIntClass(INT_TEMPLATES Templates, CLASS_ID ClassId, INT_CLASS Class) {
|
||||
int Pruner;
|
||||
@ -264,8 +261,6 @@ void AddIntClass(INT_TEMPLATES Templates, CLASS_ID ClassId, INT_CLASS Class) {
|
||||
* Globals: none
|
||||
*
|
||||
* @return Index of next free config.
|
||||
* @note Exceptions: none
|
||||
* @note History: Mon Feb 11 14:44:40 1991, DSJ, Created.
|
||||
*/
|
||||
int AddIntConfig(INT_CLASS Class) {
|
||||
int Index;
|
||||
@ -287,8 +282,6 @@ int AddIntConfig(INT_CLASS Class) {
|
||||
* Globals: none
|
||||
*
|
||||
* @return Proto index of new proto.
|
||||
* @note Exceptions: none
|
||||
* @note History: Mon Feb 11 13:26:41 1991, DSJ, Created.
|
||||
*/
|
||||
int AddIntProto(INT_CLASS Class) {
|
||||
int Index;
|
||||
@ -336,8 +329,6 @@ int AddIntProto(INT_CLASS Class) {
|
||||
* @param ClassId class id corresponding to Proto
|
||||
* @param Templates set of templates containing class pruner
|
||||
* @return none
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed Feb 13 08:49:54 1991, DSJ, Created.
|
||||
*/
|
||||
void AddProtoToClassPruner (PROTO Proto, CLASS_ID ClassId,
|
||||
INT_TEMPLATES Templates)
|
||||
@ -348,7 +339,7 @@ void AddProtoToClassPruner (PROTO Proto, CLASS_ID ClassId,
|
||||
uint32_t ClassCount;
|
||||
uint32_t WordIndex;
|
||||
int Level;
|
||||
FLOAT32 EndPad, SidePad, AnglePad;
|
||||
float EndPad, SidePad, AnglePad;
|
||||
TABLE_FILLER TableFiller;
|
||||
FILL_SPEC FillSpec;
|
||||
|
||||
@ -378,13 +369,11 @@ void AddProtoToClassPruner (PROTO Proto, CLASS_ID ClassId,
|
||||
* @param debug debug flag
|
||||
* @note Globals: none
|
||||
* @return none
|
||||
* @note Exceptions: none
|
||||
* @note History: Fri Feb 8 13:07:19 1991, DSJ, Created.
|
||||
*/
|
||||
void AddProtoToProtoPruner(PROTO Proto, int ProtoId,
|
||||
INT_CLASS Class, bool debug) {
|
||||
FLOAT32 Angle, X, Y, Length;
|
||||
FLOAT32 Pad;
|
||||
float Angle, X, Y, Length;
|
||||
float Pad;
|
||||
int Index;
|
||||
PROTO_SET ProtoSet;
|
||||
|
||||
@ -405,7 +394,7 @@ void AddProtoToProtoPruner(PROTO Proto, int ProtoId,
|
||||
Angle + ANGLE_SHIFT, classify_pp_angle_pad / 360.0,
|
||||
debug);
|
||||
|
||||
Angle *= 2.0 * PI;
|
||||
Angle *= 2.0 * M_PI;
|
||||
Length = Proto->Length;
|
||||
|
||||
X = Proto->X + X_SHIFT;
|
||||
@ -432,11 +421,11 @@ void AddProtoToProtoPruner(PROTO Proto, int ProtoId,
|
||||
* notionally (param + offset) * num_buckets, but clipped and casted to the
|
||||
* appropriate type.
|
||||
*/
|
||||
uint8_t Bucket8For(FLOAT32 param, FLOAT32 offset, int num_buckets) {
|
||||
uint8_t Bucket8For(float param, float offset, int num_buckets) {
|
||||
int bucket = IntCastRounded(MapParam(param, offset, num_buckets));
|
||||
return static_cast<uint8_t>(ClipToRange<int>(bucket, 0, num_buckets - 1));
|
||||
}
|
||||
uint16_t Bucket16For(FLOAT32 param, FLOAT32 offset, int num_buckets) {
|
||||
uint16_t Bucket16For(float param, float offset, int num_buckets) {
|
||||
int bucket = IntCastRounded(MapParam(param, offset, num_buckets));
|
||||
return static_cast<uint16_t>(ClipToRange<int>(bucket, 0, num_buckets - 1));
|
||||
}
|
||||
@ -446,7 +435,7 @@ uint16_t Bucket16For(FLOAT32 param, FLOAT32 offset, int num_buckets) {
|
||||
* notionally (param + offset) * num_buckets, but modded and casted to the
|
||||
* appropriate type.
|
||||
*/
|
||||
uint8_t CircBucketFor(FLOAT32 param, FLOAT32 offset, int num_buckets) {
|
||||
uint8_t CircBucketFor(float param, float offset, int num_buckets) {
|
||||
int bucket = IntCastRounded(MapParam(param, offset, num_buckets));
|
||||
return static_cast<uint8_t>(Modulo(bucket, num_buckets));
|
||||
} /* CircBucketFor */
|
||||
@ -461,8 +450,6 @@ uint8_t CircBucketFor(FLOAT32 param, FLOAT32 offset, int num_buckets) {
|
||||
* - FeatureShapes display list for features
|
||||
* - ProtoShapes display list for protos
|
||||
* @return none
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Mar 21 15:40:19 1991, DSJ, Created.
|
||||
*/
|
||||
void UpdateMatchDisplay() {
|
||||
if (IntMatchWindow != nullptr)
|
||||
@ -481,8 +468,6 @@ void UpdateMatchDisplay() {
|
||||
* @param Class class to add new config to
|
||||
* @return none
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Mon Feb 11 14:57:31 1991, DSJ, Created.
|
||||
*/
|
||||
void ConvertConfig(BIT_VECTOR Config, int ConfigId, INT_CLASS Class) {
|
||||
int ProtoId;
|
||||
@ -510,12 +495,10 @@ namespace tesseract {
|
||||
* @param Class integer class to add converted proto to
|
||||
* @return none
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Fri Feb 8 11:22:43 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::ConvertProto(PROTO Proto, int ProtoId, INT_CLASS Class) {
|
||||
INT_PROTO P;
|
||||
FLOAT32 Param;
|
||||
float Param;
|
||||
|
||||
assert(ProtoId < Class->NumProtos);
|
||||
|
||||
@ -551,8 +534,6 @@ void Classify::ConvertProto(PROTO Proto, int ProtoId, INT_CLASS Class) {
|
||||
* @param target_unicharset the UNICHARSET to use
|
||||
* @return New set of training templates in integer format.
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Feb 7 14:40:42 1991, DSJ, Created.
|
||||
*/
|
||||
INT_TEMPLATES Classify::CreateIntTemplates(CLASSES FloatProtos,
|
||||
const UNICHARSET&
|
||||
@ -617,10 +598,8 @@ INT_TEMPLATES Classify::CreateIntTemplates(CLASSES FloatProtos,
|
||||
* @param Feature pico-feature to be displayed
|
||||
* @param Evidence best evidence for this feature (0-1)
|
||||
* @return none
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Mar 21 14:45:04 1991, DSJ, Created.
|
||||
*/
|
||||
void DisplayIntFeature(const INT_FEATURE_STRUCT *Feature, FLOAT32 Evidence) {
|
||||
void DisplayIntFeature(const INT_FEATURE_STRUCT *Feature, float Evidence) {
|
||||
ScrollView::Color color = GetMatchColorFor(Evidence);
|
||||
RenderIntFeature(IntMatchWindow, Feature, color);
|
||||
if (FeatureDisplayWindow) {
|
||||
@ -638,10 +617,8 @@ void DisplayIntFeature(const INT_FEATURE_STRUCT *Feature, FLOAT32 Evidence) {
|
||||
* @param ProtoId id of proto in Class to be displayed
|
||||
* @param Evidence total evidence for proto (0-1)
|
||||
* @return none
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Mar 21 14:45:04 1991, DSJ, Created.
|
||||
*/
|
||||
void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, FLOAT32 Evidence) {
|
||||
void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, float Evidence) {
|
||||
ScrollView::Color color = GetMatchColorFor(Evidence);
|
||||
RenderIntProto(IntMatchWindow, Class, ProtoId, color);
|
||||
if (ProtoDisplayWindow) {
|
||||
@ -658,8 +635,6 @@ void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, FLOAT32 Evidence) {
|
||||
* @param MaxNumConfigs number of configs to allocate space for
|
||||
* @return New class created.
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Fri Feb 8 10:51:23 1991, DSJ, Created.
|
||||
*/
|
||||
INT_CLASS NewIntClass(int MaxNumProtos, int MaxNumConfigs) {
|
||||
INT_CLASS Class;
|
||||
@ -717,8 +692,6 @@ void free_int_class(INT_CLASS int_class) {
|
||||
* initialized to hold 0 classes.
|
||||
* @return The integer templates created.
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Fri Feb 8 08:38:51 1991, DSJ, Created.
|
||||
*/
|
||||
INT_TEMPLATES NewIntTemplates() {
|
||||
INT_TEMPLATES T;
|
||||
@ -755,8 +728,6 @@ namespace tesseract {
|
||||
* @param fp open file to read templates from
|
||||
* @return Pointer to integer templates read from File.
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed Feb 27 11:48:46 1991, DSJ, Created.
|
||||
*/
|
||||
INT_TEMPLATES Classify::ReadIntTemplates(TFile *fp) {
|
||||
int i, j, w, x, y, z;
|
||||
@ -1002,8 +973,6 @@ INT_TEMPLATES Classify::ReadIntTemplates(TFile *fp) {
|
||||
* - FeatureShapes display list containing feature matches
|
||||
* - ProtoShapes display list containing proto matches
|
||||
* @return none
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Mar 21 15:47:33 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::ShowMatchDisplay() {
|
||||
InitIntMatchWindowIfReqd();
|
||||
@ -1061,8 +1030,6 @@ void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView* window) {
|
||||
* @param target_unicharset the UNICHARSET to use
|
||||
* @return none
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed Feb 27 11:48:46 1991, DSJ, Created.
|
||||
*/
|
||||
void Classify::WriteIntTemplates(FILE *File, INT_TEMPLATES Templates,
|
||||
const UNICHARSET& target_unicharset) {
|
||||
@ -1139,11 +1106,9 @@ void Classify::WriteIntTemplates(FILE *File, INT_TEMPLATES Templates,
|
||||
* @param NumBuckets total number of buckets
|
||||
* @return Param value corresponding to start position of Bucket.
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Feb 14 13:24:33 1991, DSJ, Created.
|
||||
*/
|
||||
FLOAT32 BucketStart(int Bucket, FLOAT32 Offset, int NumBuckets) {
|
||||
return (((FLOAT32) Bucket / NumBuckets) - Offset);
|
||||
float BucketStart(int Bucket, float Offset, int NumBuckets) {
|
||||
return (((float) Bucket / NumBuckets) - Offset);
|
||||
|
||||
} /* BucketStart */
|
||||
|
||||
@ -1157,11 +1122,9 @@ FLOAT32 BucketStart(int Bucket, FLOAT32 Offset, int NumBuckets) {
|
||||
* @param NumBuckets total number of buckets
|
||||
* @return Param value corresponding to end position of Bucket.
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Feb 14 13:24:33 1991, DSJ, Created.
|
||||
*/
|
||||
FLOAT32 BucketEnd(int Bucket, FLOAT32 Offset, int NumBuckets) {
|
||||
return (((FLOAT32) (Bucket + 1) / NumBuckets) - Offset);
|
||||
float BucketEnd(int Bucket, float Offset, int NumBuckets) {
|
||||
return (((float) (Bucket + 1) / NumBuckets) - Offset);
|
||||
} /* BucketEnd */
|
||||
|
||||
/**
|
||||
@ -1175,8 +1138,6 @@ FLOAT32 BucketEnd(int Bucket, FLOAT32 Offset, int NumBuckets) {
|
||||
* @param WordIndex indicates which word to change
|
||||
* @return none
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Feb 19 11:11:29 1991, DSJ, Created.
|
||||
*/
|
||||
void DoFill(FILL_SPEC *FillSpec,
|
||||
CLASS_PRUNER_STRUCT* Pruner,
|
||||
@ -1217,8 +1178,6 @@ void DoFill(FILL_SPEC *FillSpec,
|
||||
* @param Filler table filler to check if done
|
||||
* @return TRUE if no more lines to fill, FALSE otherwise.
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Feb 19 10:08:05 1991, DSJ, Created.
|
||||
*/
|
||||
bool FillerDone(TABLE_FILLER* Filler) {
|
||||
FILL_SWITCH *Next;
|
||||
@ -1243,11 +1202,9 @@ bool FillerDone(TABLE_FILLER* Filler) {
|
||||
* @param debug debug flag
|
||||
* @return none
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Oct 16 09:26:54 1990, DSJ, Created.
|
||||
*/
|
||||
void FillPPCircularBits(uint32_t ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR],
|
||||
int Bit, FLOAT32 Center, FLOAT32 Spread, bool debug) {
|
||||
int Bit, float Center, float Spread, bool debug) {
|
||||
int i, FirstBucket, LastBucket;
|
||||
|
||||
if (Spread > 0.5)
|
||||
@ -1286,11 +1243,9 @@ void FillPPCircularBits(uint32_t ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR]
|
||||
* @param debug debug flag
|
||||
* @return none
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Oct 16 09:26:54 1990, DSJ, Created.
|
||||
*/
|
||||
void FillPPLinearBits(uint32_t ParamTable[NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR],
|
||||
int Bit, FLOAT32 Center, FLOAT32 Spread, bool debug) {
|
||||
int Bit, float Center, float Spread, bool debug) {
|
||||
int i, FirstBucket, LastBucket;
|
||||
|
||||
FirstBucket = (int) floor ((Center - Spread) * NUM_PP_BUCKETS);
|
||||
@ -1320,8 +1275,6 @@ namespace tesseract {
|
||||
* @param shape_id
|
||||
* @return Character entered in the debug window.
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Mar 21 16:55:13 1991, DSJ, Created.
|
||||
*/
|
||||
CLASS_ID Classify::GetClassToDebug(const char *Prompt, bool* adaptive_on,
|
||||
bool* pretrained_on, int* shape_id) {
|
||||
@ -1400,13 +1353,11 @@ CLASS_ID Classify::GetClassToDebug(const char *Prompt, bool* adaptive_on,
|
||||
* @param AnglePad place to put angle pad for Level
|
||||
* @return none (results are returned in EndPad, SidePad, and AnglePad.
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Feb 14 08:26:49 1991, DSJ, Created.
|
||||
*/
|
||||
void GetCPPadsForLevel(int Level,
|
||||
FLOAT32 *EndPad,
|
||||
FLOAT32 *SidePad,
|
||||
FLOAT32 *AnglePad) {
|
||||
float *EndPad,
|
||||
float *SidePad,
|
||||
float *AnglePad) {
|
||||
switch (Level) {
|
||||
case 0:
|
||||
*EndPad = classify_cp_end_pad_loose * GetPicoFeatureLength ();
|
||||
@ -1441,10 +1392,8 @@ void GetCPPadsForLevel(int Level,
|
||||
* @param Evidence evidence value to return color for
|
||||
* @return Color which corresponds to specified Evidence value.
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Mar 21 15:24:52 1991, DSJ, Created.
|
||||
*/
|
||||
ScrollView::Color GetMatchColorFor(FLOAT32 Evidence) {
|
||||
ScrollView::Color GetMatchColorFor(float Evidence) {
|
||||
assert (Evidence >= 0.0);
|
||||
assert (Evidence <= 1.0);
|
||||
|
||||
@ -1467,8 +1416,6 @@ ScrollView::Color GetMatchColorFor(FLOAT32 Evidence) {
|
||||
* @param Fill place to put spec for next fill
|
||||
* @return none (results are returned in Fill)
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Feb 19 10:17:42 1991, DSJ, Created.
|
||||
*/
|
||||
void GetNextFill(TABLE_FILLER *Filler, FILL_SPEC *Fill) {
|
||||
FILL_SWITCH *Next;
|
||||
@ -1519,20 +1466,18 @@ void GetNextFill(TABLE_FILLER *Filler, FILL_SPEC *Fill) {
|
||||
*
|
||||
* @return none (results are returned in Filler)
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Feb 14 09:27:05 1991, DSJ, Created.
|
||||
*/
|
||||
void InitTableFiller (FLOAT32 EndPad, FLOAT32 SidePad,
|
||||
FLOAT32 AnglePad, PROTO Proto, TABLE_FILLER * Filler)
|
||||
void InitTableFiller (float EndPad, float SidePad,
|
||||
float AnglePad, PROTO Proto, TABLE_FILLER * Filler)
|
||||
#define XS X_SHIFT
|
||||
#define YS Y_SHIFT
|
||||
#define AS ANGLE_SHIFT
|
||||
#define NB NUM_CP_BUCKETS
|
||||
{
|
||||
FLOAT32 Angle;
|
||||
FLOAT32 X, Y, HalfLength;
|
||||
FLOAT32 Cos, Sin;
|
||||
FLOAT32 XAdjust, YAdjust;
|
||||
float Angle;
|
||||
float X, Y, HalfLength;
|
||||
float Cos, Sin;
|
||||
float XAdjust, YAdjust;
|
||||
FPOINT Start, Switch1, Switch2, End;
|
||||
int S1 = 0;
|
||||
int S2 = 1;
|
||||
@ -1570,7 +1515,7 @@ void InitTableFiller (FLOAT32 EndPad, FLOAT32 SidePad,
|
||||
|
||||
if ((Angle > 0.0 && Angle < 0.25) || (Angle > 0.5 && Angle < 0.75)) {
|
||||
/* rising diagonal proto */
|
||||
Angle *= 2.0 * PI;
|
||||
Angle *= 2.0 * M_PI;
|
||||
Cos = fabs(cos(Angle));
|
||||
Sin = fabs(sin(Angle));
|
||||
|
||||
@ -1620,7 +1565,7 @@ void InitTableFiller (FLOAT32 EndPad, FLOAT32 SidePad,
|
||||
Filler->Switch[2].X = Bucket8For(End.x, XS, NB);
|
||||
} else {
|
||||
/* falling diagonal proto */
|
||||
Angle *= 2.0 * PI;
|
||||
Angle *= 2.0 * M_PI;
|
||||
Cos = fabs(cos(Angle));
|
||||
Sin = fabs(sin(Angle));
|
||||
|
||||
@ -1684,12 +1629,10 @@ void InitTableFiller (FLOAT32 EndPad, FLOAT32 SidePad,
|
||||
* @param color color to use for feature rendering
|
||||
* @return New shape list with rendering of Feature added.
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Mar 21 14:57:41 1991, DSJ, Created.
|
||||
*/
|
||||
void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT* Feature,
|
||||
ScrollView::Color color) {
|
||||
FLOAT32 X, Y, Dx, Dy, Length;
|
||||
float X, Y, Dx, Dy, Length;
|
||||
|
||||
window->Pen(color);
|
||||
assert(Feature != nullptr);
|
||||
@ -1700,8 +1643,8 @@ void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT* Feature,
|
||||
Length = GetPicoFeatureLength() * 0.7 * INT_CHAR_NORM_RANGE;
|
||||
// The -PI has no significant effect here, but the value of Theta is computed
|
||||
// using BinaryAnglePlusPi in intfx.cpp.
|
||||
Dx = (Length / 2.0) * cos((Feature->Theta / 256.0) * 2.0 * PI - PI);
|
||||
Dy = (Length / 2.0) * sin((Feature->Theta / 256.0) * 2.0 * PI - PI);
|
||||
Dx = (Length / 2.0) * cos((Feature->Theta / 256.0) * 2.0 * M_PI - M_PI);
|
||||
Dy = (Length / 2.0) * sin((Feature->Theta / 256.0) * 2.0 * M_PI - M_PI);
|
||||
|
||||
window->SetCursor(X, Y);
|
||||
window->DrawTo(X + Dx, Y + Dy);
|
||||
@ -1720,8 +1663,6 @@ void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT* Feature,
|
||||
* Globals: none
|
||||
*
|
||||
* @return New shape list with a rendering of one proto added.
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Mar 21 10:21:09 1991, DSJ, Created.
|
||||
*/
|
||||
void RenderIntProto(ScrollView *window,
|
||||
INT_CLASS Class,
|
||||
@ -1731,9 +1672,9 @@ void RenderIntProto(ScrollView *window,
|
||||
INT_PROTO Proto;
|
||||
int ProtoSetIndex;
|
||||
int ProtoWordIndex;
|
||||
FLOAT32 Length;
|
||||
float Length;
|
||||
int Xmin, Xmax, Ymin, Ymax;
|
||||
FLOAT32 X, Y, Dx, Dy;
|
||||
float X, Y, Dx, Dy;
|
||||
uint32_t ProtoMask;
|
||||
int Bucket;
|
||||
|
||||
@ -1767,8 +1708,8 @@ void RenderIntProto(ScrollView *window,
|
||||
Y = (Ymin + Ymax + 1) / 2.0 * PROTO_PRUNER_SCALE;
|
||||
// The -PI has no significant effect here, but the value of Theta is computed
|
||||
// using BinaryAnglePlusPi in intfx.cpp.
|
||||
Dx = (Length / 2.0) * cos((Proto->Angle / 256.0) * 2.0 * PI - PI);
|
||||
Dy = (Length / 2.0) * sin((Proto->Angle / 256.0) * 2.0 * PI - PI);
|
||||
Dx = (Length / 2.0) * cos((Proto->Angle / 256.0) * 2.0 * M_PI - M_PI);
|
||||
Dy = (Length / 2.0) * sin((Proto->Angle / 256.0) * 2.0 * M_PI - M_PI);
|
||||
|
||||
window->SetCursor(X - Dx, Y - Dy);
|
||||
window->DrawTo(X + Dx, Y + Dy);
|
||||
@ -1787,10 +1728,8 @@ void RenderIntProto(ScrollView *window,
|
||||
* Globals: none
|
||||
*
|
||||
* @return Truncated parameter.
|
||||
* @note Exceptions: none
|
||||
* @note History: Fri Feb 8 11:54:28 1991, DSJ, Created.
|
||||
*/
|
||||
int TruncateParam(FLOAT32 Param, int Min, int Max, char *Id) {
|
||||
int TruncateParam(float Param, int Min, int Max, char *Id) {
|
||||
if (Param < Min) {
|
||||
if (Id)
|
||||
cprintf("Warning: Param %s truncated from %f to %d!\n",
|
||||
|
@ -1,10 +1,10 @@
|
||||
/******************************************************************************
|
||||
** Filename: intproto.h
|
||||
** Purpose: Definition of data structures for integer protos.
|
||||
** Author: Dan Johnson
|
||||
** History: Thu Feb 7 12:58:45 1991, DSJ, Created.
|
||||
** Filename: intproto.h
|
||||
** Purpose: Definition of data structures for integer protos.
|
||||
** Author: Dan Johnson
|
||||
** History: Thu Feb 7 12:58:45 1991, DSJ, Created.
|
||||
**
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
@ -14,7 +14,8 @@
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
******************************************************************************/
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef INTPROTO_H
|
||||
#define INTPROTO_H
|
||||
|
||||
@ -31,42 +32,41 @@
|
||||
class FCOORD;
|
||||
|
||||
/* define order of params in pruners */
|
||||
#define PRUNER_X 0
|
||||
#define PRUNER_Y 1
|
||||
#define PRUNER_ANGLE 2
|
||||
#define PRUNER_X 0
|
||||
#define PRUNER_Y 1
|
||||
#define PRUNER_ANGLE 2
|
||||
|
||||
/* definition of coordinate system offsets for each table parameter */
|
||||
#define ANGLE_SHIFT (0.0)
|
||||
#define X_SHIFT (0.5)
|
||||
#define Y_SHIFT (0.5)
|
||||
#define X_SHIFT (0.5)
|
||||
#define Y_SHIFT (0.5)
|
||||
|
||||
#define MAX_PROTO_INDEX 24
|
||||
#define BITS_PER_WERD static_cast<int>(8 * sizeof(uint32_t))
|
||||
#define MAX_PROTO_INDEX 24
|
||||
#define BITS_PER_WERD static_cast<int>(8 * sizeof(uint32_t))
|
||||
/* Script detection: increase this number to 128 */
|
||||
#define MAX_NUM_CONFIGS 64
|
||||
#define MAX_NUM_PROTOS 512
|
||||
#define PROTOS_PER_PROTO_SET 64
|
||||
#define MAX_NUM_PROTO_SETS (MAX_NUM_PROTOS / PROTOS_PER_PROTO_SET)
|
||||
#define NUM_PP_PARAMS 3
|
||||
#define NUM_PP_BUCKETS 64
|
||||
#define NUM_CP_BUCKETS 24
|
||||
#define CLASSES_PER_CP 32
|
||||
#define NUM_BITS_PER_CLASS 2
|
||||
#define MAX_NUM_CONFIGS 64
|
||||
#define MAX_NUM_PROTOS 512
|
||||
#define PROTOS_PER_PROTO_SET 64
|
||||
#define MAX_NUM_PROTO_SETS (MAX_NUM_PROTOS / PROTOS_PER_PROTO_SET)
|
||||
#define NUM_PP_PARAMS 3
|
||||
#define NUM_PP_BUCKETS 64
|
||||
#define NUM_CP_BUCKETS 24
|
||||
#define CLASSES_PER_CP 32
|
||||
#define NUM_BITS_PER_CLASS 2
|
||||
#define CLASS_PRUNER_CLASS_MASK (~(~0u << NUM_BITS_PER_CLASS))
|
||||
#define CLASSES_PER_CP_WERD (CLASSES_PER_CP / NUM_BITS_PER_CLASS)
|
||||
#define PROTOS_PER_PP_WERD BITS_PER_WERD
|
||||
#define BITS_PER_CP_VECTOR (CLASSES_PER_CP * NUM_BITS_PER_CLASS)
|
||||
#define MAX_NUM_CLASS_PRUNERS ((MAX_NUM_CLASSES + CLASSES_PER_CP - 1) / \
|
||||
CLASSES_PER_CP)
|
||||
#define PROTOS_PER_PP_WERD BITS_PER_WERD
|
||||
#define BITS_PER_CP_VECTOR (CLASSES_PER_CP * NUM_BITS_PER_CLASS)
|
||||
#define MAX_NUM_CLASS_PRUNERS \
|
||||
((MAX_NUM_CLASSES + CLASSES_PER_CP - 1) / CLASSES_PER_CP)
|
||||
#define WERDS_PER_CP_VECTOR (BITS_PER_CP_VECTOR / BITS_PER_WERD)
|
||||
#define WERDS_PER_PP_VECTOR ((PROTOS_PER_PROTO_SET+BITS_PER_WERD-1)/ \
|
||||
BITS_PER_WERD)
|
||||
#define WERDS_PER_PP (NUM_PP_PARAMS * NUM_PP_BUCKETS * \
|
||||
WERDS_PER_PP_VECTOR)
|
||||
#define WERDS_PER_CP (NUM_CP_BUCKETS * NUM_CP_BUCKETS * \
|
||||
NUM_CP_BUCKETS * WERDS_PER_CP_VECTOR)
|
||||
#define WERDS_PER_CONFIG_VEC ((MAX_NUM_CONFIGS + BITS_PER_WERD - 1) / \
|
||||
BITS_PER_WERD)
|
||||
#define WERDS_PER_PP_VECTOR \
|
||||
((PROTOS_PER_PROTO_SET + BITS_PER_WERD - 1) / BITS_PER_WERD)
|
||||
#define WERDS_PER_PP (NUM_PP_PARAMS * NUM_PP_BUCKETS * WERDS_PER_PP_VECTOR)
|
||||
#define WERDS_PER_CP \
|
||||
(NUM_CP_BUCKETS * NUM_CP_BUCKETS * NUM_CP_BUCKETS * WERDS_PER_CP_VECTOR)
|
||||
#define WERDS_PER_CONFIG_VEC \
|
||||
((MAX_NUM_CONFIGS + BITS_PER_WERD - 1) / BITS_PER_WERD)
|
||||
|
||||
/* The first 3 dimensions of the CLASS_PRUNER_STRUCT are the
|
||||
* 3 axes of the quantized feature space.
|
||||
@ -74,11 +74,11 @@ class FCOORD;
|
||||
* 4th dimension is determined by using CPrunerWordIndexFor(c),
|
||||
* where c is the corresponding class id. */
|
||||
struct CLASS_PRUNER_STRUCT {
|
||||
uint32_t p[NUM_CP_BUCKETS][NUM_CP_BUCKETS][NUM_CP_BUCKETS][WERDS_PER_CP_VECTOR];
|
||||
uint32_t p[NUM_CP_BUCKETS][NUM_CP_BUCKETS][NUM_CP_BUCKETS]
|
||||
[WERDS_PER_CP_VECTOR];
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
int8_t A;
|
||||
uint8_t B;
|
||||
int8_t C;
|
||||
@ -86,54 +86,51 @@ typedef struct
|
||||
uint32_t Configs[WERDS_PER_CONFIG_VEC];
|
||||
}
|
||||
|
||||
INT_PROTO_STRUCT,
|
||||
*INT_PROTO;
|
||||
|
||||
INT_PROTO_STRUCT, *INT_PROTO;
|
||||
typedef uint32_t PROTO_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS]
|
||||
[WERDS_PER_PP_VECTOR];
|
||||
|
||||
typedef uint32_t PROTO_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][WERDS_PER_PP_VECTOR];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
PROTO_PRUNER ProtoPruner;
|
||||
INT_PROTO_STRUCT Protos[PROTOS_PER_PROTO_SET];
|
||||
}
|
||||
|
||||
|
||||
PROTO_SET_STRUCT, *PROTO_SET;
|
||||
PROTO_SET_STRUCT,
|
||||
*PROTO_SET;
|
||||
|
||||
typedef uint32_t CONFIG_PRUNER[NUM_PP_PARAMS][NUM_PP_BUCKETS][4];
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
uint16_t NumProtos;
|
||||
uint8_t NumProtoSets;
|
||||
uint8_t NumConfigs;
|
||||
PROTO_SET ProtoSets[MAX_NUM_PROTO_SETS];
|
||||
uint8_t *ProtoLengths;
|
||||
uint8_t* ProtoLengths;
|
||||
uint16_t ConfigLengths[MAX_NUM_CONFIGS];
|
||||
int font_set_id; // FontSet id, see above
|
||||
}
|
||||
|
||||
INT_CLASS_STRUCT,
|
||||
*INT_CLASS;
|
||||
|
||||
INT_CLASS_STRUCT, *INT_CLASS;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
int NumClasses;
|
||||
int NumClassPruners;
|
||||
INT_CLASS Class[MAX_NUM_CLASSES];
|
||||
CLASS_PRUNER_STRUCT* ClassPruners[MAX_NUM_CLASS_PRUNERS];
|
||||
}
|
||||
|
||||
|
||||
INT_TEMPLATES_STRUCT, *INT_TEMPLATES;
|
||||
INT_TEMPLATES_STRUCT,
|
||||
*INT_TEMPLATES;
|
||||
|
||||
/* definitions of integer features*/
|
||||
#define MAX_NUM_INT_FEATURES 512
|
||||
#define INT_CHAR_NORM_RANGE 256
|
||||
#define INT_CHAR_NORM_RANGE 256
|
||||
|
||||
struct INT_FEATURE_STRUCT {
|
||||
INT_FEATURE_STRUCT() : X(0), Y(0), Theta(0), CP_misses(0) { }
|
||||
INT_FEATURE_STRUCT() : X(0), Y(0), Theta(0), CP_misses(0) {}
|
||||
// Builds a feature from an FCOORD for position with all the necessary
|
||||
// clipping and rounding.
|
||||
INT_FEATURE_STRUCT(const FCOORD& pos, uint8_t theta);
|
||||
@ -145,12 +142,10 @@ struct INT_FEATURE_STRUCT {
|
||||
uint8_t Theta;
|
||||
int8_t CP_misses;
|
||||
|
||||
void print() const {
|
||||
tprintf("(%d,%d):%d\n", X, Y, Theta);
|
||||
}
|
||||
void print() const { tprintf("(%d,%d):%d\n", X, Y, Theta); }
|
||||
};
|
||||
|
||||
typedef INT_FEATURE_STRUCT *INT_FEATURE;
|
||||
typedef INT_FEATURE_STRUCT* INT_FEATURE;
|
||||
|
||||
typedef INT_FEATURE_STRUCT INT_FEATURE_ARRAY[MAX_NUM_INT_FEATURES];
|
||||
|
||||
@ -165,26 +160,27 @@ enum IntmatcherDebugAction {
|
||||
Macros
|
||||
----------------------------------------------------------------------------**/
|
||||
|
||||
#define MaxNumIntProtosIn(C) (C->NumProtoSets * PROTOS_PER_PROTO_SET)
|
||||
#define SetForProto(P) (P / PROTOS_PER_PROTO_SET)
|
||||
#define IndexForProto(P) (P % PROTOS_PER_PROTO_SET)
|
||||
#define ProtoForProtoId(C,P) (&((C->ProtoSets[SetForProto (P)])-> \
|
||||
Protos [IndexForProto (P)]))
|
||||
#define PPrunerWordIndexFor(I) (((I) % PROTOS_PER_PROTO_SET) / \
|
||||
PROTOS_PER_PP_WERD)
|
||||
#define MaxNumIntProtosIn(C) (C->NumProtoSets * PROTOS_PER_PROTO_SET)
|
||||
#define SetForProto(P) (P / PROTOS_PER_PROTO_SET)
|
||||
#define IndexForProto(P) (P % PROTOS_PER_PROTO_SET)
|
||||
#define ProtoForProtoId(C, P) \
|
||||
(&((C->ProtoSets[SetForProto(P)])->Protos[IndexForProto(P)]))
|
||||
#define PPrunerWordIndexFor(I) \
|
||||
(((I) % PROTOS_PER_PROTO_SET) / PROTOS_PER_PP_WERD)
|
||||
#define PPrunerBitIndexFor(I) ((I) % PROTOS_PER_PP_WERD)
|
||||
#define PPrunerMaskFor(I) (1 << PPrunerBitIndexFor (I))
|
||||
#define PPrunerMaskFor(I) (1 << PPrunerBitIndexFor(I))
|
||||
|
||||
#define MaxNumClassesIn(T) (T->NumClassPruners * CLASSES_PER_CP)
|
||||
#define LegalClassId(c) ((c) >= 0 && (c) <= MAX_CLASS_ID)
|
||||
#define UnusedClassIdIn(T,c) ((T)->Class[c] == nullptr)
|
||||
#define ClassForClassId(T,c) ((T)->Class[c])
|
||||
#define ClassPrunersFor(T) ((T)->ClassPruner)
|
||||
#define CPrunerIdFor(c) ((c) / CLASSES_PER_CP)
|
||||
#define CPrunerFor(T,c) ((T)->ClassPruners[CPrunerIdFor(c)])
|
||||
#define CPrunerWordIndexFor(c) (((c) % CLASSES_PER_CP) / CLASSES_PER_CP_WERD)
|
||||
#define MaxNumClassesIn(T) (T->NumClassPruners * CLASSES_PER_CP)
|
||||
#define LegalClassId(c) ((c) >= 0 && (c) <= MAX_CLASS_ID)
|
||||
#define UnusedClassIdIn(T, c) ((T)->Class[c] == nullptr)
|
||||
#define ClassForClassId(T, c) ((T)->Class[c])
|
||||
#define ClassPrunersFor(T) ((T)->ClassPruner)
|
||||
#define CPrunerIdFor(c) ((c) / CLASSES_PER_CP)
|
||||
#define CPrunerFor(T, c) ((T)->ClassPruners[CPrunerIdFor(c)])
|
||||
#define CPrunerWordIndexFor(c) (((c) % CLASSES_PER_CP) / CLASSES_PER_CP_WERD)
|
||||
#define CPrunerBitIndexFor(c) (((c) % CLASSES_PER_CP) % CLASSES_PER_CP_WERD)
|
||||
#define CPrunerMaskFor(L,c) (((L)+1) << CPrunerBitIndexFor (c) * NUM_BITS_PER_CLASS)
|
||||
#define CPrunerMaskFor(L, c) \
|
||||
(((L) + 1) << CPrunerBitIndexFor(c) * NUM_BITS_PER_CLASS)
|
||||
|
||||
/* DEBUG macros*/
|
||||
#define PRINT_MATCH_SUMMARY 0x001
|
||||
@ -194,13 +190,13 @@ enum IntmatcherDebugAction {
|
||||
#define PRINT_PROTO_MATCHES 0x010
|
||||
#define CLIP_MATCH_EVIDENCE 0x020
|
||||
|
||||
#define MatchDebuggingOn(D) (D)
|
||||
#define PrintMatchSummaryOn(D) ((D) & PRINT_MATCH_SUMMARY)
|
||||
#define DisplayFeatureMatchesOn(D) ((D) & DISPLAY_FEATURE_MATCHES)
|
||||
#define DisplayProtoMatchesOn(D) ((D) & DISPLAY_PROTO_MATCHES)
|
||||
#define PrintFeatureMatchesOn(D) ((D) & PRINT_FEATURE_MATCHES)
|
||||
#define PrintProtoMatchesOn(D) ((D) & PRINT_PROTO_MATCHES)
|
||||
#define ClipMatchEvidenceOn(D) ((D) & CLIP_MATCH_EVIDENCE)
|
||||
#define MatchDebuggingOn(D) (D)
|
||||
#define PrintMatchSummaryOn(D) ((D)&PRINT_MATCH_SUMMARY)
|
||||
#define DisplayFeatureMatchesOn(D) ((D)&DISPLAY_FEATURE_MATCHES)
|
||||
#define DisplayProtoMatchesOn(D) ((D)&DISPLAY_PROTO_MATCHES)
|
||||
#define PrintFeatureMatchesOn(D) ((D)&PRINT_FEATURE_MATCHES)
|
||||
#define PrintProtoMatchesOn(D) ((D)&PRINT_PROTO_MATCHES)
|
||||
#define ClipMatchEvidenceOn(D) ((D)&CLIP_MATCH_EVIDENCE)
|
||||
|
||||
/**----------------------------------------------------------------------------
|
||||
Public Function Prototypes
|
||||
@ -211,25 +207,24 @@ int AddIntConfig(INT_CLASS Class);
|
||||
|
||||
int AddIntProto(INT_CLASS Class);
|
||||
|
||||
void AddProtoToClassPruner(PROTO Proto,
|
||||
CLASS_ID ClassId,
|
||||
void AddProtoToClassPruner(PROTO Proto, CLASS_ID ClassId,
|
||||
INT_TEMPLATES Templates);
|
||||
|
||||
void AddProtoToProtoPruner(PROTO Proto, int ProtoId,
|
||||
INT_CLASS Class, bool debug);
|
||||
void AddProtoToProtoPruner(PROTO Proto, int ProtoId, INT_CLASS Class,
|
||||
bool debug);
|
||||
|
||||
uint8_t Bucket8For(FLOAT32 param, FLOAT32 offset, int num_buckets);
|
||||
uint16_t Bucket16For(FLOAT32 param, FLOAT32 offset, int num_buckets);
|
||||
uint8_t Bucket8For(float param, float offset, int num_buckets);
|
||||
uint16_t Bucket16For(float param, float offset, int num_buckets);
|
||||
|
||||
uint8_t CircBucketFor(FLOAT32 param, FLOAT32 offset, int num_buckets);
|
||||
uint8_t CircBucketFor(float param, float offset, int num_buckets);
|
||||
|
||||
void UpdateMatchDisplay();
|
||||
|
||||
void ConvertConfig(BIT_VECTOR Config, int ConfigId, INT_CLASS Class);
|
||||
|
||||
void DisplayIntFeature(const INT_FEATURE_STRUCT* Feature, FLOAT32 Evidence);
|
||||
void DisplayIntFeature(const INT_FEATURE_STRUCT* Feature, float Evidence);
|
||||
|
||||
void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, FLOAT32 Evidence);
|
||||
void DisplayIntProto(INT_CLASS Class, PROTO_ID ProtoId, float Evidence);
|
||||
|
||||
INT_CLASS NewIntClass(int MaxNumProtos, int MaxNumConfigs);
|
||||
|
||||
@ -249,7 +244,7 @@ void ClearFeatureSpaceWindow(NORM_METHOD norm_method, ScrollView* window);
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
#ifndef GRAPHICS_DISABLED
|
||||
void RenderIntFeature(ScrollView *window, const INT_FEATURE_STRUCT* Feature,
|
||||
void RenderIntFeature(ScrollView* window, const INT_FEATURE_STRUCT* Feature,
|
||||
ScrollView::Color color);
|
||||
|
||||
void InitIntMatchWindowIfReqd();
|
||||
|
@ -2,9 +2,6 @@
|
||||
** Filename: kdtree.cpp
|
||||
** Purpose: Routines for managing K-D search trees
|
||||
** Author: Dan Johnson
|
||||
** History: 3/10/89, DSJ, Created.
|
||||
** 5/23/89, DSJ, Added circular feature capability.
|
||||
** 7/13/89, DSJ, Made tree nodes invisible to outside.
|
||||
**
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -22,10 +19,11 @@
|
||||
Include Files and Type Defines
|
||||
-----------------------------------------------------------------------------*/
|
||||
#include "kdtree.h"
|
||||
#include "const.h"
|
||||
#include "cutil.h" // for void_proc
|
||||
#include "emalloc.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cfloat> // for FLT_MAX
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
|
||||
@ -35,8 +33,8 @@
|
||||
/*-----------------------------------------------------------------------------
|
||||
Global Data Definitions and Declarations
|
||||
-----------------------------------------------------------------------------*/
|
||||
#define MINSEARCH -MAX_FLOAT32
|
||||
#define MAXSEARCH MAX_FLOAT32
|
||||
#define MINSEARCH -FLT_MAX
|
||||
#define MAXSEARCH FLT_MAX
|
||||
|
||||
// Helper function to find the next essential dimension in a cycle.
|
||||
static int NextLevel(KDTREE *tree, int level) {
|
||||
@ -122,27 +120,27 @@ bool MinK<Key, Value>::insert(Key key, Value value) {
|
||||
*/
|
||||
class KDTreeSearch {
|
||||
public:
|
||||
KDTreeSearch(KDTREE* tree, FLOAT32 *query_point, int k_closest);
|
||||
KDTreeSearch(KDTREE* tree, float *query_point, int k_closest);
|
||||
~KDTreeSearch();
|
||||
|
||||
/** Return the k nearest points' data. */
|
||||
void Search(int *result_count, FLOAT32 *distances, void **results);
|
||||
void Search(int *result_count, float *distances, void **results);
|
||||
|
||||
private:
|
||||
void SearchRec(int Level, KDNODE *SubTree);
|
||||
bool BoxIntersectsSearch(FLOAT32 *lower, FLOAT32 *upper);
|
||||
bool BoxIntersectsSearch(float *lower, float *upper);
|
||||
|
||||
KDTREE *tree_;
|
||||
FLOAT32 *query_point_;
|
||||
FLOAT32 *sb_min_; //< search box minimum
|
||||
FLOAT32 *sb_max_; //< search box maximum
|
||||
MinK<FLOAT32, void *> results_;
|
||||
float *query_point_;
|
||||
float *sb_min_; //< search box minimum
|
||||
float *sb_max_; //< search box maximum
|
||||
MinK<float, void *> results_;
|
||||
};
|
||||
|
||||
KDTreeSearch::KDTreeSearch(KDTREE *tree, FLOAT32 *query_point, int k_closest)
|
||||
KDTreeSearch::KDTreeSearch(KDTREE *tree, float *query_point, int k_closest)
|
||||
: tree_(tree), query_point_(query_point), results_(MAXSEARCH, k_closest) {
|
||||
sb_min_ = new FLOAT32[tree->KeySize];
|
||||
sb_max_ = new FLOAT32[tree->KeySize];
|
||||
sb_min_ = new float[tree->KeySize];
|
||||
sb_max_ = new float[tree->KeySize];
|
||||
}
|
||||
|
||||
KDTreeSearch::~KDTreeSearch() {
|
||||
@ -153,7 +151,7 @@ KDTreeSearch::~KDTreeSearch() {
|
||||
/// Locate the k_closest points to query_point_, and return their distances and
|
||||
/// data into the given buffers.
|
||||
void KDTreeSearch::Search(int *result_count,
|
||||
FLOAT32 *distances,
|
||||
float *distances,
|
||||
void **results) {
|
||||
if (tree_->Root.Left == nullptr) {
|
||||
*result_count = 0;
|
||||
@ -168,7 +166,7 @@ void KDTreeSearch::Search(int *result_count,
|
||||
for (int j = 0; j < count; j++) {
|
||||
// Pre-cast to float64 as key is a template type and we have no control
|
||||
// over its actual type.
|
||||
distances[j] = (FLOAT32)sqrt((FLOAT64)results_.elements()[j].key);
|
||||
distances[j] = (float)sqrt((double)results_.elements()[j].key);
|
||||
results[j] = results_.elements()[j].value;
|
||||
}
|
||||
}
|
||||
@ -211,12 +209,8 @@ KDTREE *MakeKDTree(int16_t KeySize, const PARAM_DESC KeyDesc[]) {
|
||||
* @param Tree K-D tree in which data is to be stored
|
||||
* @param Key ptr to key by which data can be retrieved
|
||||
* @param Data ptr to data to be stored in the tree
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: 3/10/89, DSJ, Created.
|
||||
* 7/13/89, DSJ, Changed return to void.
|
||||
*/
|
||||
void KDStore(KDTREE *Tree, FLOAT32 *Key, void *Data) {
|
||||
void KDStore(KDTREE *Tree, float *Key, void *Data) {
|
||||
int Level;
|
||||
KDNODE *Node;
|
||||
KDNODE **PtrToNode;
|
||||
@ -255,14 +249,9 @@ void KDStore(KDTREE *Tree, FLOAT32 *Key, void *Data) {
|
||||
* @param Tree K-D tree to delete node from
|
||||
* @param Key key of node to be deleted
|
||||
* @param Data data contents of node to be deleted
|
||||
*
|
||||
* @note Exceptions: none
|
||||
*
|
||||
* @note History: 3/13/89, DSJ, Created.
|
||||
* 7/13/89, DSJ, Specify node indirectly by key and data.
|
||||
*/
|
||||
void
|
||||
KDDelete (KDTREE * Tree, FLOAT32 Key[], void *Data) {
|
||||
KDDelete (KDTREE * Tree, float Key[], void *Data) {
|
||||
int Level;
|
||||
KDNODE *Current;
|
||||
KDNODE *Father;
|
||||
@ -313,14 +302,10 @@ KDDelete (KDTREE * Tree, FLOAT32 Key[], void *Data) {
|
||||
* @param DBuffer ptr to QuerySize buffer to hold distances
|
||||
* from nearest neighbor to query point
|
||||
* @param NumberOfResults [out] Number of nearest neighbors actually found
|
||||
* @note Exceptions: none
|
||||
* @note History:
|
||||
* - 3/10/89, DSJ, Created.
|
||||
* - 7/13/89, DSJ, Return contents of node instead of node itself.
|
||||
*/
|
||||
void KDNearestNeighborSearch(
|
||||
KDTREE *Tree, FLOAT32 Query[], int QuerySize, FLOAT32 MaxDistance,
|
||||
int *NumberOfResults, void **NBuffer, FLOAT32 DBuffer[]) {
|
||||
KDTREE *Tree, float Query[], int QuerySize, float MaxDistance,
|
||||
int *NumberOfResults, void **NBuffer, float DBuffer[]) {
|
||||
KDTreeSearch search(Tree, Query, QuerySize);
|
||||
search.Search(NumberOfResults, DBuffer, NBuffer);
|
||||
}
|
||||
@ -344,8 +329,6 @@ void KDWalk(KDTREE *Tree, void_proc action, void *context) {
|
||||
* untouched.
|
||||
* @param Tree tree data structure to be released
|
||||
* @return none
|
||||
* @note Exceptions: none
|
||||
* @note History: 5/26/89, DSJ, Created.
|
||||
*/
|
||||
void FreeKDTree(KDTREE *Tree) {
|
||||
FreeSubTree(Tree->Root.Left);
|
||||
@ -367,10 +350,8 @@ void FreeKDTree(KDTREE *Tree) {
|
||||
* @param Data ptr to data to be stored in new node
|
||||
* @param Index index of Key to branch on
|
||||
* @return pointer to new K-D tree node
|
||||
* @note Exceptions: None
|
||||
* @note History: 3/11/89, DSJ, Created.
|
||||
*/
|
||||
KDNODE *MakeKDNode(KDTREE *tree, FLOAT32 Key[], void *Data, int Index) {
|
||||
KDNODE *MakeKDNode(KDTREE *tree, float Key[], void *Data, int Index) {
|
||||
KDNODE *NewNode;
|
||||
|
||||
NewNode = (KDNODE *) Emalloc (sizeof (KDNODE));
|
||||
@ -409,26 +390,26 @@ void KDTreeSearch::SearchRec(int level, KDNODE *sub_tree) {
|
||||
|
||||
if (query_point_[level] < sub_tree->BranchPoint) {
|
||||
if (sub_tree->Left != nullptr) {
|
||||
FLOAT32 tmp = sb_max_[level];
|
||||
float tmp = sb_max_[level];
|
||||
sb_max_[level] = sub_tree->LeftBranch;
|
||||
SearchRec(NextLevel(tree_, level), sub_tree->Left);
|
||||
sb_max_[level] = tmp;
|
||||
}
|
||||
if (sub_tree->Right != nullptr) {
|
||||
FLOAT32 tmp = sb_min_[level];
|
||||
float tmp = sb_min_[level];
|
||||
sb_min_[level] = sub_tree->RightBranch;
|
||||
SearchRec(NextLevel(tree_, level), sub_tree->Right);
|
||||
sb_min_[level] = tmp;
|
||||
}
|
||||
} else {
|
||||
if (sub_tree->Right != nullptr) {
|
||||
FLOAT32 tmp = sb_min_[level];
|
||||
float tmp = sb_min_[level];
|
||||
sb_min_[level] = sub_tree->RightBranch;
|
||||
SearchRec(NextLevel(tree_, level), sub_tree->Right);
|
||||
sb_min_[level] = tmp;
|
||||
}
|
||||
if (sub_tree->Left != nullptr) {
|
||||
FLOAT32 tmp = sb_max_[level];
|
||||
float tmp = sb_max_[level];
|
||||
sb_max_[level] = sub_tree->LeftBranch;
|
||||
SearchRec(NextLevel(tree_, level), sub_tree->Left);
|
||||
sb_max_[level] = tmp;
|
||||
@ -445,19 +426,19 @@ void KDTreeSearch::SearchRec(int level, KDNODE *sub_tree) {
|
||||
* @param dim dimension descriptions (essential, circular, etc)
|
||||
* @param p1,p2 two different points in K-D space
|
||||
*/
|
||||
FLOAT32 DistanceSquared(int k, PARAM_DESC *dim, FLOAT32 p1[], FLOAT32 p2[]) {
|
||||
FLOAT32 total_distance = 0;
|
||||
float DistanceSquared(int k, PARAM_DESC *dim, float p1[], float p2[]) {
|
||||
float total_distance = 0;
|
||||
|
||||
for (; k > 0; k--, p1++, p2++, dim++) {
|
||||
if (dim->NonEssential)
|
||||
continue;
|
||||
|
||||
FLOAT32 dimension_distance = *p1 - *p2;
|
||||
float dimension_distance = *p1 - *p2;
|
||||
|
||||
/* if this dimension is circular - check wraparound distance */
|
||||
if (dim->Circular) {
|
||||
dimension_distance = Magnitude(dimension_distance);
|
||||
FLOAT32 wrap_distance = dim->Max - dim->Min - dimension_distance;
|
||||
float wrap_distance = dim->Max - dim->Min - dimension_distance;
|
||||
dimension_distance = std::min(dimension_distance, wrap_distance);
|
||||
}
|
||||
|
||||
@ -466,7 +447,7 @@ FLOAT32 DistanceSquared(int k, PARAM_DESC *dim, FLOAT32 p1[], FLOAT32 p2[]) {
|
||||
return total_distance;
|
||||
}
|
||||
|
||||
FLOAT32 ComputeDistance(int k, PARAM_DESC *dim, FLOAT32 p1[], FLOAT32 p2[]) {
|
||||
float ComputeDistance(int k, PARAM_DESC *dim, float p1[], float p2[]) {
|
||||
return sqrt(DistanceSquared(k, dim, p1, p2));
|
||||
}
|
||||
|
||||
@ -475,11 +456,11 @@ FLOAT32 ComputeDistance(int k, PARAM_DESC *dim, FLOAT32 p1[], FLOAT32 p2[]) {
|
||||
/// query_point_ containing results->k_ points) intersects the box specified
|
||||
/// between lower and upper. For circular dimensions, we also check the point
|
||||
/// one wrap distance away from the query.
|
||||
bool KDTreeSearch::BoxIntersectsSearch(FLOAT32 *lower, FLOAT32 *upper) {
|
||||
FLOAT32 *query = query_point_;
|
||||
bool KDTreeSearch::BoxIntersectsSearch(float *lower, float *upper) {
|
||||
float *query = query_point_;
|
||||
// Compute the sum in higher precision.
|
||||
FLOAT64 total_distance = 0.0;
|
||||
FLOAT64 radius_squared =
|
||||
double total_distance = 0.0;
|
||||
double radius_squared =
|
||||
results_.max_insertable_key() * results_.max_insertable_key();
|
||||
PARAM_DESC *dim = tree_->KeyDesc;
|
||||
|
||||
@ -487,7 +468,7 @@ bool KDTreeSearch::BoxIntersectsSearch(FLOAT32 *lower, FLOAT32 *upper) {
|
||||
if (dim->NonEssential)
|
||||
continue;
|
||||
|
||||
FLOAT32 dimension_distance;
|
||||
float dimension_distance;
|
||||
if (*query < *lower)
|
||||
dimension_distance = *lower - *query;
|
||||
else if (*query > *upper)
|
||||
@ -497,7 +478,7 @@ bool KDTreeSearch::BoxIntersectsSearch(FLOAT32 *lower, FLOAT32 *upper) {
|
||||
|
||||
/* if this dimension is circular - check wraparound distance */
|
||||
if (dim->Circular) {
|
||||
FLOAT32 wrap_distance = MAX_FLOAT32;
|
||||
float wrap_distance = FLT_MAX;
|
||||
if (*query < *lower)
|
||||
wrap_distance = *query + dim->Max - dim->Min - *upper;
|
||||
else if (*query > *upper)
|
||||
|
@ -1,11 +1,9 @@
|
||||
/******************************************************************************
|
||||
** Filename: kdtree.h
|
||||
** Purpose: Definition of K-D tree access routines.
|
||||
** Author: Dan Johnson
|
||||
** History: 3/11/89, DSJ, Created.
|
||||
** 5/23/89, DSJ, Added circular feature capability.
|
||||
** Filename: kdtree.h
|
||||
** Purpose: Definition of K-D tree access routines.
|
||||
** Author: Dan Johnson
|
||||
**
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
@ -15,15 +13,15 @@
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
******************************************************************************/
|
||||
*****************************************************************************/
|
||||
#ifndef KDTREE_H
|
||||
#define KDTREE_H
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
Include Files and Type Defines
|
||||
-----------------------------------------------------------------------------*/
|
||||
#include "cutil.h" // for void_proc
|
||||
#include "host.h"
|
||||
#include "cutil.h"
|
||||
#include "ocrfeatures.h"
|
||||
|
||||
/**
|
||||
@ -37,17 +35,17 @@ correctly if circular parameters outside the specified range are used.
|
||||
*/
|
||||
|
||||
struct KDNODE {
|
||||
FLOAT32 *Key; /**< search key */
|
||||
void *Data; /**< data that corresponds to key */
|
||||
FLOAT32 BranchPoint; /**< needed to make deletes work efficiently */
|
||||
FLOAT32 LeftBranch; /**< used to optimize search pruning */
|
||||
FLOAT32 RightBranch; /**< used to optimize search pruning */
|
||||
struct KDNODE *Left; /**< ptrs for KD tree structure */
|
||||
float *Key; /**< search key */
|
||||
void *Data; /**< data that corresponds to key */
|
||||
float BranchPoint; /**< needed to make deletes work efficiently */
|
||||
float LeftBranch; /**< used to optimize search pruning */
|
||||
float RightBranch; /**< used to optimize search pruning */
|
||||
struct KDNODE *Left; /**< ptrs for KD tree structure */
|
||||
struct KDNODE *Right;
|
||||
};
|
||||
|
||||
struct KDTREE {
|
||||
int16_t KeySize; /* number of dimensions in the tree */
|
||||
int16_t KeySize; /* number of dimensions in the tree */
|
||||
KDNODE Root; /* Root.Left points to actual root node */
|
||||
PARAM_DESC KeyDesc[1]; /* description of each dimension */
|
||||
};
|
||||
@ -62,13 +60,13 @@ struct KDTREE {
|
||||
-----------------------------------------------------------------------------*/
|
||||
KDTREE *MakeKDTree(int16_t KeySize, const PARAM_DESC KeyDesc[]);
|
||||
|
||||
void KDStore(KDTREE *Tree, FLOAT32 *Key, void *Data);
|
||||
void KDStore(KDTREE *Tree, float *Key, void *Data);
|
||||
|
||||
void KDDelete(KDTREE * Tree, FLOAT32 Key[], void *Data);
|
||||
void KDDelete(KDTREE * Tree, float Key[], void *Data);
|
||||
|
||||
void KDNearestNeighborSearch(
|
||||
KDTREE *Tree, FLOAT32 Query[], int QuerySize, FLOAT32 MaxDistance,
|
||||
int *NumberOfResults, void **NBuffer, FLOAT32 DBuffer[]);
|
||||
KDTREE *Tree, float Query[], int QuerySize, float MaxDistance,
|
||||
int *NumberOfResults, void **NBuffer, float DBuffer[]);
|
||||
|
||||
void KDWalk(KDTREE *Tree, void_proc Action, void *context);
|
||||
|
||||
@ -77,13 +75,13 @@ void FreeKDTree(KDTREE *Tree);
|
||||
/*-----------------------------------------------------------------------------
|
||||
Private Function Prototypes
|
||||
-----------------------------------------------------------------------------*/
|
||||
KDNODE *MakeKDNode(KDTREE *tree, FLOAT32 Key[], void *Data, int Index);
|
||||
KDNODE *MakeKDNode(KDTREE *tree, float Key[], void *Data, int Index);
|
||||
|
||||
void FreeKDNode(KDNODE *Node);
|
||||
|
||||
FLOAT32 DistanceSquared(int k, PARAM_DESC *dim, FLOAT32 p1[], FLOAT32 p2[]);
|
||||
float DistanceSquared(int k, PARAM_DESC *dim, float p1[], float p2[]);
|
||||
|
||||
FLOAT32 ComputeDistance(int k, PARAM_DESC *dim, FLOAT32 p1[], FLOAT32 p2[]);
|
||||
float ComputeDistance(int k, PARAM_DESC *dim, float p1[], float p2[]);
|
||||
|
||||
int QueryInSearch(KDTREE *tree);
|
||||
|
||||
|
@ -30,7 +30,6 @@
|
||||
#include "allheaders.h"
|
||||
#include "boxread.h"
|
||||
#include "classify.h"
|
||||
#include "efio.h"
|
||||
#include "errorcounter.h"
|
||||
#include "featdefs.h"
|
||||
#include "sampleiterator.h"
|
||||
@ -121,7 +120,7 @@ void MasterTrainer::ReadTrainingSamples(const char* page_name,
|
||||
const int cn_feature_type = ShortNameToFeatureType(feature_defs, kCNFeatureType);
|
||||
const int geo_feature_type = ShortNameToFeatureType(feature_defs, kGeoFeatureType);
|
||||
|
||||
FILE* fp = Efopen(page_name, "rb");
|
||||
FILE* fp = fopen(page_name, "rb");
|
||||
if (fp == nullptr) {
|
||||
tprintf("Failed to open tr file: %s\n", page_name);
|
||||
return;
|
||||
|
@ -39,8 +39,6 @@
|
||||
* @param Blob blob to extract micro-features from
|
||||
* @param cn_denorm control parameter to feature extractor.
|
||||
* @return Micro-features for Blob.
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed May 23 18:06:38 1990, DSJ, Created.
|
||||
*/
|
||||
FEATURE_SET ExtractMicros(TBLOB* Blob, const DENORM& cn_denorm) {
|
||||
int NumFeatures;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
** Filename: mfdefs.c
|
||||
** Filename: mfdefs.cpp
|
||||
** Purpose: Basic routines for manipulating micro-features
|
||||
** Author: Dan Johnson
|
||||
** History: Mon Jan 22 08:48:58 1990, DSJ, Created.
|
||||
@ -30,7 +30,6 @@
|
||||
* This routine allocates and returns a new micro-feature
|
||||
* data structure.
|
||||
* @return New MICROFEATURE
|
||||
* @note History: 7/27/89, DSJ, Created.
|
||||
*/
|
||||
MICROFEATURE NewMicroFeature() {
|
||||
return ((MICROFEATURE) Emalloc (sizeof (MFBLOCK)));
|
||||
@ -43,7 +42,6 @@ MICROFEATURE NewMicroFeature() {
|
||||
* a list of micro-features.
|
||||
* @param MicroFeatures list of micro-features to be freed
|
||||
* @return none
|
||||
* @note History: 7/27/89, DSJ, Created.
|
||||
*/
|
||||
void FreeMicroFeatures(MICROFEATURES MicroFeatures) {
|
||||
destroy_nodes(MicroFeatures, Efree);
|
||||
|
@ -1,10 +1,10 @@
|
||||
/******************************************************************************
|
||||
** Filename: mfdefs.h
|
||||
** Purpose: Definition of micro-features
|
||||
** Author: Dan Johnson
|
||||
** History: Mon Jan 22 08:42:13 1990, DSJ, Created.
|
||||
** Filename: mfdefs.h
|
||||
** Purpose: Definition of micro-features
|
||||
** Author: Dan Johnson
|
||||
** History: Mon Jan 22 08:42:13 1990, DSJ, Created.
|
||||
**
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
@ -29,8 +29,8 @@ typedef LIST MICROFEATURES;
|
||||
|
||||
/* definition of structure of micro-features */
|
||||
#define MFSIZE 6
|
||||
typedef FLOAT32 MFBLOCK[MFSIZE];
|
||||
typedef FLOAT32 *MICROFEATURE;
|
||||
typedef float MFBLOCK[MFSIZE];
|
||||
typedef float *MICROFEATURE;
|
||||
|
||||
/* definitions of individual micro-feature parameters */
|
||||
#define XPOSITION 0
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "emalloc.h"
|
||||
#include "mfoutline.h"
|
||||
#include "blobs.h"
|
||||
#include "const.h"
|
||||
#include "mfx.h"
|
||||
#include "params.h"
|
||||
#include "classify.h"
|
||||
@ -115,12 +114,10 @@ LIST ConvertOutlines(TESSLINE *outline,
|
||||
* @param MinSlope controls "snapping" of segments to horizontal
|
||||
* @param MaxSlope controls "snapping" of segments to vertical
|
||||
* @return none
|
||||
* @note Exceptions: none
|
||||
* @note History: 7/21/89, DSJ, Created.
|
||||
*/
|
||||
void FindDirectionChanges(MFOUTLINE Outline,
|
||||
FLOAT32 MinSlope,
|
||||
FLOAT32 MaxSlope) {
|
||||
float MinSlope,
|
||||
float MaxSlope) {
|
||||
MFEDGEPT *Current;
|
||||
MFEDGEPT *Last;
|
||||
MFOUTLINE EdgePoint;
|
||||
@ -149,8 +146,6 @@ void FindDirectionChanges(MFOUTLINE Outline,
|
||||
* a micro-feature outline.
|
||||
* @param arg micro-feature outline to be freed
|
||||
* @return none
|
||||
* @note Exceptions: none
|
||||
* @note History: 7/27/89, DSJ, Created.
|
||||
*/
|
||||
void FreeMFOutline(void *arg) { //MFOUTLINE Outline)
|
||||
MFOUTLINE Start;
|
||||
@ -173,8 +168,6 @@ void FreeMFOutline(void *arg) { //MFOUTLINE Outline
|
||||
* of outlines.
|
||||
* @param Outlines list of mf-outlines to be freed
|
||||
* @return none
|
||||
* @note Exceptions: none
|
||||
* @note History: Thu Dec 13 16:14:50 1990, DSJ, Created.
|
||||
*/
|
||||
void FreeOutlines(LIST Outlines) {
|
||||
destroy_nodes(Outlines, FreeMFOutline);
|
||||
@ -193,8 +186,6 @@ void FreeOutlines(LIST Outlines) {
|
||||
* @param Outline micro-feature outline to analyze
|
||||
* @return none
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: 6/29/90, DSJ, Created.
|
||||
*/
|
||||
void MarkDirectionChanges(MFOUTLINE Outline) {
|
||||
MFOUTLINE Current;
|
||||
@ -232,8 +223,6 @@ MFEDGEPT *NewEdgePoint() {
|
||||
* @param EdgePoint start search from this point
|
||||
* @return Next extremity in the outline after EdgePoint.
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: 7/26/89, DSJ, Created.
|
||||
*/
|
||||
MFOUTLINE NextExtremity(MFOUTLINE EdgePoint) {
|
||||
EdgePoint = NextPointAfter(EdgePoint);
|
||||
@ -258,11 +247,9 @@ MFOUTLINE NextExtremity(MFOUTLINE EdgePoint) {
|
||||
* @param XOrigin x-origin of text
|
||||
* @return none
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: 8/2/89, DSJ, Created.
|
||||
*/
|
||||
void NormalizeOutline(MFOUTLINE Outline,
|
||||
FLOAT32 XOrigin) {
|
||||
float XOrigin) {
|
||||
if (Outline == NIL_LIST)
|
||||
return;
|
||||
|
||||
@ -294,12 +281,10 @@ namespace tesseract {
|
||||
* @param XScale x-direction scale factor used by routine
|
||||
* @param YScale y-direction scale factor used by routine
|
||||
* @return none (Outlines are changed and XScale and YScale are updated)
|
||||
* @note Exceptions: none
|
||||
* @note History: Fri Dec 14 08:14:55 1990, DSJ, Created.
|
||||
*/
|
||||
void Classify::NormalizeOutlines(LIST Outlines,
|
||||
FLOAT32 *XScale,
|
||||
FLOAT32 *YScale) {
|
||||
float *XScale,
|
||||
float *YScale) {
|
||||
MFOUTLINE Outline;
|
||||
|
||||
switch (classify_norm_method) {
|
||||
@ -331,8 +316,6 @@ void Classify::NormalizeOutlines(LIST Outlines,
|
||||
* @param Direction new direction to assign to segment
|
||||
* @return none
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Fri May 4 10:42:04 1990, DSJ, Created.
|
||||
*/
|
||||
void ChangeDirection(MFOUTLINE Start, MFOUTLINE End, DIRECTION Direction) {
|
||||
MFOUTLINE Current;
|
||||
@ -352,8 +335,6 @@ void ChangeDirection(MFOUTLINE Start, MFOUTLINE End, DIRECTION Direction) {
|
||||
* @param cn_denorm
|
||||
* @return none
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Fri Dec 14 10:27:11 1990, DSJ, Created.
|
||||
*/
|
||||
void CharNormalizeOutline(MFOUTLINE Outline, const DENORM& cn_denorm) {
|
||||
MFOUTLINE First, Current;
|
||||
@ -393,24 +374,22 @@ void CharNormalizeOutline(MFOUTLINE Outline, const DENORM& cn_denorm) {
|
||||
* @param MaxSlope slope above which lines are vertical
|
||||
* @return none
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: 7/25/89, DSJ, Created.
|
||||
*/
|
||||
void ComputeDirection(MFEDGEPT *Start,
|
||||
MFEDGEPT *Finish,
|
||||
FLOAT32 MinSlope,
|
||||
FLOAT32 MaxSlope) {
|
||||
float MinSlope,
|
||||
float MaxSlope) {
|
||||
FVECTOR Delta;
|
||||
|
||||
Delta.x = Finish->Point.x - Start->Point.x;
|
||||
Delta.y = Finish->Point.y - Start->Point.y;
|
||||
if (Delta.x == 0)
|
||||
if (Delta.y < 0) {
|
||||
Start->Slope = -MAX_FLOAT32;
|
||||
Start->Slope = -FLT_MAX;
|
||||
Start->Direction = south;
|
||||
}
|
||||
else {
|
||||
Start->Slope = MAX_FLOAT32;
|
||||
Start->Slope = FLT_MAX;
|
||||
Start->Direction = north;
|
||||
}
|
||||
else {
|
||||
@ -458,8 +437,6 @@ void ComputeDirection(MFEDGEPT *Start,
|
||||
* @param EdgePoint start search from this point
|
||||
* @return Point of next direction change in micro-feature outline.
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: 7/25/89, DSJ, Created.
|
||||
*/
|
||||
MFOUTLINE NextDirectionChange(MFOUTLINE EdgePoint) {
|
||||
DIRECTION InitialDirection;
|
||||
|
@ -1,10 +1,10 @@
|
||||
/******************************************************************************
|
||||
** Filename: mfoutline.h
|
||||
** Purpose: Interface spec for fx outline structures
|
||||
** Author: Dan Johnson
|
||||
** History: Thu May 17 08:55:32 1990, DSJ, Created.
|
||||
** Filename: mfoutline.h
|
||||
** Purpose: Interface spec for fx outline structures
|
||||
** Author: Dan Johnson
|
||||
** History: Thu May 17 08:55:32 1990, DSJ, Created.
|
||||
**
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
@ -15,8 +15,9 @@
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
******************************************************************************/
|
||||
#ifndef MFOUTLINE_H
|
||||
#define MFOUTLINE_H
|
||||
|
||||
#ifndef MFOUTLINE_H
|
||||
#define MFOUTLINE_H
|
||||
|
||||
/**----------------------------------------------------------------------------
|
||||
Include Files and Type Defines
|
||||
@ -38,7 +39,7 @@ typedef enum {
|
||||
|
||||
typedef struct {
|
||||
FPOINT Point;
|
||||
FLOAT32 Slope;
|
||||
float Slope;
|
||||
unsigned Padding:20;
|
||||
BOOL8 Hidden:TRUE;
|
||||
BOOL8 ExtremityMark:TRUE;
|
||||
@ -85,11 +86,11 @@ LIST ConvertOutlines(TESSLINE *Outline,
|
||||
LIST ConvertedOutlines,
|
||||
OUTLINETYPE OutlineType);
|
||||
|
||||
void FilterEdgeNoise(MFOUTLINE Outline, FLOAT32 NoiseSegmentLength);
|
||||
void FilterEdgeNoise(MFOUTLINE Outline, float NoiseSegmentLength);
|
||||
|
||||
void FindDirectionChanges(MFOUTLINE Outline,
|
||||
FLOAT32 MinSlope,
|
||||
FLOAT32 MaxSlope);
|
||||
float MinSlope,
|
||||
float MaxSlope);
|
||||
|
||||
void FreeMFOutline(void *agr); //MFOUTLINE Outline);
|
||||
|
||||
@ -102,7 +103,7 @@ MFEDGEPT *NewEdgePoint();
|
||||
MFOUTLINE NextExtremity(MFOUTLINE EdgePoint);
|
||||
|
||||
void NormalizeOutline(MFOUTLINE Outline,
|
||||
FLOAT32 XOrigin);
|
||||
float XOrigin);
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Private Function Prototypes
|
||||
@ -116,8 +117,8 @@ void CharNormalizeOutline(MFOUTLINE Outline, const DENORM& cn_denorm);
|
||||
|
||||
void ComputeDirection(MFEDGEPT *Start,
|
||||
MFEDGEPT *Finish,
|
||||
FLOAT32 MinSlope,
|
||||
FLOAT32 MaxSlope);
|
||||
float MinSlope,
|
||||
float MaxSlope);
|
||||
|
||||
MFOUTLINE NextDirectionChange(MFOUTLINE EdgePoint);
|
||||
|
||||
|
@ -14,14 +14,13 @@
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
******************************************************************************/
|
||||
*****************************************************************************/
|
||||
/*----------------------------------------------------------------------------
|
||||
Include Files and Type Defines
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "mfdefs.h"
|
||||
#include "mfoutline.h"
|
||||
#include "clusttool.h" //NEEDED
|
||||
#include "const.h"
|
||||
#include "intfx.h"
|
||||
#include "normalis.h"
|
||||
#include "params.h"
|
||||
@ -42,12 +41,12 @@ double_VAR(classify_max_slope, 2.414213562,
|
||||
Macros
|
||||
----------------------------------------------------------------------------*/
|
||||
/* miscellaneous macros */
|
||||
#define NormalizeAngle(A) ( (((A)<0)?((A)+2*PI):(A)) / (2*PI) )
|
||||
#define NormalizeAngle(A) ((((A) < 0) ? ((A) + 2 * M_PI) : (A)) / (2 * M_PI))
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
Private Function Prototypes
|
||||
-----------------------------------------------------------------------------*/
|
||||
FLOAT32 ComputeOrientation(MFEDGEPT *Start, MFEDGEPT *End);
|
||||
float ComputeOrientation(MFEDGEPT *Start, MFEDGEPT *End);
|
||||
|
||||
MICROFEATURES ConvertToMicroFeatures(MFOUTLINE Outline,
|
||||
MICROFEATURES MicroFeatures);
|
||||
@ -66,8 +65,6 @@ MICROFEATURE ExtractMicroFeature(MFOUTLINE Start, MFOUTLINE End);
|
||||
* @param Blob blob to extract micro-features from
|
||||
* @param cn_denorm control parameter to feature extractor
|
||||
* @return List of micro-features extracted from the blob.
|
||||
* @note Exceptions: none
|
||||
* @note History: 7/21/89, DSJ, Created.
|
||||
*/
|
||||
MICROFEATURES BlobMicroFeatures(TBLOB* Blob, const DENORM& cn_denorm) {
|
||||
MICROFEATURES MicroFeatures = NIL_LIST;
|
||||
@ -114,13 +111,9 @@ MICROFEATURES BlobMicroFeatures(TBLOB* Blob, const DENORM& cn_denorm) {
|
||||
* @param End ending edge point of micro-feature
|
||||
* @note Globals: none
|
||||
* @return Orientation parameter for the specified micro-feature.
|
||||
* @note Exceptions: none
|
||||
* @note History: 7/27/89, DSJ, Created.
|
||||
*/
|
||||
FLOAT32 ComputeOrientation(MFEDGEPT *Start, MFEDGEPT *End) {
|
||||
FLOAT32 Orientation;
|
||||
|
||||
Orientation = NormalizeAngle (AngleFrom (Start->Point, End->Point));
|
||||
float ComputeOrientation(MFEDGEPT *Start, MFEDGEPT *End) {
|
||||
float Orientation = NormalizeAngle(AngleFrom(Start->Point, End->Point));
|
||||
|
||||
/* ensure that round-off errors do not put circular param out of range */
|
||||
if ((Orientation < 0) || (Orientation >= 1))
|
||||
@ -134,8 +127,6 @@ FLOAT32 ComputeOrientation(MFEDGEPT *Start, MFEDGEPT *End) {
|
||||
* @param MicroFeatures list of micro-features to add to
|
||||
* @return List of micro-features with new features added to front.
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: 7/26/89, DSJ, Created.
|
||||
*/
|
||||
MICROFEATURES ConvertToMicroFeatures(MFOUTLINE Outline,
|
||||
MICROFEATURES MicroFeatures) {
|
||||
@ -175,10 +166,6 @@ MICROFEATURES ConvertToMicroFeatures(MFOUTLINE Outline,
|
||||
* @param End ending point of micro-feature
|
||||
* @return New micro-feature or nullptr if the feature was rejected.
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History:
|
||||
* - 7/26/89, DSJ, Created.
|
||||
* - 11/17/89, DSJ, Added handling for Start and End same point.
|
||||
*/
|
||||
MICROFEATURE ExtractMicroFeature(MFOUTLINE Start, MFOUTLINE End) {
|
||||
MICROFEATURE NewFeature;
|
||||
|
@ -29,7 +29,7 @@
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/** Return the length of the outline in baseline normalized form. */
|
||||
FLOAT32 ActualOutlineLength(FEATURE Feature) {
|
||||
float ActualOutlineLength(FEATURE Feature) {
|
||||
return (Feature->Params[CharNormLength] * LENGTH_COMPRESSION);
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
/******************************************************************************
|
||||
** Filename: normfeat.h
|
||||
** Purpose: Definition of character normalization features.
|
||||
** Author: Dan Johnson
|
||||
** History: 12/14/90, DSJ, Created.
|
||||
** Filename: normfeat.h
|
||||
** Purpose: Definition of character normalization features.
|
||||
** Author: Dan Johnson
|
||||
** History: 12/14/90, DSJ, Created.
|
||||
**
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
@ -14,9 +14,10 @@
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
******************************************************************************/
|
||||
#ifndef NORMFEAT_H
|
||||
#define NORMFEAT_H
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef NORMFEAT_H
|
||||
#define NORMFEAT_H
|
||||
|
||||
/**----------------------------------------------------------------------------
|
||||
Include Files and Type Defines
|
||||
@ -32,7 +33,7 @@ typedef enum {
|
||||
/**----------------------------------------------------------------------------
|
||||
Public Function Prototypes
|
||||
----------------------------------------------------------------------------**/
|
||||
FLOAT32 ActualOutlineLength(FEATURE Feature);
|
||||
float ActualOutlineLength(FEATURE Feature);
|
||||
|
||||
FEATURE_SET ExtractCharNormFeatures(const INT_FX_RESULT_STRUCT& fx_info);
|
||||
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
#include "classify.h"
|
||||
#include "clusttool.h"
|
||||
#include "const.h"
|
||||
#include "efio.h"
|
||||
#include "emalloc.h"
|
||||
#include "globals.h"
|
||||
#include "helpers.h"
|
||||
@ -81,16 +79,14 @@ namespace tesseract {
|
||||
* #NormProtos character normalization prototypes
|
||||
*
|
||||
* @return Best match rating for Feature against protos of ClassId.
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed Dec 19 16:56:12 1990, DSJ, Created.
|
||||
*/
|
||||
FLOAT32 Classify::ComputeNormMatch(CLASS_ID ClassId,
|
||||
const FEATURE_STRUCT& feature,
|
||||
bool DebugMatch) {
|
||||
float Classify::ComputeNormMatch(CLASS_ID ClassId,
|
||||
const FEATURE_STRUCT& feature,
|
||||
bool DebugMatch) {
|
||||
LIST Protos;
|
||||
FLOAT32 BestMatch;
|
||||
FLOAT32 Match;
|
||||
FLOAT32 Delta;
|
||||
float BestMatch;
|
||||
float Match;
|
||||
float Delta;
|
||||
PROTOTYPE *Proto;
|
||||
int ProtoId;
|
||||
|
||||
@ -110,7 +106,7 @@ FLOAT32 Classify::ComputeNormMatch(CLASS_ID ClassId,
|
||||
return (1.0 - NormEvidenceOf (Match));
|
||||
}
|
||||
|
||||
BestMatch = MAX_FLOAT32;
|
||||
BestMatch = FLT_MAX;
|
||||
Protos = NormProtos->Protos[ClassId];
|
||||
|
||||
if (DebugMatch) {
|
||||
@ -202,16 +198,14 @@ double NormEvidenceOf(double NormAdj) {
|
||||
* @param Feature[] array of feature parameters
|
||||
* Globals: none
|
||||
* @return none
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed Jan 2 09:49:35 1991, DSJ, Created.
|
||||
*/
|
||||
void PrintNormMatch(FILE *File,
|
||||
int NumParams,
|
||||
PROTOTYPE *Proto,
|
||||
FEATURE Feature) {
|
||||
int i;
|
||||
FLOAT32 ParamMatch;
|
||||
FLOAT32 TotalMatch;
|
||||
float ParamMatch;
|
||||
float TotalMatch;
|
||||
|
||||
for (i = 0, TotalMatch = 0.0; i < NumParams; i++) {
|
||||
ParamMatch = (Feature->Params[i] - Mean(Proto, i)) /
|
||||
@ -237,8 +231,6 @@ namespace tesseract {
|
||||
* @param fp open text file to read normalization protos from
|
||||
* Globals: none
|
||||
* @return Character normalization protos.
|
||||
* @note Exceptions: none
|
||||
* @note History: Wed Dec 19 16:38:49 1990, DSJ, Created.
|
||||
*/
|
||||
NORM_PROTOS *Classify::ReadNormProtos(TFile *fp) {
|
||||
NORM_PROTOS *NormProtos;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/******************************************************************************
|
||||
** Filename: features.c
|
||||
** Filename: ocrfeatures.cpp
|
||||
** Purpose: Generic definition of a feature.
|
||||
** Author: Dan Johnson
|
||||
** History: Mon May 21 10:49:04 1990, DSJ, Created.
|
||||
@ -21,7 +21,6 @@
|
||||
#include "ocrfeatures.h"
|
||||
#include "emalloc.h"
|
||||
#include "callcpp.h"
|
||||
#include "danerror.h"
|
||||
#include "scanutils.h"
|
||||
|
||||
#include <cassert>
|
||||
@ -38,7 +37,6 @@
|
||||
* @param FeatureSet set of features to add Feature to
|
||||
* @param Feature feature to be added to FeatureSet
|
||||
* @return TRUE if feature added to set, FALSE if set is already full.
|
||||
* @note History: Tue May 22 17:22:23 1990, DSJ, Created.
|
||||
*/
|
||||
bool AddFeature(FEATURE_SET FeatureSet, FEATURE Feature) {
|
||||
if (FeatureSet->NumFeatures >= FeatureSet->MaxNumFeatures) {
|
||||
@ -54,7 +52,6 @@ bool AddFeature(FEATURE_SET FeatureSet, FEATURE Feature) {
|
||||
* Release the memory consumed by the specified feature.
|
||||
* @param Feature feature to be deallocated.
|
||||
* @return none
|
||||
* @note History: Mon May 21 13:33:27 1990, DSJ, Created.
|
||||
*/
|
||||
void FreeFeature(FEATURE Feature) { free(Feature); } /* FreeFeature */
|
||||
|
||||
@ -64,7 +61,6 @@ void FreeFeature(FEATURE Feature) { free(Feature); } /* FreeFeature */
|
||||
* features contained in the set.
|
||||
* @param FeatureSet set of features to be freed
|
||||
* @return none
|
||||
* @note History: Mon May 21 13:59:46 1990, DSJ, Created.
|
||||
*/
|
||||
void FreeFeatureSet(FEATURE_SET FeatureSet) {
|
||||
int i;
|
||||
@ -81,13 +77,12 @@ void FreeFeatureSet(FEATURE_SET FeatureSet) {
|
||||
* type.
|
||||
* @param FeatureDesc description of feature to be created.
|
||||
* @return New #FEATURE.
|
||||
* @note History: Mon May 21 14:06:42 1990, DSJ, Created.
|
||||
*/
|
||||
FEATURE NewFeature(const FEATURE_DESC_STRUCT* FeatureDesc) {
|
||||
FEATURE Feature;
|
||||
|
||||
Feature = (FEATURE)malloc(sizeof(FEATURE_STRUCT) +
|
||||
(FeatureDesc->NumParams - 1) * sizeof(FLOAT32));
|
||||
(FeatureDesc->NumParams - 1) * sizeof(float));
|
||||
Feature->Type = FeatureDesc;
|
||||
return (Feature);
|
||||
|
||||
@ -98,7 +93,6 @@ FEATURE NewFeature(const FEATURE_DESC_STRUCT* FeatureDesc) {
|
||||
* hold the specified number of features.
|
||||
* @param NumFeatures maximum # of features to be put in feature set
|
||||
* @return New #FEATURE_SET.
|
||||
* @note History: Mon May 21 14:22:40 1990, DSJ, Created.
|
||||
*/
|
||||
FEATURE_SET NewFeatureSet(int NumFeatures) {
|
||||
FEATURE_SET FeatureSet;
|
||||
@ -121,9 +115,6 @@ FEATURE_SET NewFeatureSet(int NumFeatures) {
|
||||
* @param File open text file to read feature from
|
||||
* @param FeatureDesc specifies type of feature to read from File
|
||||
* @return New #FEATURE read from File.
|
||||
* @note Exceptions: #ILLEGAL_FEATURE_PARAM if text file doesn't match expected
|
||||
* format
|
||||
* @note History: Wed May 23 08:53:16 1990, DSJ, Created.
|
||||
*/
|
||||
FEATURE ReadFeature(FILE* File, const FEATURE_DESC_STRUCT* FeatureDesc) {
|
||||
FEATURE Feature;
|
||||
@ -131,14 +122,13 @@ FEATURE ReadFeature(FILE* File, const FEATURE_DESC_STRUCT* FeatureDesc) {
|
||||
|
||||
Feature = NewFeature (FeatureDesc);
|
||||
for (i = 0; i < Feature->Type->NumParams; i++) {
|
||||
if (tfscanf(File, "%f", &(Feature->Params[i])) != 1)
|
||||
DoError (ILLEGAL_FEATURE_PARAM, "Illegal feature parameter spec");
|
||||
ASSERT_HOST(tfscanf(File, "%f", &(Feature->Params[i])) == 1);
|
||||
#ifndef _WIN32
|
||||
assert (!std::isnan(Feature->Params[i]));
|
||||
#endif
|
||||
}
|
||||
return (Feature);
|
||||
} /* ReadFeature */
|
||||
return Feature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new feature set of the specified type and read in
|
||||
@ -149,22 +139,18 @@ FEATURE ReadFeature(FILE* File, const FEATURE_DESC_STRUCT* FeatureDesc) {
|
||||
* @param File open text file to read new feature set from
|
||||
* @param FeatureDesc specifies type of feature to read from File
|
||||
* @return New feature set read from File.
|
||||
* @note History: Wed May 23 09:17:31 1990, DSJ, Created.
|
||||
*/
|
||||
FEATURE_SET ReadFeatureSet(FILE* File, const FEATURE_DESC_STRUCT* FeatureDesc) {
|
||||
FEATURE_SET FeatureSet;
|
||||
int NumFeatures;
|
||||
int i;
|
||||
ASSERT_HOST(tfscanf(File, "%d", &NumFeatures) == 1);
|
||||
ASSERT_HOST(NumFeatures >= 0);
|
||||
|
||||
if (tfscanf(File, "%d", &NumFeatures) != 1 || NumFeatures < 0)
|
||||
DoError(ILLEGAL_NUM_FEATURES, "Illegal number of features in set");
|
||||
|
||||
FeatureSet = NewFeatureSet(NumFeatures);
|
||||
for (i = 0; i < NumFeatures; i++)
|
||||
FEATURE_SET FeatureSet = NewFeatureSet(NumFeatures);
|
||||
for (int i = 0; i < NumFeatures; i++)
|
||||
AddFeature(FeatureSet, ReadFeature (File, FeatureDesc));
|
||||
|
||||
return (FeatureSet);
|
||||
} /* ReadFeatureSet */
|
||||
return FeatureSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a textual representation of Feature to str.
|
||||
@ -176,7 +162,6 @@ FEATURE_SET ReadFeatureSet(FILE* File, const FEATURE_DESC_STRUCT* FeatureDesc) {
|
||||
* @param Feature feature to write out to str
|
||||
* @param str string to write Feature to
|
||||
* @return none
|
||||
* @note History: Wed May 23 09:28:18 1990, DSJ, Created.
|
||||
*/
|
||||
void WriteFeature(FEATURE Feature, STRING* str) {
|
||||
for (int i = 0; i < Feature->Type->NumParams; i++) {
|
||||
@ -196,7 +181,6 @@ void WriteFeature(FEATURE Feature, STRING* str) {
|
||||
* @param FeatureSet feature set to write to File
|
||||
* @param str string to write Feature to
|
||||
* @return none
|
||||
* @note History: Wed May 23 10:06:03 1990, DSJ, Created.
|
||||
*/
|
||||
void WriteFeatureSet(FEATURE_SET FeatureSet, STRING* str) {
|
||||
if (FeatureSet) {
|
||||
@ -221,7 +205,6 @@ void WriteFeatureSet(FEATURE_SET FeatureSet, STRING* str) {
|
||||
* @param File open text file to write FeatureDesc to
|
||||
* @param FeatureDesc feature descriptor to write to File
|
||||
* @return none
|
||||
* @note History: Fri May 25 15:27:18 1990, DSJ, Created.
|
||||
*/
|
||||
void WriteOldParamDesc(FILE* File, const FEATURE_DESC_STRUCT* FeatureDesc) {
|
||||
int i;
|
||||
|
@ -1,10 +1,10 @@
|
||||
/******************************************************************************
|
||||
** Filename: features.h
|
||||
** Purpose: Generic definition of a feature.
|
||||
** Author: Dan Johnson
|
||||
** History: Sun May 20 10:28:30 1990, DSJ, Created.
|
||||
** Filename: features.h
|
||||
** Purpose: Generic definition of a feature.
|
||||
** Author: Dan Johnson
|
||||
** History: Sun May 20 10:28:30 1990, DSJ, Created.
|
||||
**
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
@ -15,8 +15,9 @@
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
******************************************************************************/
|
||||
#ifndef FEATURES_H
|
||||
#define FEATURES_H
|
||||
|
||||
#ifndef FEATURES_H
|
||||
#define FEATURES_H
|
||||
|
||||
/**----------------------------------------------------------------------------
|
||||
Include Files and Type Defines
|
||||
@ -30,11 +31,7 @@ struct INT_FX_RESULT_STRUCT;
|
||||
|
||||
#undef Min
|
||||
#undef Max
|
||||
#define FEAT_NAME_SIZE 80
|
||||
|
||||
// define trap errors which can be caused by this module
|
||||
#define ILLEGAL_FEATURE_PARAM 1000
|
||||
#define ILLEGAL_NUM_FEATURES 1001
|
||||
#define FEAT_NAME_SIZE 80
|
||||
|
||||
// A character is described by multiple sets of extracted features. Each
|
||||
// set contains a number of features of a particular type, for example, a
|
||||
@ -44,52 +41,55 @@ struct INT_FX_RESULT_STRUCT;
|
||||
// parameters are required to be the first parameters in the feature.
|
||||
|
||||
struct PARAM_DESC {
|
||||
int8_t Circular; // TRUE if dimension wraps around
|
||||
int8_t NonEssential; // TRUE if dimension not used in searches
|
||||
FLOAT32 Min; // low end of range for circular dimensions
|
||||
FLOAT32 Max; // high end of range for circular dimensions
|
||||
FLOAT32 Range; // Max - Min
|
||||
FLOAT32 HalfRange; // (Max - Min)/2
|
||||
FLOAT32 MidRange; // (Max + Min)/2
|
||||
int8_t Circular; // TRUE if dimension wraps around
|
||||
int8_t NonEssential; // TRUE if dimension not used in searches
|
||||
float Min; // low end of range for circular dimensions
|
||||
float Max; // high end of range for circular dimensions
|
||||
float Range; // Max - Min
|
||||
float HalfRange; // (Max - Min)/2
|
||||
float MidRange; // (Max + Min)/2
|
||||
};
|
||||
|
||||
struct FEATURE_DESC_STRUCT {
|
||||
uint16_t NumParams; // total # of params
|
||||
const char *ShortName; // short name for feature
|
||||
const PARAM_DESC *ParamDesc; // array - one per param
|
||||
uint16_t NumParams; // total # of params
|
||||
const char* ShortName; // short name for feature
|
||||
const PARAM_DESC* ParamDesc; // array - one per param
|
||||
};
|
||||
using FEATURE_DESC = FEATURE_DESC_STRUCT *;
|
||||
using FEATURE_DESC = FEATURE_DESC_STRUCT*;
|
||||
|
||||
struct FEATURE_STRUCT {
|
||||
const FEATURE_DESC_STRUCT *Type; // points to description of feature type
|
||||
FLOAT32 Params[1]; // variable size array - params for feature
|
||||
const FEATURE_DESC_STRUCT* Type; // points to description of feature type
|
||||
float Params[1]; // variable size array - params for feature
|
||||
};
|
||||
using FEATURE = FEATURE_STRUCT *;
|
||||
using FEATURE = FEATURE_STRUCT*;
|
||||
|
||||
struct FEATURE_SET_STRUCT {
|
||||
uint16_t NumFeatures; // number of features in set
|
||||
uint16_t MaxNumFeatures; // maximum size of feature set
|
||||
FEATURE Features[1]; // variable size array of features
|
||||
uint16_t NumFeatures; // number of features in set
|
||||
uint16_t MaxNumFeatures; // maximum size of feature set
|
||||
FEATURE Features[1]; // variable size array of features
|
||||
};
|
||||
using FEATURE_SET = FEATURE_SET_STRUCT *;
|
||||
using FEATURE_SET = FEATURE_SET_STRUCT*;
|
||||
|
||||
// A generic character description as a char pointer. In reality, it will be
|
||||
// a pointer to some data structure. Paired feature extractors/matchers need
|
||||
// to agree on the data structure to be used, however, the high level
|
||||
// classifier does not need to know the details of this data structure.
|
||||
using CHAR_FEATURES = char *;
|
||||
using CHAR_FEATURES = char*;
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Macros for defining the parameters of a new features
|
||||
----------------------------------------------------------------------*/
|
||||
#define StartParamDesc(Name) \
|
||||
const PARAM_DESC Name[] = {
|
||||
#define StartParamDesc(Name) const PARAM_DESC Name[] = {
|
||||
#define DefineParam(Circular, NonEssential, Min, Max) \
|
||||
{Circular, \
|
||||
NonEssential, \
|
||||
Min, \
|
||||
Max, \
|
||||
(Max) - (Min), \
|
||||
(((Max) - (Min)) / 2.0), \
|
||||
(((Max) + (Min)) / 2.0)},
|
||||
|
||||
#define DefineParam(Circular, NonEssential, Min, Max) \
|
||||
{Circular, NonEssential, Min, Max, \
|
||||
(Max) - (Min), (((Max) - (Min))/2.0), (((Max) + (Min))/2.0)},
|
||||
|
||||
#define EndParamDesc };
|
||||
#define EndParamDesc };
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Macro for describing a new feature. The parameters of the macro
|
||||
@ -97,9 +97,8 @@ are as follows:
|
||||
|
||||
DefineFeature (Name, NumLinear, NumCircular, ShortName, ParamName)
|
||||
----------------------------------------------------------------------*/
|
||||
#define DefineFeature(Name, NL, NC, SN, PN) \
|
||||
const FEATURE_DESC_STRUCT Name = { \
|
||||
((NL) + (NC)), SN, PN};
|
||||
#define DefineFeature(Name, NL, NC, SN, PN) \
|
||||
const FEATURE_DESC_STRUCT Name = {((NL) + (NC)), SN, PN};
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Generic routines that work for all feature types
|
||||
@ -110,13 +109,13 @@ void FreeFeature(FEATURE Feature);
|
||||
|
||||
void FreeFeatureSet(FEATURE_SET FeatureSet);
|
||||
|
||||
FEATURE NewFeature(const FEATURE_DESC_STRUCT *FeatureDesc);
|
||||
FEATURE NewFeature(const FEATURE_DESC_STRUCT* FeatureDesc);
|
||||
|
||||
FEATURE_SET NewFeatureSet(int NumFeatures);
|
||||
|
||||
FEATURE ReadFeature(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc);
|
||||
FEATURE ReadFeature(FILE* File, const FEATURE_DESC_STRUCT* FeatureDesc);
|
||||
|
||||
FEATURE_SET ReadFeatureSet(FILE *File, const FEATURE_DESC_STRUCT *FeatureDesc);
|
||||
FEATURE_SET ReadFeatureSet(FILE* File, const FEATURE_DESC_STRUCT* FeatureDesc);
|
||||
|
||||
void WriteFeature(FEATURE Feature, STRING* str);
|
||||
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "outfeat.h"
|
||||
|
||||
#include "classify.h"
|
||||
#include "efio.h"
|
||||
#include "featdefs.h"
|
||||
#include "mfoutline.h"
|
||||
#include "ocrfeatures.h"
|
||||
@ -39,17 +38,13 @@ namespace tesseract {
|
||||
* @param Blob blob to extract pico-features from
|
||||
* @return Outline-features for Blob.
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History:
|
||||
* - 11/13/90, DSJ, Created.
|
||||
* - 05/24/91, DSJ, Updated for either char or baseline normalize.
|
||||
*/
|
||||
FEATURE_SET Classify::ExtractOutlineFeatures(TBLOB *Blob) {
|
||||
LIST Outlines;
|
||||
LIST RemainingOutlines;
|
||||
MFOUTLINE Outline;
|
||||
FEATURE_SET FeatureSet;
|
||||
FLOAT32 XScale, YScale;
|
||||
float XScale, YScale;
|
||||
|
||||
FeatureSet = NewFeatureSet (MAX_OUTLINE_FEATURES);
|
||||
if (Blob == nullptr)
|
||||
@ -87,8 +82,6 @@ FEATURE_SET Classify::ExtractOutlineFeatures(TBLOB *Blob) {
|
||||
* @param FeatureSet set to add outline-feature to
|
||||
* @return none (results are placed in FeatureSet)
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: 11/13/90, DSJ, Created.
|
||||
*/
|
||||
void AddOutlineFeatureToSet(FPOINT *Start,
|
||||
FPOINT *End,
|
||||
@ -114,10 +107,6 @@ void AddOutlineFeatureToSet(FPOINT *Start,
|
||||
* @param FeatureSet set of features to add outline-features to
|
||||
* @return none (results are returned in FeatureSet)
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History:
|
||||
* - 11/13/90, DSJ, Created.
|
||||
* - 5/24/91, DSJ, Added hidden edge capability.
|
||||
*/
|
||||
void ConvertToOutlineFeatures(MFOUTLINE Outline, FEATURE_SET FeatureSet) {
|
||||
MFOUTLINE Next;
|
||||
@ -157,16 +146,14 @@ void ConvertToOutlineFeatures(MFOUTLINE Outline, FEATURE_SET FeatureSet) {
|
||||
* @param FeatureSet outline-features to be normalized
|
||||
* @return none (FeatureSet is changed)
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: 11/13/90, DSJ, Created.
|
||||
*/
|
||||
void NormalizeOutlineX(FEATURE_SET FeatureSet) {
|
||||
int i;
|
||||
FEATURE Feature;
|
||||
FLOAT32 Length;
|
||||
FLOAT32 TotalX = 0.0;
|
||||
FLOAT32 TotalWeight = 0.0;
|
||||
FLOAT32 Origin;
|
||||
float Length;
|
||||
float TotalX = 0.0;
|
||||
float TotalWeight = 0.0;
|
||||
float Origin;
|
||||
|
||||
if (FeatureSet->NumFeatures <= 0)
|
||||
return;
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "picofeat.h"
|
||||
|
||||
#include "classify.h"
|
||||
#include "efio.h"
|
||||
#include "featdefs.h"
|
||||
#include "fpoint.h"
|
||||
#include "mfoutline.h"
|
||||
@ -61,15 +60,13 @@ namespace tesseract {
|
||||
* - classify_norm_method normalization method currently specified
|
||||
* @param Blob blob to extract pico-features from
|
||||
* @return Pico-features for Blob.
|
||||
* @note Exceptions: none
|
||||
* @note History: 9/4/90, DSJ, Created.
|
||||
*/
|
||||
FEATURE_SET Classify::ExtractPicoFeatures(TBLOB *Blob) {
|
||||
LIST Outlines;
|
||||
LIST RemainingOutlines;
|
||||
MFOUTLINE Outline;
|
||||
FEATURE_SET FeatureSet;
|
||||
FLOAT32 XScale, YScale;
|
||||
float XScale, YScale;
|
||||
|
||||
FeatureSet = NewFeatureSet(MAX_PICO_FEATURES);
|
||||
Outlines = ConvertBlob(Blob);
|
||||
@ -103,15 +100,13 @@ FEATURE_SET Classify::ExtractPicoFeatures(TBLOB *Blob) {
|
||||
* @param End ending point of pico-feature
|
||||
* @param FeatureSet set to add pico-feature to
|
||||
* @return none (results are placed in FeatureSet)
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Apr 30 15:44:34 1991, DSJ, Created.
|
||||
*/
|
||||
void ConvertSegmentToPicoFeat(FPOINT *Start,
|
||||
FPOINT *End,
|
||||
FEATURE_SET FeatureSet) {
|
||||
FEATURE Feature;
|
||||
FLOAT32 Angle;
|
||||
FLOAT32 Length;
|
||||
float Angle;
|
||||
float Length;
|
||||
int NumFeatures;
|
||||
FPOINT Center;
|
||||
FPOINT Delta;
|
||||
@ -157,8 +152,6 @@ void ConvertSegmentToPicoFeat(FPOINT *Start,
|
||||
* @param Outline outline to extract micro-features from
|
||||
* @param FeatureSet set of features to add pico-features to
|
||||
* @return none (results are returned in FeatureSet)
|
||||
* @note Exceptions: none
|
||||
* @note History: 4/30/91, DSJ, Adapted from ConvertToPicoFeatures().
|
||||
*/
|
||||
void ConvertToPicoFeatures2(MFOUTLINE Outline, FEATURE_SET FeatureSet) {
|
||||
MFOUTLINE Next;
|
||||
@ -198,13 +191,11 @@ void ConvertToPicoFeatures2(MFOUTLINE Outline, FEATURE_SET FeatureSet) {
|
||||
* @param FeatureSet pico-features to be normalized
|
||||
* @return none (FeatureSet is changed)
|
||||
* @note Globals: none
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Sep 4 16:50:08 1990, DSJ, Created.
|
||||
*/
|
||||
void NormalizePicoX(FEATURE_SET FeatureSet) {
|
||||
int i;
|
||||
FEATURE Feature;
|
||||
FLOAT32 Origin = 0.0;
|
||||
float Origin = 0.0;
|
||||
|
||||
for (i = 0; i < FeatureSet->NumFeatures; i++) {
|
||||
Feature = FeatureSet->Features[i];
|
||||
@ -224,8 +215,6 @@ namespace tesseract {
|
||||
* @param blob blob to extract features from
|
||||
* @param fx_info
|
||||
* @return Integer character-normalized features for blob.
|
||||
* @note Exceptions: none
|
||||
* @note History: 8/8/2011, rays, Created.
|
||||
*/
|
||||
FEATURE_SET Classify::ExtractIntCNFeatures(
|
||||
const TBLOB& blob, const INT_FX_RESULT_STRUCT& fx_info) {
|
||||
@ -256,8 +245,6 @@ FEATURE_SET Classify::ExtractIntCNFeatures(
|
||||
* @param blob blob to extract features from
|
||||
* @param fx_info
|
||||
* @return Geometric (top/bottom/width) features for blob.
|
||||
* @note Exceptions: none
|
||||
* @note History: 8/8/2011, rays, Created.
|
||||
*/
|
||||
FEATURE_SET Classify::ExtractIntGeoFeatures(
|
||||
const TBLOB& blob, const INT_FX_RESULT_STRUCT& fx_info) {
|
||||
|
@ -1,10 +1,10 @@
|
||||
/******************************************************************************
|
||||
** Filename: picofeat.h
|
||||
** Purpose: Definition of pico features.
|
||||
** Author: Dan Johnson
|
||||
** History: 9/4/90, DSJ, Created.
|
||||
** Filename: picofeat.h
|
||||
** Purpose: Definition of pico features.
|
||||
** Author: Dan Johnson
|
||||
** History: 9/4/90, DSJ, Created.
|
||||
**
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
@ -15,8 +15,9 @@
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
******************************************************************************/
|
||||
#ifndef PICOFEAT_H
|
||||
#define PICOFEAT_H
|
||||
|
||||
#ifndef PICOFEAT_H
|
||||
#define PICOFEAT_H
|
||||
|
||||
/**----------------------------------------------------------------------------
|
||||
Include Files and Type Defines
|
||||
@ -33,16 +34,14 @@ enum IntParams {
|
||||
|
||||
// Enum for the order/type of params in GeoFeatDesc.
|
||||
enum GeoParams {
|
||||
GeoBottom, // Bounding box bottom in baseline space (0-255).
|
||||
GeoTop, // Bounding box top in baseline space (0-255).
|
||||
GeoWidth, // Bounding box width in baseline space (0-255).
|
||||
GeoBottom, // Bounding box bottom in baseline space (0-255).
|
||||
GeoTop, // Bounding box top in baseline space (0-255).
|
||||
GeoWidth, // Bounding box width in baseline space (0-255).
|
||||
|
||||
GeoCount // Number of geo features.
|
||||
GeoCount // Number of geo features.
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{ PicoFeatY, PicoFeatDir, PicoFeatX }
|
||||
PICO_FEAT_PARAM_NAME;
|
||||
typedef enum { PicoFeatY, PicoFeatDir, PicoFeatX } PICO_FEAT_PARAM_NAME;
|
||||
|
||||
#define MAX_PICO_FEATURES (1000)
|
||||
|
||||
@ -52,14 +51,14 @@ PICO_FEAT_PARAM_NAME;
|
||||
|
||||
extern double_VAR_H(classify_pico_feature_length, 0.05, "Pico Feature Length");
|
||||
|
||||
|
||||
/**----------------------------------------------------------------------------
|
||||
Public Function Prototypes
|
||||
----------------------------------------------------------------------------**/
|
||||
#define GetPicoFeatureLength() (PicoFeatureLength)
|
||||
#define GetPicoFeatureLength() (PicoFeatureLength)
|
||||
|
||||
/**----------------------------------------------------------------------------
|
||||
Global Data Definitions and Declarations
|
||||
----------------------------------------------------------------------------**/
|
||||
extern TESS_API FLOAT32 PicoFeatureLength;
|
||||
extern TESS_API float PicoFeatureLength;
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* -*-C-*-
|
||||
********************************************************************************
|
||||
******************************************************************************
|
||||
*
|
||||
* File: protos.cpp (Formerly protos.c)
|
||||
* Description:
|
||||
@ -21,12 +21,11 @@
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
*
|
||||
*********************************************************************************/
|
||||
*****************************************************************************/
|
||||
/*----------------------------------------------------------------------
|
||||
I n c l u d e s
|
||||
----------------------------------------------------------------------*/
|
||||
#include "protos.h"
|
||||
#include "const.h"
|
||||
#include "emalloc.h"
|
||||
#include "callcpp.h"
|
||||
#include "tprintf.h"
|
||||
@ -137,9 +136,9 @@ int AddProtoToClass(CLASS_TYPE Class) {
|
||||
* @param Class The class to add to
|
||||
* @param Config FIXME
|
||||
*/
|
||||
FLOAT32 ClassConfigLength(CLASS_TYPE Class, BIT_VECTOR Config) {
|
||||
float ClassConfigLength(CLASS_TYPE Class, BIT_VECTOR Config) {
|
||||
int16_t Pid;
|
||||
FLOAT32 TotalLength = 0;
|
||||
float TotalLength = 0;
|
||||
|
||||
for (Pid = 0; Pid < Class->NumProtos; Pid++) {
|
||||
if (test_bit (Config, Pid)) {
|
||||
@ -158,9 +157,9 @@ FLOAT32 ClassConfigLength(CLASS_TYPE Class, BIT_VECTOR Config) {
|
||||
*
|
||||
* @param Class The class to use
|
||||
*/
|
||||
FLOAT32 ClassProtoLength(CLASS_TYPE Class) {
|
||||
float ClassProtoLength(CLASS_TYPE Class) {
|
||||
int16_t Pid;
|
||||
FLOAT32 TotalLength = 0;
|
||||
float TotalLength = 0;
|
||||
|
||||
for (Pid = 0; Pid < Class->NumProtos; Pid++) {
|
||||
TotalLength += (ProtoIn (Class, Pid))->Length;
|
||||
@ -194,9 +193,9 @@ void CopyProto(PROTO Src, PROTO Dest) {
|
||||
* Fill in Protos A, B, C fields based on the X, Y, Angle fields.
|
||||
**********************************************************************/
|
||||
void FillABC(PROTO Proto) {
|
||||
FLOAT32 Slope, Intercept, Normalizer;
|
||||
float Slope, Intercept, Normalizer;
|
||||
|
||||
Slope = tan (Proto->Angle * 2.0 * PI);
|
||||
Slope = tan(Proto->Angle * 2.0 * M_PI);
|
||||
Intercept = Proto->Y - Slope * Proto->X;
|
||||
Normalizer = 1.0 / sqrt (Slope * Slope + 1.0);
|
||||
Proto->A = Slope * Normalizer;
|
||||
@ -275,6 +274,6 @@ void PrintProtos(CLASS_TYPE Class) {
|
||||
PrintProto (ProtoIn (Class, Pid));
|
||||
cprintf ("\t");
|
||||
PrintProtoLine (ProtoIn (Class, Pid));
|
||||
new_line();
|
||||
tprintf("\n");
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* -*-C-*-
|
||||
********************************************************************************
|
||||
******************************************************************************
|
||||
*
|
||||
* File: protos.h (Formerly protos.h)
|
||||
* File: protos.h
|
||||
* Description:
|
||||
* Author: Mark Seaman, SW Productivity
|
||||
* Created: Fri Oct 16 14:37:00 1987
|
||||
@ -21,7 +21,8 @@
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
*
|
||||
*********************************************************************************/
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef PROTOS_H
|
||||
#define PROTOS_H
|
||||
|
||||
@ -29,33 +30,34 @@
|
||||
I n c l u d e s
|
||||
----------------------------------------------------------------------*/
|
||||
#include "bitvec.h"
|
||||
#include "cutil.h"
|
||||
#include "params.h"
|
||||
#include "unichar.h"
|
||||
#include "unicity_table.h"
|
||||
#include "params.h"
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
T y p e s
|
||||
----------------------------------------------------------------------*/
|
||||
using CONFIGS = BIT_VECTOR *;
|
||||
using CONFIGS = BIT_VECTOR*;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FLOAT32 A;
|
||||
FLOAT32 B;
|
||||
FLOAT32 C;
|
||||
FLOAT32 X;
|
||||
FLOAT32 Y;
|
||||
FLOAT32 Angle;
|
||||
FLOAT32 Length;
|
||||
typedef struct {
|
||||
float A;
|
||||
float B;
|
||||
float C;
|
||||
float X;
|
||||
float Y;
|
||||
float Angle;
|
||||
float Length;
|
||||
} PROTO_STRUCT;
|
||||
using PROTO = PROTO_STRUCT *;
|
||||
using PROTO = PROTO_STRUCT*;
|
||||
|
||||
struct CLASS_STRUCT {
|
||||
CLASS_STRUCT()
|
||||
: NumProtos(0), MaxNumProtos(0), Prototypes(nullptr),
|
||||
NumConfigs(0), MaxNumConfigs(0), Configurations(nullptr) {
|
||||
}
|
||||
: NumProtos(0),
|
||||
MaxNumProtos(0),
|
||||
Prototypes(nullptr),
|
||||
NumConfigs(0),
|
||||
MaxNumConfigs(0),
|
||||
Configurations(nullptr) {}
|
||||
int16_t NumProtos;
|
||||
int16_t MaxNumProtos;
|
||||
PROTO Prototypes;
|
||||
@ -64,15 +66,15 @@ struct CLASS_STRUCT {
|
||||
CONFIGS Configurations;
|
||||
UnicityTableEqEq<int> font_set;
|
||||
};
|
||||
using CLASS_TYPE = CLASS_STRUCT *;
|
||||
using CLASSES = CLASS_STRUCT *;
|
||||
using CLASS_TYPE = CLASS_STRUCT*;
|
||||
using CLASSES = CLASS_STRUCT*;
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
C o n s t a n t s
|
||||
----------------------------------------------------------------------*/
|
||||
#define NUMBER_OF_CLASSES MAX_NUM_CLASSES
|
||||
#define Y_OFFSET -40.0
|
||||
#define FEATURE_SCALE 100.0
|
||||
#define NUMBER_OF_CLASSES MAX_NUM_CLASSES
|
||||
#define Y_OFFSET -40.0
|
||||
#define FEATURE_SCALE 100.0
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
V a r i a b l e s
|
||||
@ -90,8 +92,7 @@ extern STRING_VAR_H(classify_training_file, "MicroFeatures", "Training file");
|
||||
* Set a single proto bit in the specified configuration.
|
||||
*/
|
||||
|
||||
#define AddProtoToConfig(Pid,Config) \
|
||||
(SET_BIT (Config, Pid))
|
||||
#define AddProtoToConfig(Pid, Config) (SET_BIT(Config, Pid))
|
||||
|
||||
/**
|
||||
* RemoveProtoFromConfig
|
||||
@ -99,8 +100,7 @@ extern STRING_VAR_H(classify_training_file, "MicroFeatures", "Training file");
|
||||
* Clear a single proto bit in the specified configuration.
|
||||
*/
|
||||
|
||||
#define RemoveProtoFromConfig(Pid,Config) \
|
||||
(reset_bit (Config, Pid))
|
||||
#define RemoveProtoFromConfig(Pid, Config) (reset_bit(Config, Pid))
|
||||
|
||||
/**
|
||||
* ClassOfChar
|
||||
@ -108,10 +108,8 @@ extern STRING_VAR_H(classify_training_file, "MicroFeatures", "Training file");
|
||||
* Return the class of a particular ASCII character value.
|
||||
*/
|
||||
|
||||
#define ClassOfChar(Char) \
|
||||
((TrainingData [Char].NumProtos) ? \
|
||||
(& TrainingData [Char]) : \
|
||||
NO_CLASS)
|
||||
#define ClassOfChar(Char) \
|
||||
((TrainingData[Char].NumProtos) ? (&TrainingData[Char]) : NO_CLASS)
|
||||
|
||||
/**
|
||||
* ProtoIn
|
||||
@ -120,8 +118,7 @@ extern STRING_VAR_H(classify_training_file, "MicroFeatures", "Training file");
|
||||
* pointer to it (type PROTO).
|
||||
*/
|
||||
|
||||
#define ProtoIn(Class,Pid) \
|
||||
(& (Class)->Prototypes [Pid])
|
||||
#define ProtoIn(Class, Pid) (&(Class)->Prototypes[Pid])
|
||||
|
||||
/**
|
||||
* PrintProto
|
||||
@ -130,13 +127,9 @@ extern STRING_VAR_H(classify_training_file, "MicroFeatures", "Training file");
|
||||
* type 'PROTO'.
|
||||
*/
|
||||
|
||||
#define PrintProto(Proto) \
|
||||
(tprintf("X=%4.2f, Y=%4.2f, Length=%4.2f, Angle=%4.2f", \
|
||||
Proto->X, \
|
||||
Proto->Y, \
|
||||
Proto->Length, \
|
||||
Proto->Angle)) \
|
||||
|
||||
#define PrintProto(Proto) \
|
||||
(tprintf("X=%4.2f, Y=%4.2f, Length=%4.2f, Angle=%4.2f", Proto->X, Proto->Y, \
|
||||
Proto->Length, Proto->Angle))
|
||||
|
||||
/**
|
||||
* PrintProtoLine
|
||||
@ -145,11 +138,8 @@ extern STRING_VAR_H(classify_training_file, "MicroFeatures", "Training file");
|
||||
* type 'PROTO'.
|
||||
*/
|
||||
|
||||
#define PrintProtoLine(Proto) \
|
||||
(cprintf ("A=%4.2f, B=%4.2f, C=%4.2f", \
|
||||
Proto->A, \
|
||||
Proto->B, \
|
||||
Proto->C)) \
|
||||
#define PrintProtoLine(Proto) \
|
||||
(cprintf("A=%4.2f, B=%4.2f, C=%4.2f", Proto->A, Proto->B, Proto->C))
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
F u n c t i o n s
|
||||
@ -158,9 +148,9 @@ int AddConfigToClass(CLASS_TYPE Class);
|
||||
|
||||
int AddProtoToClass(CLASS_TYPE Class);
|
||||
|
||||
FLOAT32 ClassConfigLength(CLASS_TYPE Class, BIT_VECTOR Config);
|
||||
float ClassConfigLength(CLASS_TYPE Class, BIT_VECTOR Config);
|
||||
|
||||
FLOAT32 ClassProtoLength(CLASS_TYPE Class);
|
||||
float ClassProtoLength(CLASS_TYPE Class);
|
||||
|
||||
void CopyProto(PROTO Src, PROTO Dest);
|
||||
|
||||
|
@ -297,8 +297,8 @@ Pix* TrainingSample::RenderToPix(const UNICHARSET* unicharset) const {
|
||||
for (int f = 0; f < num_features_; ++f) {
|
||||
int start_x = features_[f].X;
|
||||
int start_y = kIntFeatureExtent - features_[f].Y;
|
||||
double dx = cos((features_[f].Theta / 256.0) * 2.0 * PI - PI);
|
||||
double dy = -sin((features_[f].Theta / 256.0) * 2.0 * PI - PI);
|
||||
double dx = cos((features_[f].Theta / 256.0) * 2.0 * M_PI - M_PI);
|
||||
double dy = -sin((features_[f].Theta / 256.0) * 2.0 * M_PI - M_PI);
|
||||
for (int i = 0; i <= 5; ++i) {
|
||||
int x = static_cast<int>(start_x + dx * i);
|
||||
int y = static_cast<int>(start_y + dy * i);
|
||||
|
@ -8,13 +8,13 @@ AM_CPPFLAGS += -DTESS_EXPORTS \
|
||||
endif
|
||||
|
||||
noinst_HEADERS = \
|
||||
bitvec.h callcpp.h const.h cutil.h cutil_class.h danerror.h efio.h \
|
||||
bitvec.h callcpp.h cutil.h cutil_class.h \
|
||||
emalloc.h globals.h \
|
||||
oldlist.h structures.h
|
||||
|
||||
noinst_LTLIBRARIES = libtesseract_cutil.la
|
||||
|
||||
libtesseract_cutil_la_SOURCES = \
|
||||
bitvec.cpp callcpp.cpp cutil.cpp cutil_class.cpp danerror.cpp efio.cpp \
|
||||
bitvec.cpp callcpp.cpp cutil_class.cpp \
|
||||
emalloc.cpp \
|
||||
oldlist.cpp structures.cpp
|
||||
|
@ -41,8 +41,6 @@
|
||||
* @param NewNumBits new size of bit vector
|
||||
*
|
||||
* @return New expanded bit vector.
|
||||
* @note Exceptions: none
|
||||
* @note History: Fri Nov 16 10:11:16 1990, DSJ, Created.
|
||||
*/
|
||||
BIT_VECTOR ExpandBitVector(BIT_VECTOR Vector, int NewNumBits) {
|
||||
return ((BIT_VECTOR) Erealloc(Vector,
|
||||
@ -63,8 +61,6 @@ void FreeBitVector(BIT_VECTOR BitVector) {
|
||||
*
|
||||
* @param BitVector bit vector to be freed
|
||||
*
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Oct 23 16:46:09 1990, DSJ, Created.
|
||||
*/
|
||||
if (BitVector) {
|
||||
Efree(BitVector);
|
||||
@ -83,8 +79,6 @@ void FreeBitVector(BIT_VECTOR BitVector) {
|
||||
* @param NumBits number of bits in new bit vector
|
||||
*
|
||||
* @return New bit vector.
|
||||
* @note Exceptions: none
|
||||
* @note History: Tue Oct 23 16:51:27 1990, DSJ, Created.
|
||||
*/
|
||||
BIT_VECTOR NewBitVector(int NumBits) {
|
||||
return ((BIT_VECTOR) Emalloc(sizeof(uint32_t) *
|
||||
|
@ -1,23 +0,0 @@
|
||||
/**************************************************************************
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
** http://www.apache.org/licenses/LICENSE-2.0
|
||||
** Unless required by applicable law or agreed to in writing, software
|
||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef CONST_H
|
||||
#define CONST_H
|
||||
|
||||
/*This file contains constants which are global to the entire system*/
|
||||
#define SPLINESIZE 23 // max spline parts to a line
|
||||
|
||||
#define PI 3.14159265359 // pi
|
||||
|
||||
#define EDGEPTFLAGS 4 // concavity,length etc.
|
||||
|
||||
#endif
|
@ -1,100 +0,0 @@
|
||||
/* -*-C-*-
|
||||
********************************************************************************
|
||||
*
|
||||
* File: cutil.cpp
|
||||
* Description: General utility functions
|
||||
* Author: Mark Seaman, SW Productivity
|
||||
* Created: Fri Oct 16 14:37:00 1987
|
||||
* Modified: Wed Jun 6 16:29:17 1990 (Mark Seaman) marks@hpgrlt
|
||||
* Language: C
|
||||
* Package: N/A
|
||||
* Status: Reusable Software Component
|
||||
*
|
||||
* (c) Copyright 1987, Hewlett-Packard Company.
|
||||
** Licensed under the Apache License, Version 2.0 (the "License");
|
||||
** you may not use this file except in compliance with the License.
|
||||
** You may obtain a copy of the License at
|
||||
** http://www.apache.org/licenses/LICENSE-2.0
|
||||
** Unless required by applicable law or agreed to in writing, software
|
||||
** distributed under the License is distributed on an "AS IS" BASIS,
|
||||
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
** See the License for the specific language governing permissions and
|
||||
** limitations under the License.
|
||||
*
|
||||
********************************************************************************
|
||||
Revision 1.1 2007/02/02 23:39:07 theraysmith
|
||||
Fixed portability issues
|
||||
|
||||
Revision 1.1.1.1 2004/02/20 19:39:06 slumos
|
||||
Import original HP distribution
|
||||
|
||||
* Revision 1.3 90/03/06 15:39:10 15:39:10 marks (Mark Seaman)
|
||||
* Look for correct file of <malloc.h> or <stdlib.h>
|
||||
*
|
||||
* Revision 1.2 90/01/15 13:02:13 13:02:13 marks (Mark Seaman)
|
||||
* Added memory allocator (*allocate) and (*deallocate)
|
||||
*
|
||||
* Revision 1.1 89/10/09 14:58:29 14:58:29 marks (Mark Seaman)
|
||||
* Initial revision
|
||||
**/
|
||||
|
||||
#include "cutil.h"
|
||||
#include "tprintf.h"
|
||||
#include "callcpp.h"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#define RESET_COUNT 2000
|
||||
|
||||
/**********************************************************************
|
||||
* long_rand
|
||||
*
|
||||
* Return a long random number whose value is less than limit. Do this
|
||||
* by calling the standard cheepo random number generator and resetting
|
||||
* it pretty often.
|
||||
**********************************************************************/
|
||||
long long_rand(long limit) {
|
||||
#if RAND_MAX < 0x1000000
|
||||
static long seed;
|
||||
|
||||
long num;
|
||||
num = (long) rand () << 16;
|
||||
num |= rand () & 0xffff;
|
||||
seed ^= num;
|
||||
long result = num % limit;
|
||||
while (result < 0) {
|
||||
result += limit;
|
||||
}
|
||||
return result;
|
||||
#else
|
||||
return (long)((double)limit * rand()/(RAND_MAX + 1.0));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* open_file
|
||||
*
|
||||
* Open a file for reading or writing. If the file name parameter is
|
||||
* nullptr use stdin (or stdout) for the file. If the file can not be
|
||||
* opened then call the error routine.
|
||||
**********************************************************************/
|
||||
FILE *open_file(const char *filename, const char *mode) {
|
||||
FILE *thisfile = nullptr;
|
||||
if ((thisfile = fopen (filename, mode)) == nullptr) {
|
||||
tprintf ("Could not open file, %s\n", filename);
|
||||
exit (1);
|
||||
}
|
||||
return (thisfile);
|
||||
}
|
||||
|
||||
/// Check whether the file exists
|
||||
bool exists_file(const char *filename) {
|
||||
bool exists = false;
|
||||
FILE *f = nullptr;
|
||||
if ((f = fopen(filename, "rb")) != nullptr) {
|
||||
fclose(f);
|
||||
exists = true;
|
||||
}
|
||||
return exists;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user