Revise after code review

This commit is contained in:
James R. Barlow 2016-12-08 15:08:48 -08:00
parent fb7298e82e
commit 56b6f061cd
4 changed files with 35 additions and 42 deletions

View File

@ -1891,7 +1891,15 @@ char* TessBaseAPI::GetUNLVText() {
return result; return result;
} }
bool TessBaseAPI::DetectOrientationScript(int& orient_deg, float& orient_conf, std::string& script, float& script_conf) { /**
* Detect the orientation of the input image and apparent script (alphabet).
* orient_deg is the detected clockwise rotation of the input image in degrees (0, 90, 180, 270)
* orient_conf is the confidence (15.0 is reasonably confident)
* script_name is an ASCII string, the name of the script, e.g. "Latin"
* script_conf is confidence level in the script
* Returns true on success and writes values to each parameter as an output
*/
bool TessBaseAPI::DetectOrientationScript(int* orient_deg, float* orient_conf, const char** script_name, float* script_conf) {
OSResults osr; OSResults osr;
bool osd = DetectOS(&osr); bool osd = DetectOS(&osr);
@ -1901,15 +1909,21 @@ bool TessBaseAPI::DetectOrientationScript(int& orient_deg, float& orient_conf, s
int orient_id = osr.best_result.orientation_id; int orient_id = osr.best_result.orientation_id;
int script_id = osr.get_best_script(orient_id); int script_id = osr.get_best_script(orient_id);
orient_conf = osr.best_result.oconfidence; if (orient_conf)
script_conf = osr.best_result.sconfidence; *orient_conf = osr.best_result.oconfidence;
const char* script_name = if (orient_deg)
*orient_deg = orient_id * 90; // convert quadrant to degrees
if (script_name) {
const char* script =
osr.unicharset->get_script_from_script_id(script_id); osr.unicharset->get_script_from_script_id(script_id);
// clockwise orientation of the input image, in degrees *script_name = script;
orient_deg = orient_id * 90; }
if (script_conf)
*script_conf = osr.best_result.sconfidence;
script = script_name;
return true; return true;
} }
@ -1921,10 +1935,10 @@ bool TessBaseAPI::DetectOrientationScript(int& orient_deg, float& orient_conf, s
char* TessBaseAPI::GetOsdText(int page_number) { char* TessBaseAPI::GetOsdText(int page_number) {
int orient_deg; int orient_deg;
float orient_conf; float orient_conf;
std::string script_name; const char* script_name;
float script_conf; float script_conf;
if (!DetectOrientationScript(orient_deg, orient_conf, script_name, script_conf)) if (!DetectOrientationScript(&orient_deg, &orient_conf, &script_name, &script_conf))
return NULL; return NULL;
// clockwise rotation needed to make the page upright // clockwise rotation needed to make the page upright
@ -1939,7 +1953,7 @@ char* TessBaseAPI::GetOsdText(int page_number) {
"Orientation confidence: %.2f\n" "Orientation confidence: %.2f\n"
"Script: %s\n" "Script: %s\n"
"Script confidence: %.2f\n", "Script confidence: %.2f\n",
page_number, orient_deg, rotate, orient_conf, script_name.c_str(), page_number, orient_deg, rotate, orient_conf, script_name,
script_conf); script_conf);
return osd_buf; return osd_buf;

View File

@ -26,7 +26,6 @@
(patch)) (patch))
#include <stdio.h> #include <stdio.h>
#include <string>
// To avoid collision with other typenames include the ABSOLUTE MINIMUM // To avoid collision with other typenames include the ABSOLUTE MINIMUM
// complexity of includes here. Use forward declarations wherever possible // complexity of includes here. Use forward declarations wherever possible
// and hide includes of complex types in baseapi.cpp. // and hide includes of complex types in baseapi.cpp.
@ -621,12 +620,13 @@ class TESS_API TessBaseAPI {
/** /**
* Detect the orientation of the input image and apparent script (alphabet). * Detect the orientation of the input image and apparent script (alphabet).
* orient_deg is the detected clockwise rotation of the input image * orient_deg is the detected clockwise rotation of the input image in degrees (0, 90, 180, 270)
* orient_conf is the confidence (15.0 is reasonable) * orient_conf is the confidence (15.0 is reasonably confident)
* script is an ASCII string, the name of the script, e.g. "Latin" * script_name is an ASCII string, the name of the script, e.g. "Latin"
* script_conf is confidence level in the script * script_conf is confidence level in the script
* Returns true on success and writes values to each parameter as an output
*/ */
bool DetectOrientationScript(int& orient_deg, float& orient_conf, std::string& script, float& script_conf); bool DetectOrientationScript(int* orient_deg, float* orient_conf, const char** script_name, float* script_conf);
/** /**
* The recognized text is returned as a char* which is coded * The recognized text is returned as a char* which is coded

View File

@ -541,32 +541,12 @@ TESS_API BOOL TESS_CALL TessBaseAPIDetectOS(TessBaseAPI* handle, OSResults* resu
return FALSE; // Unsafe ABI, return FALSE always return FALSE; // Unsafe ABI, return FALSE always
} }
TESS_API BOOL TESS_CALL TessBaseAPIDetectOrientationScript(TessBaseAPI* handle, char** best_script_name, TESS_API BOOL TESS_CALL TessBaseAPIDetectOrientationScript(TessBaseAPI* handle,
int* best_orientation_deg, float* script_confidence, int* orient_deg, float* orient_conf, const char** script_name, float* script_conf)
float* orientation_confidence)
{ {
int orient_deg; bool success;
float orient_conf;
std::string script_name;
float script_conf;
BOOL success;
success = handle->DetectOrientationScript(orient_deg, orient_conf, script_name, script_conf); success = handle->DetectOrientationScript(orient_deg, orient_conf, script_name, script_conf);
if (!success) return (BOOL)success;
return FALSE;
if (best_script_name) {
*best_script_name = new char [script_name.length() + 1];
strcpy(*best_script_name, script_name.c_str());
}
if (best_orientation_deg)
*best_orientation_deg = orient_deg;
if (script_confidence)
*script_confidence = script_conf;
if (orientation_confidence)
*orientation_confidence = orient_conf;
return TRUE;
} }

View File

@ -287,9 +287,8 @@ TESS_API void TESS_CALL TessBaseAPISetProbabilityInContextFunc(TessBaseAPI* han
TESS_API void TESS_CALL TessBaseAPISetFillLatticeFunc(TessBaseAPI* handle, TessFillLatticeFunc f); TESS_API void TESS_CALL TessBaseAPISetFillLatticeFunc(TessBaseAPI* handle, TessFillLatticeFunc f);
// Call TessDeleteText(*best_script_name) to free memory allocated by this function // Call TessDeleteText(*best_script_name) to free memory allocated by this function
TESS_API BOOL TESS_CALL TessBaseAPIDetectOrientationScript(TessBaseAPI* handle, char** best_script_name, TESS_API BOOL TESS_CALL TessBaseAPIDetectOrientationScript(TessBaseAPI* handle,
int* best_orientation_deg, float* script_confidence, int* orient_deg, float* orient_conf, const char **script_name, float* script_conf);
float* orientation_confidence);
TESS_API void TESS_CALL TessBaseAPIGetFeaturesForBlob(TessBaseAPI* handle, TBLOB* blob, INT_FEATURE_STRUCT* int_features, TESS_API void TESS_CALL TessBaseAPIGetFeaturesForBlob(TessBaseAPI* handle, TBLOB* blob, INT_FEATURE_STRUCT* int_features,
int* num_features, int* FeatureOutlineIndex); int* num_features, int* FeatureOutlineIndex);