Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
OpenCL: Remove PERF_COUNT framework
It was rarely used, but added a lot of code and an unconditional
dependency on openclwrapper.h.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Feb 9, 2019
1 parent ec8f02c commit d42413d
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 213 deletions.
15 changes: 3 additions & 12 deletions src/api/baseapi.cpp
Expand Up @@ -70,7 +70,9 @@
#include "mutableiterator.h" // for MutableIterator
#include "normalis.h" // for kBlnBaselineOffset, kBlnXHeight
#include "ocrclass.h" // for ETEXT_DESC
#include "openclwrapper.h" // for PERF_COUNT_END, PERF_COUNT_START, PERF...
#if defined(USE_OPENCL)
#include "openclwrapper.h" // for OpenclDevice
#endif
#include "osdetect.h" // for OSResults, OSBestResult, OrientationId...
#include "pageres.h" // for PAGE_RES_IT, WERD_RES, PAGE_RES, CR_DE...
#include "paragraphs.h" // for DetectParagraphs
Expand Down Expand Up @@ -360,7 +362,6 @@ int TessBaseAPI::Init(const char* data, int data_size, const char* language,
const GenericVector<STRING>* vars_vec,
const GenericVector<STRING>* vars_values,
bool set_only_non_debug_params, FileReader reader) {
PERF_COUNT_START("TessBaseAPI::Init")
// Default language is "eng".
if (language == nullptr) language = "eng";
STRING datapath = data_size == 0 ? data : language;
Expand All @@ -376,12 +377,10 @@ int TessBaseAPI::Init(const char* data, int data_size, const char* language,
delete tesseract_;
tesseract_ = nullptr;
}
// PERF_COUNT_SUB("delete tesseract_")
#ifdef USE_OPENCL
OpenclDevice od;
od.InitEnv();
#endif
PERF_COUNT_SUB("OD::InitEnv()")
bool reset_classifier = true;
if (tesseract_ == nullptr) {
reset_classifier = false;
Expand All @@ -400,7 +399,6 @@ int TessBaseAPI::Init(const char* data, int data_size, const char* language,
}
}

PERF_COUNT_SUB("update tesseract_")
// Update datapath and language requested for the last valid initialization.
if (datapath_ == nullptr)
datapath_ = new STRING(datapath);
Expand All @@ -417,14 +415,11 @@ int TessBaseAPI::Init(const char* data, int data_size, const char* language,
last_oem_requested_ = oem;

#ifndef DISABLED_LEGACY_ENGINE
// PERF_COUNT_SUB("update last_oem_requested_")
// For same language and datapath, just reset the adaptive classifier.
if (reset_classifier) {
tesseract_->ResetAdaptiveClassifier();
PERF_COUNT_SUB("tesseract_->ResetAdaptiveClassifier()")
}
#endif // ndef DISABLED_LEGACY_ENGINE
PERF_COUNT_END
return 0;
}

Expand Down Expand Up @@ -1106,7 +1101,6 @@ bool TessBaseAPI::ProcessPagesInternal(const char* filename,
const char* retry_config,
int timeout_millisec,
TessResultRenderer* renderer) {
PERF_COUNT_START("ProcessPages")
bool stdInput = !strcmp(filename, "stdin") || !strcmp(filename, "-");
if (stdInput) {
#ifdef WIN32
Expand Down Expand Up @@ -1199,14 +1193,12 @@ bool TessBaseAPI::ProcessPagesInternal(const char* filename,
if (!r || (renderer && !renderer->EndDocument())) {
return false;
}
PERF_COUNT_END
return true;
}

bool TessBaseAPI::ProcessPage(Pix* pix, int page_index, const char* filename,
const char* retry_config, int timeout_millisec,
TessResultRenderer* renderer) {
PERF_COUNT_START("ProcessPage")
SetInputName(filename);
SetImage(pix);
bool failed = false;
Expand Down Expand Up @@ -1264,7 +1256,6 @@ bool TessBaseAPI::ProcessPage(Pix* pix, int page_index, const char* filename,
failed = !renderer->AddImage(this);
}

PERF_COUNT_END
return !failed;
}

Expand Down
8 changes: 3 additions & 5 deletions src/api/tesseractmain.cpp
Expand Up @@ -28,7 +28,9 @@
#include "baseapi.h"
#include "basedir.h"
#include "dict.h"
#include "openclwrapper.h" // for PERF_COUNT_START, ...
#if defined(USE_OPENCL)
#include "openclwrapper.h" // for OpenclDevice
#endif
#include "osdetect.h"
#include "renderer.h"
#include "simddetect.h"
Expand Down Expand Up @@ -582,8 +584,6 @@ int main(int argc, char** argv) {
if (image == nullptr && !list_langs && !print_parameters)
return EXIT_SUCCESS;

PERF_COUNT_START("Tesseract:main")

// Call GlobalDawgCache here to create the global DawgCache object before
// the TessBaseAPI object. This fixes the order of destructor calls:
// first TessBaseAPI must be destructed, DawgCache must be the last object.
Expand Down Expand Up @@ -721,7 +721,5 @@ int main(int argc, char** argv) {
}
}

PERF_COUNT_END

return EXIT_SUCCESS;
}
11 changes: 4 additions & 7 deletions src/ccmain/thresholder.cpp
Expand Up @@ -25,8 +25,11 @@
#include <cstring>

#include "otsuthr.h"
#include "tprintf.h" // for tprintf

#include "openclwrapper.h" // for PERF_COUNT_START, ...
#if defined(USE_OPENCL)
#include "openclwrapper.h" // for OpenclDevice
#endif

namespace tesseract {

Expand Down Expand Up @@ -263,7 +266,6 @@ Pix* ImageThresholder::GetPixRectGrey() {
// Otsu thresholds the rectangle, taking the rectangle from *this.
void ImageThresholder::OtsuThresholdRectToPix(Pix* src_pix,
Pix** out_pix) const {
PERF_COUNT_START("OtsuThresholdRectToPix")
int* thresholds;
int* hi_values;

Expand All @@ -286,8 +288,6 @@ void ImageThresholder::OtsuThresholdRectToPix(Pix* src_pix,
#endif
delete [] thresholds;
delete [] hi_values;

PERF_COUNT_END
}

/// Threshold the rectangle, taking everything except the src_pix
Expand All @@ -299,7 +299,6 @@ void ImageThresholder::ThresholdRectToPix(Pix* src_pix,
const int* thresholds,
const int* hi_values,
Pix** pix) const {
PERF_COUNT_START("ThresholdRectToPix")
*pix = pixCreate(rect_width_, rect_height_, 1);
uint32_t* pixdata = pixGetData(*pix);
int wpl = pixGetWpl(*pix);
Expand All @@ -325,8 +324,6 @@ void ImageThresholder::ThresholdRectToPix(Pix* src_pix,
SET_DATA_BIT(pixline, x);
}
}

PERF_COUNT_END
}

} // namespace tesseract.
8 changes: 3 additions & 5 deletions src/ccstruct/otsuthr.cpp
Expand Up @@ -22,7 +22,9 @@
#include <cstring>
#include "allheaders.h"
#include "helpers.h"
#include "openclwrapper.h" // for PERF_COUNT_START, ...
#if defined(USE_OPENCL)
#include "openclwrapper.h" // for OpenclDevice
#endif

namespace tesseract {

Expand All @@ -40,7 +42,6 @@ int OtsuThreshold(Pix* src_pix, int left, int top, int width, int height,
int num_channels = pixGetDepth(src_pix) / 8;
// Of all channels with no good hi_value, keep the best so we can always
// produce at least one answer.
PERF_COUNT_START("OtsuThreshold")
int best_hi_value = 1;
int best_hi_index = 0;
bool any_good_hivalue = false;
Expand Down Expand Up @@ -139,7 +140,6 @@ int OtsuThreshold(Pix* src_pix, int left, int top, int width, int height,
// Use the best of the ones that were not good enough.
(*hi_values)[best_hi_index] = best_hi_value;
}
PERF_COUNT_END
return num_channels;
}

Expand All @@ -150,7 +150,6 @@ int OtsuThreshold(Pix* src_pix, int left, int top, int width, int height,
void HistogramRect(Pix* src_pix, int channel,
int left, int top, int width, int height,
int* histogram) {
PERF_COUNT_START("HistogramRect")
int num_channels = pixGetDepth(src_pix) / 8;
channel = ClipToRange(channel, 0, num_channels - 1);
int bottom = top + height;
Expand All @@ -164,7 +163,6 @@ void HistogramRect(Pix* src_pix, int channel,
++histogram[pixel];
}
}
PERF_COUNT_END
}

// Computes the Otsu threshold(s) for the given histogram.
Expand Down

0 comments on commit d42413d

Please sign in to comment.