
boofcv.abst.fiducial.QrCodePreciseDetector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of boofcv-recognition Show documentation
Show all versions of boofcv-recognition Show documentation
BoofCV is an open source Java library for real-time computer vision and robotics applications.
/*
* Copyright (c) 2011-2018, 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.abst.filter.binary.BinaryContourHelper;
import boofcv.abst.filter.binary.InputToBinary;
import boofcv.alg.fiducial.qrcode.QrCode;
import boofcv.alg.fiducial.qrcode.QrCodeDecoderImage;
import boofcv.alg.fiducial.qrcode.QrCodePositionPatternDetector;
import boofcv.alg.shapes.polygon.DetectPolygonBinaryGrayRefine;
import boofcv.misc.MovingAverage;
import boofcv.struct.image.GrayU8;
import boofcv.struct.image.ImageGray;
import java.util.List;
/**
* A QR-Code detector which is designed to find the location of corners in the finder pattern precisely.
*
* @param
*/
public class QrCodePreciseDetector> implements QrCodeDetector
{
QrCodePositionPatternDetector detectPositionPatterns;
QrCodeDecoderImage decoder;
InputToBinary inputToBinary;
Class imageType;
BinaryContourHelper contourHelper;
// runtime profiling
boolean profiler = false;
protected MovingAverage milliBinary = new MovingAverage(0.8);
protected MovingAverage milliDecoding = new MovingAverage(0.8);
public QrCodePreciseDetector(InputToBinary inputToBinary,
QrCodePositionPatternDetector detectPositionPatterns,
boolean copyBinary, Class imageType) {
this.inputToBinary = inputToBinary;
this.detectPositionPatterns = detectPositionPatterns;
this.decoder = new QrCodeDecoderImage<>(imageType);
this.imageType = imageType;
this.contourHelper = new BinaryContourHelper(detectPositionPatterns.getSquareDetector().getDetector().getContourFinder(),copyBinary);
}
@Override
public void process(T gray) {
long time0 = System.nanoTime();
contourHelper.reshape(gray.width,gray.height);
inputToBinary.process(gray,contourHelper.withoutPadding());
long time1 = System.nanoTime();
milliBinary.update((time1-time0)*1e-6);
if( profiler )
System.out.printf("qrcode: binary %5.2f ",milliBinary.getAverage());
detectPositionPatterns.process(gray,contourHelper.padded());
time0 = System.nanoTime();
decoder.process(detectPositionPatterns.getPositionPatterns(),gray);
time1 = System.nanoTime();
milliDecoding.update((time1-time0)*1e-6);
if( profiler )
System.out.printf(" decoding %5.1f\n",milliDecoding.getAverage());
}
@Override
public List getDetections() {
return decoder.getFound();
}
@Override
public List getFailures() {
return decoder.getFailures();
}
public GrayU8 getBinary() {
return contourHelper.withoutPadding();
}
public void setProfilerState( boolean active ) {
profiler = active;
detectPositionPatterns.setProfilerState(active);
}
public void resetRuntimeProfiling() {
milliBinary.reset();
milliDecoding.reset();
detectPositionPatterns.resetRuntimeProfiling();
}
public QrCodePositionPatternDetector getDetectPositionPatterns() {
return detectPositionPatterns;
}
public DetectPolygonBinaryGrayRefine getSquareDetector() {
return detectPositionPatterns.getSquareDetector();
}
public QrCodeDecoderImage getDecoder() {
return decoder;
}
@Override
public Class getImageType() {
return imageType;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy