diff --git a/src/gui/components/result-panel/result-panel.tsx b/src/gui/components/result-panel/result-panel.tsx index bd09639..be3e3bb 100644 --- a/src/gui/components/result-panel/result-panel.tsx +++ b/src/gui/components/result-panel/result-panel.tsx @@ -13,6 +13,8 @@ import MathUtil from '../../solver/math-util' import CoordinatesUtil, { ImageCoordinateFrame } from '../../solver/coordinates-util' import Button from '../common/button' import Checkbox from '../settings-panel/checkbox' +import Solver from '../../solver/solver' +import strings from '../../strings/strings' interface ResultPanelProps { globalSettings: GlobalSettings @@ -273,6 +275,12 @@ export default class ResultPanel extends React.PureComponent { } const displayFocalLength = this.props.resultDisplaySettings.displayAbsoluteFocalLength + const proportionsMatch = Solver.imageProportionsMatchSensor( + cameraParameters.imageWidth, + cameraParameters.imageHeight, + sensorWidth, + sensorHeight + ) return (
@@ -282,6 +290,12 @@ export default class ResultPanel extends React.PureComponent { onChange={ (enabled: boolean) => { this.props.onDisplayAbsoluteFocalLengthChanged(enabled) } } /> { displayFocalLength ? this.renderCameraPresetForm(absoluteFocalLength, cameraData) : null } + { !proportionsMatch ? () : null }
) } diff --git a/src/gui/solver/solver.ts b/src/gui/solver/solver.ts index b14784a..e5642bc 100644 --- a/src/gui/solver/solver.ts +++ b/src/gui/solver/solver.ts @@ -9,6 +9,7 @@ import CoordinatesUtil, { ImageCoordinateFrame } from './coordinates-util' import { SolverResult, CameraParameters } from './solver-result' import { defaultSolverResult } from './../defaults/solver-result' import { cameraPresets } from './camera-presets' +import strings from '../strings/strings' /** * The solver handles estimation of focal length and camera orientation @@ -68,8 +69,8 @@ export default class Solver { relativeFocalLength = 2 * absoluteFocalLength / sensorHeight } - if (Math.abs(sensorAspectRatio - imageWidth / imageHeight) > 0.01) { // TODO: choose epsilon - result.warnings.push('Image/sensor aspect ratio mismatch') + if (!this.imageProportionsMatchSensor(sensorWidth, sensorHeight, imageWidth, imageHeight)) { + result.warnings.push(strings.imageSensorProportionsMismatch) } // Compute the input vanishing point in image plane coordinates @@ -246,6 +247,23 @@ export default class Solver { return result } + static imageProportionsMatchSensor(imageWidth: number, imageHeight: number, sensorWidth: number, sensorHeight: number): boolean { + if (sensorHeight == 0 || sensorWidth == 0 || imageWidth == 0 || imageHeight == 0) { + return false + } + const epsilon = 0.01 + const imageAspectRatio = imageWidth / imageHeight + const sensorAspectRatio = sensorWidth / sensorHeight + + const imageFitsSensor = Math.abs(sensorAspectRatio - imageAspectRatio) < epsilon + const rotated90DegImageFitsSensor = Math.abs(sensorAspectRatio - 1 / imageAspectRatio) < epsilon + if (!imageFitsSensor && !rotated90DegImageFitsSensor) { + return false + } + + return true + } + /** * Computes the focal length based on two vanishing points and a center of projection. * See 3.2 "Determining the focal length from a single image" diff --git a/src/gui/strings/strings.ts b/src/gui/strings/strings.ts index 2bd1136..e8488ee 100644 --- a/src/gui/strings/strings.ts +++ b/src/gui/strings/strings.ts @@ -1,6 +1,7 @@ const strings = { customCameraPresetName: 'Custom camera', - unitMm: 'mm' + unitMm: 'mm', + imageSensorProportionsMismatch: 'Image/sensor proportions mismatch' } export default strings