Skip to content

Commit

Permalink
don't warn about image/sensor proportions mismatch if the 90 deg rota…
Browse files Browse the repository at this point in the history
…ted image fits the sensor
  • Loading branch information
stuffmatic committed Nov 12, 2018
1 parent 74a6e85 commit 8ce40f7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/gui/components/result-panel/result-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -273,6 +275,12 @@ export default class ResultPanel extends React.PureComponent<ResultPanelProps> {
}

const displayFocalLength = this.props.resultDisplaySettings.displayAbsoluteFocalLength
const proportionsMatch = Solver.imageProportionsMatchSensor(
cameraParameters.imageWidth,
cameraParameters.imageHeight,
sensorWidth,
sensorHeight
)

return (
<div className='panel-section bottom-border'>
Expand All @@ -282,6 +290,12 @@ export default class ResultPanel extends React.PureComponent<ResultPanelProps> {
onChange={ (enabled: boolean) => { this.props.onDisplayAbsoluteFocalLengthChanged(enabled) } }
/>
{ displayFocalLength ? this.renderCameraPresetForm(absoluteFocalLength, cameraData) : null }
{ !proportionsMatch ? (<BulletList
messages={
[ strings.imageSensorProportionsMismatch ]
}
type={BulletListType.Warnings}
/>) : null }
</div>
)
}
Expand Down
22 changes: 20 additions & 2 deletions src/gui/solver/solver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/gui/strings/strings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const strings = {
customCameraPresetName: 'Custom camera',
unitMm: 'mm'
unitMm: 'mm',
imageSensorProportionsMismatch: 'Image/sensor proportions mismatch'
}

export default strings

0 comments on commit 8ce40f7

Please sign in to comment.