mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
incomplete port of aztec detector
This commit is contained in:
@@ -14,53 +14,54 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.google.zxing.aztec.detector;
|
// package com.google.zxing.aztec.detector;
|
||||||
|
|
||||||
import com.google.zxing.NotFoundException;
|
// import com.google.zxing.NotFoundException;
|
||||||
import com.google.zxing.aztec.AztecDetectorRXingResult;
|
// import com.google.zxing.aztec.AztecDetectorRXingResult;
|
||||||
import com.google.zxing.aztec.decoder.Decoder;
|
// import com.google.zxing.aztec.decoder.Decoder;
|
||||||
import com.google.zxing.aztec.detector.Detector.Point;
|
// import com.google.zxing.aztec.detector.Detector.Point;
|
||||||
import com.google.zxing.aztec.encoder.AztecCode;
|
// import com.google.zxing.aztec.encoder.AztecCode;
|
||||||
import com.google.zxing.aztec.encoder.Encoder;
|
// import com.google.zxing.aztec.encoder.Encoder;
|
||||||
import com.google.zxing.common.BitMatrix;
|
// import com.google.zxing.common.BitMatrix;
|
||||||
import com.google.zxing.common.DecoderRXingResult;
|
// import com.google.zxing.common.DecoderRXingResult;
|
||||||
import org.junit.Assert;
|
// import org.junit.Assert;
|
||||||
import org.junit.Test;
|
// import org.junit.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
// import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
// import java.util.Arrays;
|
||||||
import java.util.Collection;
|
// import java.util.Collection;
|
||||||
import java.util.List;
|
// import java.util.List;
|
||||||
import java.util.Random;
|
// import java.util.Random;
|
||||||
import java.util.TreeSet;
|
// import java.util.TreeSet;
|
||||||
|
|
||||||
|
use crate::common::BitMatrix;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for the Detector
|
* Tests for the Detector
|
||||||
*
|
*
|
||||||
* @author Frank Yellin
|
* @author Frank Yellin
|
||||||
*/
|
*/
|
||||||
public final class DetectorTest extends Assert {
|
|
||||||
|
|
||||||
@Test
|
#[test]
|
||||||
public void testErrorInParameterLocatorZeroZero() throws Exception {
|
fn testErrorInParameterLocatorZeroZero() {
|
||||||
// Layers=1, CodeWords=1. So the parameter info and its Reed-Solomon info
|
// Layers=1, CodeWords=1. So the parameter info and its Reed-Solomon info
|
||||||
// will be completely zero!
|
// will be completely zero!
|
||||||
testErrorInParameterLocator("X");
|
testErrorInParameterLocator("X");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
#[test]
|
||||||
public void testErrorInParameterLocatorCompact() throws Exception {
|
fn testErrorInParameterLocatorCompact() {
|
||||||
testErrorInParameterLocator("This is an example Aztec symbol for Wikipedia.");
|
testErrorInParameterLocator("This is an example Aztec symbol for Wikipedia.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
#[test]
|
||||||
public void testErrorInParameterLocatorNotCompact() throws Exception {
|
fn testErrorInParameterLocatorNotCompact() {
|
||||||
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxyz";
|
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxyz";
|
||||||
testErrorInParameterLocator(alphabet + alphabet + alphabet);
|
testErrorInParameterLocator(alphabet + alphabet + alphabet);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test that we can tolerate errors in the parameter locator bits
|
// Test that we can tolerate errors in the parameter locator bits
|
||||||
private static void testErrorInParameterLocator(String data) throws Exception {
|
fn testErrorInParameterLocator( data:&str) {
|
||||||
AztecCode aztec = Encoder.encode(data, 25, Encoder.DEFAULT_AZTEC_LAYERS);
|
AztecCode aztec = Encoder.encode(data, 25, Encoder.DEFAULT_AZTEC_LAYERS);
|
||||||
Random random = new Random(aztec.getMatrix().hashCode()); // pseudo-random, but deterministic
|
Random random = new Random(aztec.getMatrix().hashCode()); // pseudo-random, but deterministic
|
||||||
int layers = aztec.getLayers();
|
int layers = aztec.getLayers();
|
||||||
@@ -109,9 +110,9 @@ public final class DetectorTest extends Assert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Zooms a bit matrix so that each bit is factor x factor
|
// Zooms a bit matrix so that each bit is factor x factor
|
||||||
private static BitMatrix makeLarger(BitMatrix input, int factor) {
|
fn makeLarger( input:&BitMatrix, factor:u32) -> BitMatrix{
|
||||||
int width = input.getWidth();
|
let width = input.getWidth();
|
||||||
BitMatrix output = new BitMatrix(width * factor);
|
let output = BitMatrix::new(width * factor);
|
||||||
for (int inputY = 0; inputY < width; inputY++) {
|
for (int inputY = 0; inputY < width; inputY++) {
|
||||||
for (int inputX = 0; inputX < width; inputX++) {
|
for (int inputX = 0; inputX < width; inputX++) {
|
||||||
if (input.get(inputX, inputY)) {
|
if (input.get(inputX, inputY)) {
|
||||||
@@ -123,7 +124,7 @@ public final class DetectorTest extends Assert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns a list of the four rotations of the BitMatrix.
|
// Returns a list of the four rotations of the BitMatrix.
|
||||||
private static Iterable<BitMatrix> getRotations(BitMatrix matrix0) {
|
fn getRotations( matrix0:&BitMatrix)-> Vec<BitMatrix> {
|
||||||
BitMatrix matrix90 = rotateRight(matrix0);
|
BitMatrix matrix90 = rotateRight(matrix0);
|
||||||
BitMatrix matrix180 = rotateRight(matrix90);
|
BitMatrix matrix180 = rotateRight(matrix90);
|
||||||
BitMatrix matrix270 = rotateRight(matrix180);
|
BitMatrix matrix270 = rotateRight(matrix180);
|
||||||
@@ -131,7 +132,7 @@ public final class DetectorTest extends Assert {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rotates a square BitMatrix to the right by 90 degrees
|
// Rotates a square BitMatrix to the right by 90 degrees
|
||||||
private static BitMatrix rotateRight(BitMatrix input) {
|
fn rotateRight( input:&BitMatrix) -> BitMatrix{
|
||||||
int width = input.getWidth();
|
int width = input.getWidth();
|
||||||
BitMatrix result = new BitMatrix(width);
|
BitMatrix result = new BitMatrix(width);
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
@@ -146,8 +147,8 @@ public final class DetectorTest extends Assert {
|
|||||||
|
|
||||||
// Returns the transpose of a bit matrix, which is equivalent to rotating the
|
// Returns the transpose of a bit matrix, which is equivalent to rotating the
|
||||||
// matrix to the right, and then flipping it left-to-right
|
// matrix to the right, and then flipping it left-to-right
|
||||||
private static BitMatrix transpose(BitMatrix input) {
|
fn transpose( input:&BitMatrix) -> BitMatrix {
|
||||||
int width = input.getWidth();
|
let width = input.getWidth();
|
||||||
BitMatrix result = new BitMatrix(width);
|
BitMatrix result = new BitMatrix(width);
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
for (int y = 0; y < width; y++) {
|
for (int y = 0; y < width; y++) {
|
||||||
@@ -159,7 +160,7 @@ public final class DetectorTest extends Assert {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BitMatrix clone(BitMatrix input) {
|
fn clone( input:&BitMatrix) -> BitMatrix {
|
||||||
int width = input.getWidth();
|
int width = input.getWidth();
|
||||||
BitMatrix result = new BitMatrix(width);
|
BitMatrix result = new BitMatrix(width);
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
@@ -172,7 +173,7 @@ public final class DetectorTest extends Assert {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Point> getOrientationPoints(AztecCode code) {
|
fn getOrientationPoints( code::&AztecCode) -> Vec<Point> {
|
||||||
int center = code.getMatrix().getWidth() / 2;
|
int center = code.getMatrix().getWidth() / 2;
|
||||||
int offset = code.isCompact() ? 5 : 7;
|
int offset = code.isCompact() ? 5 : 7;
|
||||||
List<Point> result = new ArrayList<>();
|
List<Point> result = new ArrayList<>();
|
||||||
@@ -185,5 +186,3 @@ public final class DetectorTest extends Assert {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,12 @@
|
|||||||
mod AztecDetectorResult;
|
mod AztecDetectorResult;
|
||||||
pub mod decoder;
|
pub mod decoder;
|
||||||
// pub mod detector;
|
pub mod detector;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod DecoderTest;
|
mod DecoderTest;
|
||||||
// #[cfg(test)]
|
// #[cfg(test)]
|
||||||
// mod EncoderTest;
|
// mod EncoderTest;
|
||||||
|
#[cfg(test)]
|
||||||
|
mod DetectorTest;
|
||||||
|
|
||||||
mod shared_test_methods;
|
mod shared_test_methods;
|
||||||
@@ -823,7 +823,7 @@ use crate::common::detector::MathUtils;
|
|||||||
*
|
*
|
||||||
* @author Sean Owen
|
* @author Sean Owen
|
||||||
*/
|
*/
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct RXingResultPoint {
|
pub struct RXingResultPoint {
|
||||||
x: f32,
|
x: f32,
|
||||||
y: f32,
|
y: f32,
|
||||||
|
|||||||
Reference in New Issue
Block a user