/*
* 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.alg.distort.universal;
import boofcv.struct.calib.CameraUniversalOmni;
import georegression.misc.GrlConstants;
import georegression.struct.point.Point2D_F32;
import georegression.struct.point.Point3D_F32;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
/**
* @author Peter Abeles
*/
public class TestUniOmniPtoS_F32 {
/**
* Tell it to project the center pixel forwards. All the distortion shouldn't affect it there and it should
* appear to be image center exactly.
*/
@Test
public void centerIsCenter() {
centerIsCenter(1.0f);
centerIsCenter(0.5f);
centerIsCenter(3.5f);
}
private void centerIsCenter( float mirror ) {
CameraUniversalOmni model = createModel(mirror);
UniOmniPtoS_F32 alg = new UniOmniPtoS_F32();
alg.setModel(model);
Point3D_F32 found = new Point3D_F32(10,10, 10);
alg.compute(320,240, found); // directly forward on unit sphere
assertEquals(0,found.x, GrlConstants.FLOAT_TEST_TOL);
assertEquals(0,found.y, GrlConstants.FLOAT_TEST_TOL);
assertEquals(1,found.z, GrlConstants.FLOAT_TEST_TOL);
}
@Test
public void back_and_forth() {
back_and_forth(1.0f);
back_and_forth(0.5f);
back_and_forth(3.5f);
}
private void back_and_forth( float mirror ) {
CameraUniversalOmni model = createModel(mirror);
UniOmniPtoS_F32 pixelToUnit = new UniOmniPtoS_F32();
pixelToUnit.setModel(model);
UniOmniStoP_F32 unitToPixel = new UniOmniStoP_F32();
unitToPixel.setModel(model);
List<Point2D_F32> listPixels = new ArrayList<>();
listPixels.add( new Point2D_F32(320,240));
listPixels.add( new Point2D_F32(320,200));
listPixels.add( new Point2D_F32(320,280));
listPixels.add( new Point2D_F32(280,240));
listPixels.add( new Point2D_F32(360,240));
listPixels.add( new Point2D_F32(280,240));
listPixels.add( new Point2D_F32(240,180));
for( Point2D_F32 pixel : listPixels ) {
Point3D_F32 circle = new Point3D_F32(10,10, 10);
pixelToUnit.compute(pixel.x,pixel.y, circle); // directly forward on unit sphere
// it should be on the unit circle
assertEquals(1.0f, circle.norm(), GrlConstants.FLOAT_TEST_TOL);
Point2D_F32 found = new Point2D_F32();
unitToPixel.compute(circle.x, circle.y, circle.z, found);
assertEquals(pixel.x, found.x, GrlConstants.FLOAT_TEST_TOL_SQRT);
assertEquals(pixel.y, found.y, GrlConstants.FLOAT_TEST_TOL_SQRT);
}
}
public static CameraUniversalOmni createModel(float mirror) {
CameraUniversalOmni model = new CameraUniversalOmni(2);
model.fsetK(400,405,0.01f,320,240,640,480);
model.fsetMirror(mirror);
model.fsetRadial(0.01f,-0.03f);
model.fsetTangental(0.001f,0.002f);
return model;
}
}