mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-01-23 19:13:00 +08:00
Merge pull request #2022 from stweil/coverity
Fix several issues reported by Coverity Scan
This commit is contained in:
commit
5a68b7f41b
@ -17,6 +17,10 @@
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath> // for std::fabs
|
||||
#include <memory>
|
||||
|
||||
#include "osdetect.h"
|
||||
|
||||
#include "blobbox.h"
|
||||
@ -33,9 +37,6 @@
|
||||
#include "tesseractclass.h"
|
||||
#include "textord.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
||||
const float kSizeRatioToReject = 2.0;
|
||||
const int kMinAcceptableBlobHeight = 10;
|
||||
|
||||
@ -252,7 +253,10 @@ int os_detect(TO_BLOCK_LIST* port_blocks, OSResults* osr,
|
||||
TBOX box = blob->bounding_box();
|
||||
++blobs_total;
|
||||
|
||||
float y_x = fabs((box.height() * 1.0) / box.width());
|
||||
// Catch illegal value of box width and avoid division by zero.
|
||||
if (box.width() == 0) continue;
|
||||
// TODO: Can height and width be negative? If not, remove fabs.
|
||||
float y_x = std::fabs((box.height() * 1.0f) / box.width());
|
||||
float x_y = 1.0f / y_x;
|
||||
// Select a >= 1.0 ratio
|
||||
float ratio = x_y > y_x ? x_y : y_x;
|
||||
|
@ -46,7 +46,7 @@ double ErrorCounter::ComputeErrorRate(ShapeClassifier* classifier,
|
||||
GenericVector<UnicharRating> results;
|
||||
|
||||
clock_t start = clock();
|
||||
int total_samples = 0;
|
||||
unsigned total_samples = 0;
|
||||
double unscaled_error = 0.0;
|
||||
// Set a number of samples on which to run the classify debug mode.
|
||||
int error_samples = report_level > 3 ? report_level * report_level : 0;
|
||||
@ -89,7 +89,7 @@ double ErrorCounter::ComputeErrorRate(ShapeClassifier* classifier,
|
||||
fontinfo_table,
|
||||
*it, unichar_error, fonts_report);
|
||||
if (scaled_error != nullptr) *scaled_error = counter.scaled_error_;
|
||||
if (report_level > 1) {
|
||||
if (report_level > 1 && total_samples > 0) {
|
||||
// It is useful to know the time in microseconds/char.
|
||||
tprintf("Errors computed in %.2fs at %.1f μs/char\n",
|
||||
total_time, 1000000.0 * total_time / total_samples);
|
||||
|
@ -663,10 +663,12 @@ void ColPartition::Absorb(ColPartition* other, WidthCallback* cb) {
|
||||
// Update the special_blobs_densities_.
|
||||
memset(special_blobs_densities_, 0, sizeof(special_blobs_densities_));
|
||||
for (int type = 0; type < BSTT_COUNT; ++type) {
|
||||
int w1 = boxes_.length(), w2 = other->boxes_.length();
|
||||
unsigned w1 = boxes_.length();
|
||||
unsigned w2 = other->boxes_.length();
|
||||
float new_val = special_blobs_densities_[type] * w1 +
|
||||
other->special_blobs_densities_[type] * w2;
|
||||
if (!w1 || !w2) {
|
||||
ASSERT_HOST((w1 + w2) > 0);
|
||||
special_blobs_densities_[type] = new_val / (w1 + w2);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user