-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added QR and Micro QR Rendering - Added a simple function for rendering micro qr codes as an image
- Loading branch information
1 parent
c6f9adf
commit 22eb1fa
Showing
5 changed files
with
221 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...fcv-recognition/src/benchmark/java/boofcv/abst/fiducial/BenchmarkMicroQrCodeDetector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (c) 2022, Peter Abeles. All Rights Reserved. | ||
* | ||
* This file is part of BoofCV (http://boofcv.org). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package boofcv.abst.fiducial; | ||
|
||
import boofcv.BoofTesting; | ||
import boofcv.abst.distort.FDistort; | ||
import boofcv.alg.fiducial.microqr.MicroQrCode; | ||
import boofcv.alg.fiducial.microqr.MicroQrCodeEncoder; | ||
import boofcv.alg.fiducial.microqr.MicroQrCodeGenerator; | ||
import boofcv.alg.misc.GImageMiscOps; | ||
import boofcv.factory.fiducial.FactoryFiducial; | ||
import boofcv.misc.BoofMiscOps; | ||
import boofcv.struct.image.GrayU8; | ||
import org.openjdk.jmh.annotations.*; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
import org.openjdk.jmh.runner.options.TimeValue; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@Warmup(iterations = 2) | ||
@Measurement(iterations = 3) | ||
@State(Scope.Benchmark) | ||
@Fork(value = 1) | ||
public class BenchmarkMicroQrCodeDetector { | ||
|
||
List<GrayU8> images = new ArrayList<>(); | ||
|
||
MicroQrCodeDetector<GrayU8> detector = FactoryFiducial.microqr(null, GrayU8.class); | ||
|
||
/** | ||
* Generate a set of synthetic images with two markers in it to test against | ||
*/ | ||
@Setup public void setup() { | ||
var rand = new Random(BoofTesting.BASE_SEED); | ||
MicroQrCode qr1 = new MicroQrCodeEncoder().addAutomatic("1").fixate(); | ||
MicroQrCode qr2 = new MicroQrCodeEncoder().addAutomatic("ALPHA NUMERIC 123").fixate(); | ||
|
||
GrayU8 image1 = MicroQrCodeGenerator.renderImage(5, 2, qr1); | ||
GrayU8 image2 = MicroQrCodeGenerator.renderImage(5, 2, qr2); | ||
|
||
var fullImage = new GrayU8(image1.width + image2.width + 50, image1.width + image2.width + 100); | ||
GImageMiscOps.fillUniform(fullImage, rand, 50, 150); | ||
|
||
GImageMiscOps.copy(0, 0, 10, 15, image1.width, image1.height, image1, fullImage); | ||
GImageMiscOps.copy(0, 0, 20 + image1.width, 50, image2.width, image2.height, image2, fullImage); | ||
|
||
images.add(fullImage); | ||
|
||
// manually checked that all the distorted images have markers inside the image | ||
for (int i = 0; i < 4; i++) { | ||
GrayU8 distorted = fullImage.createSameShape(); | ||
new FDistort(fullImage, distorted).affine( | ||
1.0, rand.nextGaussian()*0.01, | ||
rand.nextGaussian()*0.01, 1.0, | ||
rand.nextGaussian()*0.5, rand.nextGaussian()*0.5).apply(); | ||
images.add(distorted); | ||
} | ||
} | ||
|
||
@Benchmark public void qrcode() { | ||
for (int imageIdx = 0; imageIdx < images.size(); imageIdx++) { | ||
detector.process(images.get(imageIdx)); | ||
// sanity check to make sure everything is running as expected | ||
BoofMiscOps.checkEq(2, detector.getDetections().size()); | ||
} | ||
} | ||
|
||
public static void main( String[] args ) throws RunnerException { | ||
Options opt = new OptionsBuilder() | ||
.include(BenchmarkMicroQrCodeDetector.class.getSimpleName()) | ||
.warmupTime(TimeValue.seconds(1)) | ||
.measurementTime(TimeValue.seconds(1)) | ||
.build(); | ||
|
||
new Runner(opt).run(); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
main/boofcv-recognition/src/benchmark/java/boofcv/abst/fiducial/BenchmarkQrCodeDetector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (c) 2022, Peter Abeles. All Rights Reserved. | ||
* | ||
* This file is part of BoofCV (http://boofcv.org). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package boofcv.abst.fiducial; | ||
|
||
import boofcv.BoofTesting; | ||
import boofcv.abst.distort.FDistort; | ||
import boofcv.alg.fiducial.qrcode.QrCode; | ||
import boofcv.alg.fiducial.qrcode.QrCodeEncoder; | ||
import boofcv.alg.fiducial.qrcode.QrCodeGeneratorImage; | ||
import boofcv.alg.misc.GImageMiscOps; | ||
import boofcv.factory.fiducial.FactoryFiducial; | ||
import boofcv.misc.BoofMiscOps; | ||
import boofcv.struct.image.GrayU8; | ||
import org.openjdk.jmh.annotations.*; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
import org.openjdk.jmh.runner.options.TimeValue; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@BenchmarkMode(Mode.AverageTime) | ||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | ||
@Warmup(iterations = 2) | ||
@Measurement(iterations = 3) | ||
@State(Scope.Benchmark) | ||
@Fork(value = 1) | ||
public class BenchmarkQrCodeDetector { | ||
|
||
List<GrayU8> images = new ArrayList<>(); | ||
|
||
QrCodeDetector<GrayU8> detector = FactoryFiducial.qrcode(null, GrayU8.class); | ||
|
||
/** | ||
* Generate a set of synthetic images with two markers in it to test against | ||
*/ | ||
@Setup public void setup() { | ||
var rand = new Random(BoofTesting.BASE_SEED); | ||
QrCode qr1 = new QrCodeEncoder().addAutomatic("small").fixate(); | ||
QrCode qr2 = new QrCodeEncoder().addAutomatic("Much Larger Than the Oth9er!!#").fixate(); | ||
|
||
GrayU8 image1 = new QrCodeGeneratorImage(5).render(qr1).getGray(); | ||
GrayU8 image2 = new QrCodeGeneratorImage(5).render(qr2).getGray(); | ||
|
||
var fullImage = new GrayU8(image1.width + image2.width + 50, image1.width + image2.width + 100); | ||
GImageMiscOps.fillUniform(fullImage, rand, 50, 150); | ||
|
||
GImageMiscOps.copy(0, 0, 10, 15, image1.width, image1.height, image1, fullImage); | ||
GImageMiscOps.copy(0, 0, 20 + image1.width, 50, image2.width, image2.height, image2, fullImage); | ||
|
||
images.add(fullImage); | ||
|
||
// manually checked that all the distorted images have markers inside the image | ||
for (int i = 0; i < 4; i++) { | ||
GrayU8 distorted = fullImage.createSameShape(); | ||
new FDistort(fullImage, distorted).affine( | ||
1.0 + rand.nextGaussian()*0.1, rand.nextGaussian()*0.01, | ||
rand.nextGaussian()*0.01, 1.0 + rand.nextGaussian()*0.1, | ||
rand.nextGaussian()*0.5, rand.nextGaussian()*0.5).apply(); | ||
images.add(distorted); | ||
} | ||
} | ||
|
||
@Benchmark public void qrcode() { | ||
for (int imageIdx = 0; imageIdx < images.size(); imageIdx++) { | ||
detector.process(images.get(imageIdx)); | ||
// sanity check to make sure everything is running as expected | ||
BoofMiscOps.checkEq(2, detector.getDetections().size()); | ||
} | ||
} | ||
|
||
public static void main( String[] args ) throws RunnerException { | ||
Options opt = new OptionsBuilder() | ||
.include(BenchmarkQrCodeDetector.class.getSimpleName()) | ||
.warmupTime(TimeValue.seconds(1)) | ||
.measurementTime(TimeValue.seconds(1)) | ||
.build(); | ||
|
||
new Runner(opt).run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters