mirror of
https://github.com/zxing/zxing.git
synced 2025-01-12 19:57:27 -08:00
debug printout cleanup
git-svn-id: https://zxing.googlecode.com/svn/trunk@472 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
8cffdc4b70
commit
753ca4afbf
|
@ -87,14 +87,14 @@ estimateBlackPoint(BlackPointEstimationMethod method, int arg) {
|
||||||
valarray<int> histogram(LUMINANCE_BUCKETS);
|
valarray<int> histogram(LUMINANCE_BUCKETS);
|
||||||
if (method == BlackPointEstimationMethod_2D) {
|
if (method == BlackPointEstimationMethod_2D) {
|
||||||
size_t minDimension = width < height ? width : height;
|
size_t minDimension = width < height ? width : height;
|
||||||
size_t yOffset = height == minDimension ? 0 : (height - width) >> 1;
|
size_t startX = (width - minDimension) >> 1;
|
||||||
size_t xOffset = width == minDimension ? 0 : (width - height) >> 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]++;
|
histogram[pixel >> LUMINANCE_SHIFT]++;
|
||||||
}
|
}
|
||||||
} else if (method == BlackPointEstimationMethod_RowSampling) {
|
} else if (method == BlackPointEstimationMethod_RowSampling) {
|
||||||
if (arg < 0 || arg > (int)height) {
|
if (arg < 0 || arg >= (int)height) {
|
||||||
throw new IllegalArgumentException
|
throw new IllegalArgumentException
|
||||||
("black point estimation argument out of range");
|
("black point estimation argument out of range");
|
||||||
}
|
}
|
||||||
|
@ -114,6 +114,6 @@ estimateBlackPoint(BlackPointEstimationMethod method, int arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
BlackPointEstimationMethod MonochromeBitmapSource::getLastEstimationMethod() {
|
BlackPointEstimationMethod MonochromeBitmapSource::getLastEstimationMethod() {
|
||||||
return BlackPointEstimationMethod_None;
|
return lastEstimationMethod_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ namespace common {
|
||||||
size_t BlackPointEstimator::estimate(valarray<int> &histogram) {
|
size_t BlackPointEstimator::estimate(valarray<int> &histogram) {
|
||||||
|
|
||||||
size_t numBuckets = histogram.size();
|
size_t numBuckets = histogram.size();
|
||||||
|
int maxBucketCount = 0;
|
||||||
|
|
||||||
// Find tallest peak in histogram
|
// Find tallest peak in histogram
|
||||||
size_t firstPeak = 0;
|
size_t firstPeak = 0;
|
||||||
|
@ -37,6 +38,9 @@ namespace common {
|
||||||
firstPeak = i;
|
firstPeak = i;
|
||||||
firstPeakSize = histogram[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
|
||||||
|
@ -65,7 +69,7 @@ namespace common {
|
||||||
// Decoding the image/line is either pointless, or may in some cases lead to a false positive
|
// Decoding the image/line is either pointless, or may in some cases lead to a false positive
|
||||||
// for 1D formats, which are relatively lenient.
|
// for 1D formats, which are relatively lenient.
|
||||||
// We arbitrarily say "close" is "<= 1/16 of the total histogram buckets apart"
|
// 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
|
throw new IllegalArgumentException
|
||||||
("Too little dynamic range in luminance");
|
("Too little dynamic range in luminance");
|
||||||
}
|
}
|
||||||
|
@ -77,7 +81,7 @@ namespace common {
|
||||||
int fromFirst = i - firstPeak;
|
int fromFirst = i - firstPeak;
|
||||||
// Favor a "valley" that is not too close to either peak -- especially not the black peak --
|
// Favor a "valley" that is not too close to either peak -- especially not the black peak --
|
||||||
// and that has a low value of course
|
// 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) {
|
if (score > bestValleyScore) {
|
||||||
bestValley = i;
|
bestValley = i;
|
||||||
bestValleyScore = score;
|
bestValleyScore = score;
|
||||||
|
|
|
@ -40,13 +40,20 @@ namespace reedsolomon {
|
||||||
cout << "decode(): received = " << &received << ", array = " <<
|
cout << "decode(): received = " << &received << ", array = " <<
|
||||||
received.array_ << " (" << received.array_->count_ << ")\n";
|
received.array_ << " (" << received.array_->count_ << ")\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Ref<GF256Poly> poly(new GF256Poly(field, received));
|
Ref<GF256Poly> poly(new GF256Poly(field, received));
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
cout << "decoding with poly " << *poly << "\n";
|
cout << "decoding with poly " << *poly << "\n";
|
||||||
|
#endif
|
||||||
|
|
||||||
ArrayRef<int> syndromeCoefficients(new Array<int>(twoS));
|
ArrayRef<int> syndromeCoefficients(new Array<int>(twoS));
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cout << "syndromeCoefficients array = " <<
|
cout << "syndromeCoefficients array = " <<
|
||||||
syndromeCoefficients.array_ << "\n";
|
syndromeCoefficients.array_ << "\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool noError = true;
|
bool noError = true;
|
||||||
for (int i = 0; i < twoS; i++) {
|
for (int i = 0; i < twoS; i++) {
|
||||||
int eval = poly->evaluateAt(field.exp(i));
|
int eval = poly->evaluateAt(field.exp(i));
|
||||||
|
@ -56,10 +63,12 @@ namespace reedsolomon {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (noError) {
|
if (noError) {
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
cout << "before returning: syndromeCoefficients rc = " <<
|
cout << "before returning: syndromeCoefficients rc = " <<
|
||||||
syndromeCoefficients.array_->count_ << "\n";
|
syndromeCoefficients.array_->count_ << "\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,10 +158,12 @@ namespace reedsolomon {
|
||||||
Ref<GF256Poly> sigma(t->multiply(inverse));
|
Ref<GF256Poly> sigma(t->multiply(inverse));
|
||||||
Ref<GF256Poly> omega(r->multiply(inverse));
|
Ref<GF256Poly> omega(r->multiply(inverse));
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
cout << "t = " << *t << "\n";
|
cout << "t = " << *t << "\n";
|
||||||
cout << "r = " << *r << "\n";
|
cout << "r = " << *r << "\n";
|
||||||
cout << "sigma = " << *sigma << "\n";
|
cout << "sigma = " << *sigma << "\n";
|
||||||
cout << "omega = " << *omega << "\n";
|
cout << "omega = " << *omega << "\n";
|
||||||
|
#endif
|
||||||
|
|
||||||
vector<Ref<GF256Poly> > result(2);
|
vector<Ref<GF256Poly> > result(2);
|
||||||
result[0] = sigma;
|
result[0] = sigma;
|
||||||
|
|
|
@ -31,12 +31,24 @@ namespace qrcode {
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
Ref<Result> QRCodeReader::decode(Ref<MonochromeBitmapSource> image) {
|
Ref<Result> QRCodeReader::decode(Ref<MonochromeBitmapSource> image) {
|
||||||
|
#ifdef DEBUG
|
||||||
cout << "decoding image " << image.object_ << ":\n" << flush;
|
cout << "decoding image " << image.object_ << ":\n" << flush;
|
||||||
|
#endif
|
||||||
|
|
||||||
Detector detector(image);
|
Detector detector(image);
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
cout << "(1) created detector " << &detector << "\n" << flush;
|
cout << "(1) created detector " << &detector << "\n" << flush;
|
||||||
|
#endif
|
||||||
|
|
||||||
Ref<DetectorResult> detectorResult(detector.detect());
|
Ref<DetectorResult> detectorResult(detector.detect());
|
||||||
|
#ifdef DEBUG
|
||||||
cout << "(2) detected, have detectorResult " << detectorResult.object_ << "\n" << flush;
|
cout << "(2) detected, have detectorResult " << detectorResult.object_ << "\n" << flush;
|
||||||
|
#endif
|
||||||
|
|
||||||
ArrayRef<Ref<ResultPoint> > points(detectorResult->getPoints());
|
ArrayRef<Ref<ResultPoint> > points(detectorResult->getPoints());
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
cout << "(3) extracted points " << &points << "\n" << flush;
|
cout << "(3) extracted points " << &points << "\n" << flush;
|
||||||
cout << "found " << points->size() << " points:\n";
|
cout << "found " << points->size() << " points:\n";
|
||||||
for (size_t i = 0; i < points->size(); i++) {
|
for (size_t i = 0; i < points->size(); i++) {
|
||||||
|
@ -44,13 +56,21 @@ namespace qrcode {
|
||||||
}
|
}
|
||||||
cout << "bits:\n";
|
cout << "bits:\n";
|
||||||
cout << *(detectorResult->getBits()) << "\n";
|
cout << *(detectorResult->getBits()) << "\n";
|
||||||
|
#endif
|
||||||
|
|
||||||
Ref<DecoderResult> decoderResult(decoder_.decode(detectorResult->getBits()));
|
Ref<DecoderResult> decoderResult(decoder_.decode(detectorResult->getBits()));
|
||||||
|
#ifdef DEBUG
|
||||||
cout << "(4) decoded, have decoderResult " << decoderResult.object_ << "\n" << flush;
|
cout << "(4) decoded, have decoderResult " << decoderResult.object_ << "\n" << flush;
|
||||||
|
#endif
|
||||||
|
|
||||||
Ref<Result> result(new Result(decoderResult->getText(),
|
Ref<Result> result(new Result(decoderResult->getText(),
|
||||||
decoderResult->getRawBytes(),
|
decoderResult->getRawBytes(),
|
||||||
points,
|
points,
|
||||||
BarcodeFormat_QR_CODE));
|
BarcodeFormat_QR_CODE));
|
||||||
|
#ifdef DEBUG
|
||||||
cout << "(5) created result " << result.object_ << ", returning\n" << flush;
|
cout << "(5) created result " << result.object_ << ", returning\n" << flush;
|
||||||
|
#endif
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,8 +166,10 @@ namespace qrcode {
|
||||||
functionPattern->setRegion(dimension - 11, 0, 3, 6);
|
functionPattern->setRegion(dimension - 11, 0, 3, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
cout << "version " << versionNumber_ << " built function pattern:\n";
|
cout << "version " << versionNumber_ << " built function pattern:\n";
|
||||||
cout << *functionPattern;
|
cout << *functionPattern;
|
||||||
|
#endif
|
||||||
|
|
||||||
return functionPattern;
|
return functionPattern;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue