Ref<BitArray> GlobalHistogramBinarizer::getBlackRow(int y, Ref<BitArray> row) {
-
- if (row == cached_row_num_) {
+ if (y == cached_row_num_) {
return cached_row_;
}
cached_row_ = array_ref;
cached_row_num_ = y;
-
delete [] row_pixels;
return array_ref;
} catch (IllegalArgumentException const& iae) {
+ // Cache the fact that this row failed.
+ cached_row_ = NULL;
+ cached_row_num_ = y;
delete [] row_pixels;
throw iae;
}
}
Ref<BitMatrix> GlobalHistogramBinarizer::getBlackMatrix() {
-
if (cached_matrix_ != NULL) {
return cached_matrix_;
}
int height = source.getHeight();
vector<int> histogram(LUMINANCE_BUCKETS, 0);
-
// Quickly calculates the histogram by sampling four rows from the image.
// This proved to be more robust on the blackbox tests than sampling a
// diagonal as we used to do.
int numBuckets = histogram.size();
int maxBucketCount = 0;
-
// Find tallest peak in histogram
int firstPeak = 0;
int firstPeakSize = 0;