![JAR search and dependency download from the Maven repository](/logo.png)
boofcv.abst.fiducial.calib.CalibrationDetectorSquareGrid Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of recognition Show documentation
Show all versions of recognition Show documentation
BoofCV is an open source Java library for real-time computer vision and robotics applications.
/*
* Copyright (c) 2011-2016, 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.calib;
import boofcv.abst.filter.binary.InputToBinary;
import boofcv.abst.geo.calibration.CalibrationDetector;
import boofcv.alg.fiducial.calib.grid.DetectSquareGridFiducial;
import boofcv.alg.geo.calibration.CalibrationObservation;
import boofcv.alg.shapes.polygon.BinaryPolygonDetector;
import boofcv.factory.filter.binary.FactoryThresholdBinary;
import boofcv.factory.shape.FactoryShapeDetector;
import boofcv.struct.image.GrayF32;
import georegression.struct.point.Point2D_F64;
import java.util.ArrayList;
import java.util.List;
/**
* Implementation of {@link CalibrationDetector} for square grid target types.
*
* @author Peter Abeles
*/
public class CalibrationDetectorSquareGrid implements CalibrationDetector {
DetectSquareGridFiducial detect;
List layoutPoints;
CalibrationObservation detected;
public CalibrationDetectorSquareGrid(ConfigSquareGrid config) {
if( config.refineWithCorners) {
config.square.refine = config.configRefineCorners;
} else {
config.square.refine = config.configRefineLines;
}
double spaceToSquareRatio = config.spaceWidth/config.squareWidth;
InputToBinary inputToBinary =
FactoryThresholdBinary.threshold(config.thresholding,GrayF32.class);
BinaryPolygonDetector detectorSquare =
FactoryShapeDetector.polygon(config.square,GrayF32.class);
detect = new DetectSquareGridFiducial(config.numRows,config.numCols,
spaceToSquareRatio,inputToBinary,detectorSquare);
layoutPoints = createLayout(config.numRows, config.numCols, config.squareWidth,config.spaceWidth);
}
@Override
public boolean process(GrayF32 input) {
if( detect.process(input) ) {
detected = new CalibrationObservation();
List found = detect.getCalibrationPoints();
for (int i = 0; i < found.size(); i++) {
detected.add( found.get(i), i );
}
return true;
} else {
return false;
}
}
/**
* Creates a target that is composed of squares. The squares are spaced out and each corner provides
* a calibration point.
*
* @param numRows Number of rows in calibration target. Must be odd.
* @param numCols Number of column in each calibration target. Must be odd.
* @param squareWidth How wide each square is. Units are target dependent.
* @param spaceWidth Distance between the sides on each square. Units are target dependent.
* @return Target description
*/
public static List createLayout(int numRows, int numCols, double squareWidth, double spaceWidth)
{
List all = new ArrayList();
double width = (numCols*squareWidth + (numCols-1)*spaceWidth);
double height = (numRows*squareWidth + (numRows-1)*spaceWidth);
double startX = -width/2;
double startY = -height/2;
for( int i = numRows-1; i >= 0; i-- ) {
// this will be on the top of the black in the row
double y = startY + i*(squareWidth+spaceWidth)+squareWidth;
List top = new ArrayList();
List bottom = new ArrayList();
for( int j = 0; j < numCols; j++ ) {
double x = startX + j*(squareWidth+spaceWidth);
top.add( new Point2D_F64(x,y));
top.add( new Point2D_F64(x+squareWidth,y));
bottom.add( new Point2D_F64(x,y-squareWidth));
bottom.add( new Point2D_F64(x + squareWidth, y - squareWidth));
}
all.addAll(top);
all.addAll(bottom);
}
return all;
}
@Override
public CalibrationObservation getDetectedPoints() {
return detected;
}
@Override
public List getLayout() {
return layoutPoints;
}
public DetectSquareGridFiducial getAlgorithm() {
return detect;
}
/**
* Returns number of rows in the grid
* @return number of rows
*/
public int getGridRows() {
return detect.getRows();
}
/**
* Returns number of columns in the grid
* @return number of columns
*/
public int getGridColumns() {
return detect.getColumns();
}
/**
* Returns number of rows in calibration point grid
* @return number of rows
*/
public int getPointRows() {
return detect.getCalibrationRows();
}
/**
* Returns number of columns in calibration point grid
* @return number of columns
*/
public int getPointColumns() {
return detect.getCalibrationCols();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy