2007-03-08 04:03:40 +08:00
|
|
|
/* -*-C-*-
|
|
|
|
********************************************************************************
|
|
|
|
*
|
|
|
|
* File: wordclass.c (Formerly wordclass.c)
|
|
|
|
* Description: Word classifier
|
|
|
|
* Author: Mark Seaman, OCR Technology
|
|
|
|
* Created: Tue Jan 30 14:03:25 1990
|
|
|
|
* Modified: Fri Jul 12 16:03:06 1991 (Mark Seaman) marks@hpgrlt
|
|
|
|
* Language: C
|
|
|
|
* Package: N/A
|
|
|
|
* Status: Experimental (Do Not Distribute)
|
|
|
|
*
|
|
|
|
* (c) Copyright 1990, 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.
|
|
|
|
*
|
|
|
|
*********************************************************************************/
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
I N C L U D E S
|
|
|
|
----------------------------------------------------------------------*/
|
|
|
|
#include <assert.h>
|
2013-09-23 23:26:50 +08:00
|
|
|
#include <stdio.h>
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
#include "associate.h"
|
|
|
|
#include "render.h"
|
|
|
|
#include "callcpp.h"
|
2009-07-11 10:46:01 +08:00
|
|
|
#include "wordrec.h"
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2010-09-30 23:53:40 +08:00
|
|
|
// Include automatically generated configuration file if running autoconf.
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config_auto.h"
|
|
|
|
#endif
|
|
|
|
|
2007-03-08 04:03:40 +08:00
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
F u n c t i o n s
|
|
|
|
----------------------------------------------------------------------*/
|
2010-07-27 21:23:23 +08:00
|
|
|
namespace tesseract {
|
|
|
|
/**
|
|
|
|
* @name classify_blob
|
2007-03-08 04:03:40 +08:00
|
|
|
*
|
|
|
|
* Classify the this blob if it is not already recorded in the match
|
2009-07-11 10:46:01 +08:00
|
|
|
* table. Attempt to recognize this blob as a character. The recognition
|
|
|
|
* rating for this blob will be stored as a part of the blob. This value
|
|
|
|
* will also be returned to the caller.
|
2010-07-27 21:23:23 +08:00
|
|
|
* @param blob Current blob
|
|
|
|
* @param string The string to display in ScrollView
|
|
|
|
* @param color The colour to use when displayed with ScrollView
|
|
|
|
*/
|
2013-09-23 23:26:50 +08:00
|
|
|
BLOB_CHOICE_LIST *Wordrec::classify_blob(TBLOB *blob,
|
2012-02-02 11:01:38 +08:00
|
|
|
const char *string, C_COL color,
|
|
|
|
BlamerBundle *blamer_bundle) {
|
2007-03-08 04:03:40 +08:00
|
|
|
#ifndef GRAPHICS_DISABLED
|
2009-07-11 10:46:01 +08:00
|
|
|
if (wordrec_display_all_blobs)
|
2007-07-18 09:15:07 +08:00
|
|
|
display_blob(blob, color);
|
2007-03-08 04:03:40 +08:00
|
|
|
#endif
|
2013-09-23 23:26:50 +08:00
|
|
|
// TODO(rays) collapse with call_matcher and move all to wordrec.cpp.
|
|
|
|
BLOB_CHOICE_LIST* choices = call_matcher(blob);
|
|
|
|
// If a blob with the same bounding box as one of the truth character
|
|
|
|
// bounding boxes is not classified as the corresponding truth character
|
|
|
|
// blame character classifier for incorrect answer.
|
|
|
|
if (blamer_bundle != NULL) {
|
|
|
|
blamer_bundle->BlameClassifier(getDict().getUnicharset(),
|
|
|
|
blob->bounding_box(),
|
|
|
|
*choices,
|
|
|
|
wordrec_debug_blamer);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2013-09-23 23:26:50 +08:00
|
|
|
#ifndef GRAPHICS_DISABLED
|
2010-11-24 02:34:14 +08:00
|
|
|
if (classify_debug_level && string)
|
2009-07-11 10:46:01 +08:00
|
|
|
print_ratings_list(string, choices, getDict().getUnicharset());
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2009-07-11 10:46:01 +08:00
|
|
|
if (wordrec_blob_pause)
|
2007-07-18 09:15:07 +08:00
|
|
|
window_wait(blob_window);
|
2007-03-08 04:03:40 +08:00
|
|
|
#endif
|
|
|
|
|
2013-09-23 23:26:50 +08:00
|
|
|
return choices;
|
2009-07-11 10:46:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace tesseract;
|