boofcv.struct.calib.CameraPinhole Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of boofcv-geo Show documentation
Show all versions of boofcv-geo 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.struct.calib;
/**
*
* Intrinsic camera parameters for a pinhole camera. Specifies the calibration
* matrix K and distortion parameters.
*
*
*
* [ fx skew cx ]
* K = [ 0 fy cy ]
* [ 0 0 1 ]
*
*
* @author Peter Abeles
*/
public class CameraPinhole extends CameraModel {
// serialization version
public static final long serialVersionUID = 1L;
/** focal length along x and y axis (units: pixels) */
public double fx,fy;
/** skew parameter, typically 0 (units: pixels)*/
public double skew;
/** image center (units: pixels) */
public double cx,cy;
/**
* Default constructor. flipY is false and everything else is zero or null.
*/
public CameraPinhole() {
}
public CameraPinhole(CameraPinhole param ) {
set(param);
}
public CameraPinhole(double fx, double fy,
double skew,
double cx, double cy,
int width, int height ) {
fsetK(fx, fy, skew, cx, cy, width, height);
}
public CameraPinhole fsetK(double fx, double fy,
double skew,
double cx, double cy,
int width, int height) {
this.fx = fx;
this.fy = fy;
this.skew = skew;
this.cx = cx;
this.cy = cy;
this.width = width;
this.height = height;
return this;
}
public void set( CameraPinhole param ) {
this.fx = param.fx;
this.fy = param.fy;
this.skew = param.skew;
this.cx = param.cx;
this.cy = param.cy;
this.width = param.width;
this.height = param.height;
}
/**
* Is the pixel coordinate inside the image
* @param x pixel X
* @param y pixel Y
* @return true if inside or false if not
*/
public boolean inside(double x , double y ) {
return x >= 0 && y >= 0 && x < width-1 && y <= height-1;
}
public double getCx() {
return cx;
}
public void setCx(double cx) {
this.cx = cx;
}
public double getCy() {
return cy;
}
public void setCy(double cy) {
this.cy = cy;
}
public double getFx() {
return fx;
}
public void setFx(double fx) {
this.fx = fx;
}
public double getFy() {
return fy;
}
public void setFy(double fy) {
this.fy = fy;
}
public double getSkew() {
return skew;
}
public void setSkew(double skew) {
this.skew = skew;
}
public void print() {
System.out.println("Shape "+width+" "+height);
System.out.printf("center %7.2f %7.2f\n", cx, cy);
System.out.println("fx = " + fx);
System.out.println("fy = "+fy);
System.out.println("skew = "+skew);
}
@Override
public T createLike() {
return (T)new CameraPinhole();
}
@Override
public String toString() {
return "CameraPinhole{" +
"fx=" + fx +
", fy=" + fy +
", skew=" + skew +
", cx=" + cx +
", cy=" + cy +
", width=" + width +
", height=" + height +
'}';
}
public boolean isEquals( CameraPinhole param , double tol ) {
if( Math.abs(fx-param.fx) > tol )
return false;
if( Math.abs(fy-param.fy) > tol )
return false;
if( Math.abs(skew-param.skew) > tol )
return false;
if( Math.abs(cx-param.cx) > tol )
return false;
if( Math.abs(cy-param.cy) > tol )
return false;
if( width != param.width)
return false;
return height==param.height;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy