2019-09-19 14:07:42 -04:00
|
|
|
package com.chameleonvision.vision.camera;
|
2019-09-16 04:08:23 -04:00
|
|
|
|
|
|
|
|
import org.apache.commons.math3.fraction.Fraction;
|
|
|
|
|
import org.apache.commons.math3.util.FastMath;
|
|
|
|
|
|
2019-09-21 13:05:00 -04:00
|
|
|
@SuppressWarnings("WeakerAccess")
|
2019-09-16 04:08:23 -04:00
|
|
|
public class CameraValues {
|
|
|
|
|
public final int ImageWidth;
|
|
|
|
|
public final int ImageHeight;
|
|
|
|
|
public final double FOV;
|
|
|
|
|
public final double ImageArea;
|
|
|
|
|
public final double CenterX;
|
|
|
|
|
public final double CenterY;
|
|
|
|
|
public final double DiagonalView;
|
|
|
|
|
public final Fraction AspectFraction;
|
|
|
|
|
public final int HorizontalRatio;
|
|
|
|
|
public final int VerticalRatio;
|
|
|
|
|
public final double HorizontalView;
|
|
|
|
|
public final double VerticalView;
|
|
|
|
|
public final double HorizontalFocalLength;
|
|
|
|
|
public final double VerticalFocalLength;
|
|
|
|
|
|
2019-09-18 03:08:06 -04:00
|
|
|
public CameraValues(Camera camera) {
|
2019-09-19 14:07:42 -04:00
|
|
|
this(camera.getVideoMode().width, camera.getVideoMode().height, camera.getFOV());
|
2019-09-18 03:08:06 -04:00
|
|
|
}
|
|
|
|
|
|
2019-09-16 04:08:23 -04:00
|
|
|
public CameraValues(int imageWidth, int imageHeight, double fov) {
|
|
|
|
|
ImageWidth = imageWidth;
|
|
|
|
|
ImageHeight = imageHeight;
|
|
|
|
|
FOV = fov;
|
|
|
|
|
ImageArea = ImageWidth * ImageHeight;
|
|
|
|
|
CenterX = ((double) ImageWidth / 2) - 0.5;
|
|
|
|
|
CenterY = ((double) ImageHeight / 2) - 0.5;
|
|
|
|
|
DiagonalView = FastMath.toRadians(FOV);
|
|
|
|
|
AspectFraction = new Fraction(ImageWidth, ImageHeight);
|
|
|
|
|
HorizontalRatio = AspectFraction.getNumerator();
|
|
|
|
|
VerticalRatio = AspectFraction.getDenominator();
|
|
|
|
|
HorizontalView = FastMath.atan(FastMath.tan(DiagonalView / 2) * (HorizontalRatio / DiagonalView)) * 2;
|
|
|
|
|
VerticalView = FastMath.atan(FastMath.tan(DiagonalView/2) * (VerticalRatio / DiagonalView)) * 2;
|
|
|
|
|
HorizontalFocalLength = ImageWidth / (2 * FastMath.tan(HorizontalView /2));
|
2019-09-21 08:06:27 -07:00
|
|
|
VerticalFocalLength = ImageHeight / (2 * FastMath.tan(VerticalView /2));
|
2019-09-16 04:08:23 -04:00
|
|
|
}
|
2019-09-17 13:59:53 +03:00
|
|
|
public double CalculatePitch(double PixelY, double centerY){
|
2019-09-21 08:06:27 -07:00
|
|
|
double pitch = (FastMath.toDegrees((FastMath.atan(PixelY - centerY) / VerticalFocalLength)));
|
|
|
|
|
return (pitch * -1);
|
2019-09-17 13:59:53 +03:00
|
|
|
}
|
|
|
|
|
public double CalculateYaw(double PixelX, double centerX){
|
|
|
|
|
return FastMath.toDegrees(FastMath.atan(PixelX - centerX) / HorizontalFocalLength);
|
|
|
|
|
}
|
2019-09-16 04:08:23 -04:00
|
|
|
}
|