* However it tends to produce artifacts on lower frequency images and is therefore not
* a good general purpose binarizer for uses outside ZXing.
*
+ * NOTE: This class is still experimental and may not be ready for prime time yet.
+ *
* @author dswitkin@google.com (Daniel Switkin)
*/
public final class LocalBlockBinarizer extends Binarizer {
super(source);
}
+ // TODO: Consider a different strategy for 1D Readers.
public BitArray getBlackRow(int y, BitArray row) {
binarizeEntireImage();
return matrix.getRow(y, row);
}
+ // TODO: If getBlackRow() calculates its own values, removing sharpening here.
public BitMatrix getBlackMatrix() {
binarizeEntireImage();
return matrix;
int center = luminances[offset + 1] & 0xff;
for (int x = 1; x < width - 1; x++) {
int right = luminances[offset + x + 1] & 0xff;
- luminances[x] = (byte)(((center << 2) - left - right) >> 1);
+ int pixel = ((center << 2) - left - right) >> 1;
+ // Must clamp values to 0..255 so they will fit in a byte.
+ if (pixel > 255) {
+ pixel = 255;
+ } else if (pixel < 0) {
+ pixel = 0;
+ }
+ luminances[offset + x] = (byte)pixel;
left = center;
center = right;
}
// modules, but the
// very corners. So there is no 0.5f here; 0.0f is right.
GridSampler sampler = GridSampler.getInstance();
- return sampler.sampleGrid(image, dimension, 0.0f, // p1ToX
+
+ // FIXME: Temporary fix calling getBlackMatrix() inline here. It should be called once
+ // and the result matrix passed down into sampleGrid() and throughout the reader.
+ return sampler.sampleGrid(image.getBlackMatrix(), dimension, 0.0f, // p1ToX
0.0f, // p1ToY
dimension, // p2ToX
0.0f, // p2ToY
import com.google.zxing.oned.UPCEBlackBox1TestCase;
import com.google.zxing.oned.UPCEBlackBox2TestCase;
import com.google.zxing.oned.UPCEBlackBox3ReflectiveTestCase;
+import com.google.zxing.pdf417.PDF417BlackBox1TestCase;
import com.google.zxing.qrcode.QRCodeBlackBox1TestCase;
import com.google.zxing.qrcode.QRCodeBlackBox2TestCase;
import com.google.zxing.qrcode.QRCodeBlackBox3TestCase;
new UPCEBlackBox1TestCase(),
new UPCEBlackBox2TestCase(),
new UPCEBlackBox3ReflectiveTestCase(),
+ new PDF417BlackBox1TestCase(),
new QRCodeBlackBox1TestCase(),
new QRCodeBlackBox2TestCase(),
new QRCodeBlackBox3TestCase(),
AbstractBlackBoxTestCase.SummaryResults results = new AbstractBlackBoxTestCase.SummaryResults();
for (int x = 0; x < TESTS.length; x++) {
- results.add(TESTS[x].testBlackBoxCountingResults());
+ results.add(TESTS[x].testBlackBoxCountingResults(false));
}
// This threaded version can't be used yet because BlackPointEstimator (and possibly other code)
// This workaround is used because AbstractNegativeBlackBoxTestCase overrides this method but does
// not return SummaryResults.
public void testBlackBox() throws IOException {
- testBlackBoxCountingResults();
+ testBlackBoxCountingResults(true);
}
- public SummaryResults testBlackBoxCountingResults() throws IOException {
+ public SummaryResults testBlackBoxCountingResults(boolean assertOnFailure) throws IOException {
assertFalse(testResults.isEmpty());
File[] imageFiles = getImageFiles();
}
// Then run through again and assert if any failed
- for (int x = 0; x < testCount; x++) {
- assertTrue("Rotation " + testResults.get(x).getRotation() +
- " degrees: Too many images failed",
- passedCounts[x] >= testResults.get(x).getMustPassCount());
- assertTrue("Try harder, Rotation " + testResults.get(x).getRotation() +
- " degrees: Too many images failed",
- tryHarderCounts[x] >= testResults.get(x).getTryHarderCount());
+ if (assertOnFailure) {
+ for (int x = 0; x < testCount; x++) {
+ assertTrue("Rotation " + testResults.get(x).getRotation() +
+ " degrees: Too many images failed",
+ passedCounts[x] >= testResults.get(x).getMustPassCount());
+ assertTrue("Try harder, Rotation " + testResults.get(x).getRotation() +
+ " degrees: Too many images failed",
+ tryHarderCounts[x] >= testResults.get(x).getTryHarderCount());
+ }
}
return new SummaryResults(totalFound, totalMustPass, totalTests);
}