All Downloads are FREE. Search and download functionalities are using the official Maven repository.

boofcv.alg.distort.spherical.EquirectangularTools_F32 Maven / Gradle / Ivy

Go to download

BoofCV is an open source Java library for real-time computer vision and robotics applications.

There is a newer version: 1.1.5
Show newest version
/*
 * Copyright (c) 2021, 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.spherical;

import javax.annotation.Generated;
import boofcv.struct.geo.GeoLL_F32;
import georegression.geometry.ConvertCoordinates3D_F32;
import georegression.metric.UtilAngle;
import georegression.misc.GrlConstants;
import georegression.struct.point.Point2D_F32;
import georegression.struct.point.Point3D_F32;

/**
 * Contains common operations for handling coordinates in an equirectangular image.
 * On most globes, a positive latitude corresponds to the north pole, or up, and negative towards the south pole.
 * Images have 0 on the top and increase downwards. To compensate for this the y-axis can be flipped. This
 * is indicated by functions with FV (flip vertical) on the end of their name.
 *
 * Coordinate System:
 * 
    *
  • longitude is along the x-axis and goes from -pi to pi
  • *
  • latitude is along the y-axis and goes from -pi/2 to pi/2
  • *
  • image center (width/2, (height-1)/2.0ff) or (lat=0, lon=0) corresponds to a unit sphere of (1,0,0)
  • *
  • unit sphere of (0,0,1) is pixel (width/2,0) and (0,0,-1) is (width/2,height-1)
  • *
  • unit sphere of (0,1,0) is pixel (3*width/4,(height-1)/2) and (0,0,-1) is (width/4,(height-1)/2)
  • *
* Coordinate System with y-flipped: *
    *
  • longitude is along the x-axis and goes from -pi to pi
  • *
  • latitude is along the y-axis and goes from pi/2 to -pi/2
  • *
  • image center (width/2, height/2) or (lat=0, lon=0) corresponds to a unit sphere of (1,0,0)
  • *
  • unit sphere of (0,0,1) is pixel (width/2,height-1) and (0,0,-1) is (width/2,0)
  • *
  • unit sphere of (0,1,0) is pixel (3*width/4,(height-1)/2) and (0,0,-1) is (width/4,(height-1)/2)
  • *
* *

Latitude and Longitude shown on a sphere in equirectangular format. Note that y is NOT flipped and angles * are shown in degrees not radians git push.

*
* *
* * @author Peter Abeles */ @Generated("boofcv.alg.distort.spherical.EquirectangularTools_F64") public class EquirectangularTools_F32 { // input image width and height int width; int height; // internal storage to avoid declaring new memory GeoLL_F32 temp = new GeoLL_F32(); /** * Specifies the image and which latitude/longtiude will comprise the center axises * * @param width Image width * @param height Image height */ public void configure( int width, int height ) { this.width = width; this.height = height; } /** * Converts equirectangular into normalized pointing vector * * @param x pixel coordinate in equirectangular image * @param y pixel coordinate in equirectangular image * @param norm Normalized pointing vector */ public void equiToNorm( float x, float y, Point3D_F32 norm ) { equiToLatLon(x, y, temp); ConvertCoordinates3D_F32.latlonToUnitVector(temp.lat, temp.lon, norm); } public void normToEqui( float nx, float ny, float nz, Point2D_F32 rect ) { /**/double r = /**/Math.sqrt(nx*nx + ny*ny); /**/double lon = /**/Math.atan2(ny, nx); /**/double lat = UtilAngle.atanSafe(-nz, r); latlonToEqui((float)lat, (float)lon, rect); } public void equiToNormFV( float x, float y, Point3D_F32 norm ) { equiToLatLonFV(x, y, temp); ConvertCoordinates3D_F32.latlonToUnitVector(temp.lat, temp.lon, norm); } public void normToEquiFV( float nx, float ny, float nz, Point2D_F32 rect ) { /**/double r = /**/Math.sqrt(nx*nx + ny*ny); /**/double lon = /**/Math.atan2(ny, nx); /**/double lat = UtilAngle.atanSafe(-nz, r); latlonToEquiFV((float)lat, (float)lon, rect); } /** * Converts the equirectangular coordinate into a latitude and longitude * * @param x pixel coordinate in equirectangular image * @param y pixel coordinate in equirectangular image * @param geo (output) */ public void equiToLatLon( float x, float y, GeoLL_F32 geo ) { geo.lon = (x/width - 0.5f)*GrlConstants.F_PI2; geo.lat = (y/(height - 1) - 0.5f)*GrlConstants.F_PI; } /** *

* Converts the equirectangular coordinate into a latitude and longitude. * Vertical equirectangular axis has been flipped *

* y' = height - y - 1 * * @param x pixel coordinate in equirectangular image * @param y pixel coordinate in equirectangular image * @param geo (output) */ public void equiToLatLonFV( float x, float y, GeoLL_F32 geo ) { geo.lon = (x/width - 0.5f)*GrlConstants.F_PI2; geo.lat = ((height - y - 1.0f)/(height - 1) - 0.5f)*GrlConstants.F_PI; } /** * Convert from latitude-longitude coordinates into equirectangular coordinates * * @param lat Latitude * @param lon Longitude * @param rect (Output) equirectangular coordinate */ public void latlonToEqui( float lat, float lon, Point2D_F32 rect ) { rect.x = UtilAngle.wrapZeroToOne(lon/GrlConstants.F_PI2 + 0.5f)*width; rect.y = UtilAngle.reflectZeroToOne(lat/GrlConstants.F_PI + 0.5f)*(height - 1); } /** * Convert from latitude-longitude coordinates into equirectangular coordinates. * Vertical equirectangular axis has been flipped * * @param lat Latitude * @param lon Longitude * @param rect (Output) equirectangular coordinate */ public void latlonToEquiFV( float lat, float lon, Point2D_F32 rect ) { rect.x = UtilAngle.wrapZeroToOne(lon/GrlConstants.F_PI2 + 0.5f)*width; rect.y = UtilAngle.reflectZeroToOne(lat/GrlConstants.F_PI + 0.5f)*(height - 1); rect.y = height - rect.y - 1; } public int getWidth() { return width; } public int getHeight() { return height; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy