summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
ca9d7b0)
valarray<int> histogram(LUMINANCE_BUCKETS);
if (method == BlackPointEstimationMethod_2D) {
size_t minDimension = width < height ? width : height;
valarray<int> histogram(LUMINANCE_BUCKETS);
if (method == BlackPointEstimationMethod_2D) {
size_t minDimension = width < height ? width : height;
- size_t yOffset = height == minDimension ? 0 : (height - width) >> 1;
- size_t xOffset = width == minDimension ? 0 : (width - height) >> 1;
+ size_t startX = (width - minDimension) >> 1;
+ size_t startY = (height - minDimension) >> 1;
for (size_t n = 0; n < minDimension; n++) {
for (size_t n = 0; n < minDimension; n++) {
- unsigned char pixel = getPixel(xOffset + n, yOffset + n);
+ unsigned char pixel = getPixel(startX + n, startY + n);
histogram[pixel >> LUMINANCE_SHIFT]++;
}
} else if (method == BlackPointEstimationMethod_RowSampling) {
histogram[pixel >> LUMINANCE_SHIFT]++;
}
} else if (method == BlackPointEstimationMethod_RowSampling) {
- if (arg < 0 || arg > (int)height) {
+ if (arg < 0 || arg >= (int)height) {
throw new IllegalArgumentException
("black point estimation argument out of range");
}
throw new IllegalArgumentException
("black point estimation argument out of range");
}
}
BlackPointEstimationMethod MonochromeBitmapSource::getLastEstimationMethod() {
}
BlackPointEstimationMethod MonochromeBitmapSource::getLastEstimationMethod() {
- return BlackPointEstimationMethod_None;
+ return lastEstimationMethod_;
size_t BlackPointEstimator::estimate(valarray<int> &histogram) {
size_t numBuckets = histogram.size();
size_t BlackPointEstimator::estimate(valarray<int> &histogram) {
size_t numBuckets = histogram.size();
+ int maxBucketCount = 0;
// Find tallest peak in histogram
size_t firstPeak = 0;
// Find tallest peak in histogram
size_t firstPeak = 0;
firstPeak = i;
firstPeakSize = histogram[i];
}
firstPeak = i;
firstPeakSize = histogram[i];
}
+ if (histogram[i] > maxBucketCount) {
+ maxBucketCount = histogram[i];
+ }
}
// Find second-tallest peak -- well, another peak that is tall and not
}
// Find second-tallest peak -- well, another peak that is tall and not
// Decoding the image/line is either pointless, or may in some cases lead to a false positive
// for 1D formats, which are relatively lenient.
// We arbitrarily say "close" is "<= 1/16 of the total histogram buckets apart"
// Decoding the image/line is either pointless, or may in some cases lead to a false positive
// for 1D formats, which are relatively lenient.
// We arbitrarily say "close" is "<= 1/16 of the total histogram buckets apart"
- if (secondPeak - firstPeak <= histogram.size() >> 4) {
+ if (secondPeak - firstPeak <= numBuckets >> 4) {
throw new IllegalArgumentException
("Too little dynamic range in luminance");
}
throw new IllegalArgumentException
("Too little dynamic range in luminance");
}
int fromFirst = i - firstPeak;
// Favor a "valley" that is not too close to either peak -- especially not the black peak --
// and that has a low value of course
int fromFirst = i - firstPeak;
// Favor a "valley" that is not too close to either peak -- especially not the black peak --
// and that has a low value of course
- int score = fromFirst * fromFirst * (secondPeak - i) * (256 - histogram[i]);
+ int score = fromFirst * fromFirst * (secondPeak - i) * (maxBucketCount - histogram[i]);
if (score > bestValleyScore) {
bestValley = i;
bestValleyScore = score;
if (score > bestValleyScore) {
bestValley = i;
bestValleyScore = score;
cout << "decode(): received = " << &received << ", array = " <<
received.array_ << " (" << received.array_->count_ << ")\n";
#endif
cout << "decode(): received = " << &received << ", array = " <<
received.array_ << " (" << received.array_->count_ << ")\n";
#endif
Ref<GF256Poly> poly(new GF256Poly(field, received));
Ref<GF256Poly> poly(new GF256Poly(field, received));
cout << "decoding with poly " << *poly << "\n";
cout << "decoding with poly " << *poly << "\n";
ArrayRef<int> syndromeCoefficients(new Array<int>(twoS));
ArrayRef<int> syndromeCoefficients(new Array<int>(twoS));
#ifdef DEBUG
cout << "syndromeCoefficients array = " <<
syndromeCoefficients.array_ << "\n";
#endif
#ifdef DEBUG
cout << "syndromeCoefficients array = " <<
syndromeCoefficients.array_ << "\n";
#endif
bool noError = true;
for (int i = 0; i < twoS; i++) {
int eval = poly->evaluateAt(field.exp(i));
bool noError = true;
for (int i = 0; i < twoS; i++) {
int eval = poly->evaluateAt(field.exp(i));
#ifdef DEBUG
cout << "before returning: syndromeCoefficients rc = " <<
syndromeCoefficients.array_->count_ << "\n";
#endif
#ifdef DEBUG
cout << "before returning: syndromeCoefficients rc = " <<
syndromeCoefficients.array_->count_ << "\n";
#endif
Ref<GF256Poly> sigma(t->multiply(inverse));
Ref<GF256Poly> omega(r->multiply(inverse));
Ref<GF256Poly> sigma(t->multiply(inverse));
Ref<GF256Poly> omega(r->multiply(inverse));
cout << "t = " << *t << "\n";
cout << "r = " << *r << "\n";
cout << "sigma = " << *sigma << "\n";
cout << "omega = " << *omega << "\n";
cout << "t = " << *t << "\n";
cout << "r = " << *r << "\n";
cout << "sigma = " << *sigma << "\n";
cout << "omega = " << *omega << "\n";
vector<Ref<GF256Poly> > result(2);
result[0] = sigma;
vector<Ref<GF256Poly> > result(2);
result[0] = sigma;
using namespace std;
Ref<Result> QRCodeReader::decode(Ref<MonochromeBitmapSource> image) {
using namespace std;
Ref<Result> QRCodeReader::decode(Ref<MonochromeBitmapSource> image) {
cout << "decoding image " << image.object_ << ":\n" << flush;
cout << "decoding image " << image.object_ << ":\n" << flush;
Detector detector(image);
Detector detector(image);
cout << "(1) created detector " << &detector << "\n" << flush;
cout << "(1) created detector " << &detector << "\n" << flush;
Ref<DetectorResult> detectorResult(detector.detect());
Ref<DetectorResult> detectorResult(detector.detect());
cout << "(2) detected, have detectorResult " << detectorResult.object_ << "\n" << flush;
cout << "(2) detected, have detectorResult " << detectorResult.object_ << "\n" << flush;
ArrayRef<Ref<ResultPoint> > points(detectorResult->getPoints());
ArrayRef<Ref<ResultPoint> > points(detectorResult->getPoints());
cout << "(3) extracted points " << &points << "\n" << flush;
cout << "found " << points->size() << " points:\n";
for (size_t i = 0; i < points->size(); i++) {
cout << "(3) extracted points " << &points << "\n" << flush;
cout << "found " << points->size() << " points:\n";
for (size_t i = 0; i < points->size(); i++) {
}
cout << "bits:\n";
cout << *(detectorResult->getBits()) << "\n";
}
cout << "bits:\n";
cout << *(detectorResult->getBits()) << "\n";
Ref<DecoderResult> decoderResult(decoder_.decode(detectorResult->getBits()));
Ref<DecoderResult> decoderResult(decoder_.decode(detectorResult->getBits()));
cout << "(4) decoded, have decoderResult " << decoderResult.object_ << "\n" << flush;
cout << "(4) decoded, have decoderResult " << decoderResult.object_ << "\n" << flush;
Ref<Result> result(new Result(decoderResult->getText(),
decoderResult->getRawBytes(),
points,
BarcodeFormat_QR_CODE));
Ref<Result> result(new Result(decoderResult->getText(),
decoderResult->getRawBytes(),
points,
BarcodeFormat_QR_CODE));
cout << "(5) created result " << result.object_ << ", returning\n" << flush;
cout << "(5) created result " << result.object_ << ", returning\n" << flush;
functionPattern->setRegion(dimension - 11, 0, 3, 6);
}
functionPattern->setRegion(dimension - 11, 0, 3, 6);
}
cout << "version " << versionNumber_ << " built function pattern:\n";
cout << *functionPattern;
cout << "version " << versionNumber_ << " built function pattern:\n";
cout << *functionPattern;
return functionPattern;
}
return functionPattern;
}