Skip to content

Commit

Permalink
Merge pull request #4 from zygmuntszpak/covariance_matrix
Browse files Browse the repository at this point in the history
Adds measure of uncertainty for AML-based  fundamental matrix estimate
  • Loading branch information
zygmuntszpak authored Jun 1, 2018
2 parents 1d9f357 + cfa2996 commit c366e34
Show file tree
Hide file tree
Showing 41 changed files with 884 additions and 292 deletions.
9 changes: 6 additions & 3 deletions src/MultipleViewGeometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ __precompile__()
module MultipleViewGeometry

using Compat
using StaticArrays



Expand All @@ -13,15 +14,17 @@ export CostFunction, ApproximateMaximumLikelihood, AML
export HomogeneousCoordinates
export CoordinateSystemTransformation, CanonicalToHartley, HartleyToCanonical
export CovarianceMatrices
export Point2DH, Point3DH
export HessianApproximation, CanonicalApproximation, CovarianceEstimationScheme

# Aliases exported from math_aliases.jl
export βŠ—, βˆ‘, √

# Functions exported from `operators.jl`.
export 𝑛, smallest_eigenpair,vec2antisym
export 𝑛, βˆ‚π‘›, smallest_eigenpair,vec2antisym

# Functions exported from `hartley_transformation.jl`.
export hartley_normalization, hartley_transformation
export hartley_normalization, hartley_normalization!, hartley_transformation

# Functions exported from `transform.jl`.
export transform
Expand All @@ -45,7 +48,7 @@ export project
export rotx, roty, rotz, rotxyz, rodrigues2matrix

# Functions exported from `cost_functions.jl`
export cost, X
export cost, X, covariance_matrix, covariance_matrix_debug

include("math_aliases/ModuleMathAliases.jl")
include("types/ModuleTypes.jl")
Expand Down
1 change: 1 addition & 0 deletions src/carriers/ModuleCarriers.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module ModuleCarriers
using MultipleViewGeometry.ModuleTypes, MultipleViewGeometry.ModuleMathAliases, MultipleViewGeometry.ModuleOperators
using StaticArrays
export βˆ‚β‚“u, uβ‚“
include("carriers.jl")
end
24 changes: 14 additions & 10 deletions src/carriers/carriers.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
# Carrier vector for fundamental matrix estimation.
function βˆ‚β‚“u(entity::FundamentalMatrix, π’Ÿ)
m, mΚΉ = π’Ÿ
𝐦 = 𝑛(collect(Float64,m.coords))
𝐦ʹ = 𝑛(collect(Float64,mΚΉ.coords))
@inline function βˆ‚β‚“u(entity::FundamentalMatrix, π’Ÿ)
m, mΚΉ = collect(π’Ÿ)
# 𝐦 = 𝑛(collect(Float64,m.coords))
# 𝐦ʹ = 𝑛(collect(Float64,mΚΉ.coords))
𝐦 = 𝑛(m)
𝐦ʹ = 𝑛(mΚΉ)
βˆ‚β‚“u(entity, 𝐦 , 𝐦ʹ)
end

function βˆ‚β‚“u(entity::FundamentalMatrix, 𝐦::Vector{Float64}, 𝐦ʹ::Vector{Float64})
@inline function βˆ‚β‚“u(entity::FundamentalMatrix, 𝐦::AbstractVector, 𝐦ʹ::AbstractVector)
πžβ‚ = [1.0 0.0 0.0]'
πžβ‚‚ = [0.0 1.0 0.0]'
[(πžβ‚ βŠ— 𝐦ʹ) (πžβ‚‚ βŠ— 𝐦ʹ) (𝐦 βŠ— πžβ‚) (𝐦 βŠ— πžβ‚‚)]
end


function uβ‚“(entity::FundamentalMatrix, π’Ÿ)
m, mΚΉ = π’Ÿ
𝐦 = 𝑛(collect(Float64,m.coords))
𝐦ʹ = 𝑛(collect(Float64,mΚΉ.coords))
@inline function uβ‚“(entity::FundamentalMatrix, π’Ÿ)
m, mΚΉ = collect(π’Ÿ)
# 𝐦 = 𝑛(collect(Float64,m.coords))
# 𝐦ʹ = 𝑛(collect(Float64,mΚΉ.coords))
𝐦 = 𝑛(m)
𝐦ʹ = 𝑛(mΚΉ)
uβ‚“(entity, 𝐦 , 𝐦ʹ)
end

function uβ‚“(entity::FundamentalMatrix, 𝐦::Vector{Float64}, 𝐦ʹ::Vector{Float64})
@inline function uβ‚“(entity::FundamentalMatrix, 𝐦::AbstractVector, 𝐦ʹ::AbstractVector)
𝐦 βŠ— 𝐦ʹ
end
2 changes: 2 additions & 0 deletions src/construct/ModuleConstruct.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module ModuleConstruct
using MultipleViewGeometry.ModuleTypes, MultipleViewGeometry.ModuleMathAliases, MultipleViewGeometry.ModuleOperators
using MultipleViewGeometry.ModuleProjection
using StaticArrays
export construct

include("construct_projectionmatrix.jl")
include("construct_fundamentalmatrix.jl")
end
23 changes: 11 additions & 12 deletions src/construct/construct_fundamentalmatrix.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
function construct( e::FundamentalMatrix,
πŠβ‚::AbstractArray{T,2},
𝐑₁::AbstractArray{T,2},
𝐭₁::AbstractArray{T,1},
πŠβ‚‚::AbstractArray{T,2},
𝐑₂::AbstractArray{T,2},
𝐭₂::AbstractArray{T,1} ) where T<:Real
πŠβ‚::AbstractArray,
𝐑₁::AbstractArray,
𝐭₁::AbstractArray,
πŠβ‚‚::AbstractArray,
𝐑₂::AbstractArray,
𝐭₂::AbstractArray)

if size(πŠβ‚) != (3,3) || size(πŠβ‚‚) != (3,3) ||
size(𝐑₁) != (3,3) || size(𝐑₂) != (3,3)
Expand All @@ -14,16 +14,15 @@ function construct( e::FundamentalMatrix,
throw(ArgumentError("Expect length-3 translation vectors."))
end
𝐅 = vec2antisym(πŠβ‚‚*𝐑₂*(𝐭₁ .- 𝐭₂))*πŠβ‚‚*𝐑₂/𝐑₁/πŠβ‚
MMatrix{3,3,Float64,3*3}(𝐅)
end

function construct( e::FundamentalMatrix,
𝐏₁::AbstractArray{T,2},
𝐏₂::AbstractArray{T,2}) where T<:Real

function construct( e::FundamentalMatrix, 𝐏₁::AbstractArray, 𝐏₂::AbstractArray)
if (size(𝐏₁) != (3,4)) || (size(𝐏₂) != (3,4))
throw(ArgumentError("Expect 3 x 4 projection matrices."))
end
πœβ‚ = nullspace(𝐏₁)
πœβ‚ = SVector{4,Float64}(nullspace(Array(𝐏₁)))
πžβ‚‚ = 𝐏₂*πœβ‚
return 𝐅 = vec2antisym(πžβ‚‚)*𝐏₂*pinv(𝐏₁)
𝐅 = vec2antisym(πžβ‚‚)*𝐏₂*pinv(Array(𝐏₁))
MMatrix{3,3,Float64,3*3}(𝐅)
end
17 changes: 11 additions & 6 deletions src/construct/construct_projectionmatrix.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function construct( e::ProjectionMatrix,
𝐊::AbstractArray{T,2},
𝐑::AbstractArray{T,2},
𝐭::AbstractArray{T,1} ) where T<:Real
𝐊::AbstractArray,
𝐑::AbstractArray,
𝐭::AbstractArray )

if size(𝐊) != (3,3) || size(𝐑) != (3,3)
throw(ArgumentError("Expect 3 x 3 calibration and rotation matrices."))
Expand All @@ -10,9 +10,14 @@ function construct( e::ProjectionMatrix,
throw(ArgumentError("Expect length-3 translation vectors."))
end
𝐏 = 𝐊*[𝐑 -𝐑*𝐭]
SMatrix{3,4,Float64,3*4}(𝐏)
end

function construct( e::ProjectionMatrix, 𝐅::AbstractArray{T,2}) where T<:Real
𝐞 = collect(epipole(𝐅').coords)
eye(3,4), [vec2antisym(𝐞) * 𝐅 𝐞]
function construct( e::ProjectionMatrix, 𝐅::AbstractArray)
𝐞 = epipole(𝐅')
𝐏₁ = eye(3,4)
𝐏₂ = [vec2antisym(𝐞) * 𝐅 𝐞]

SMatrix{3,4,Float64,3*4}(𝐏₁), SMatrix{3,4,Float64,3*4}(𝐏₂)

end
4 changes: 3 additions & 1 deletion src/cost_function/ModuleCostFunction.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module ModuleCostFunction
using MultipleViewGeometry.ModuleTypes, MultipleViewGeometry.ModuleOperators, MultipleViewGeometry.ModuleMathAliases
using MultipleViewGeometry.ModuleCarriers
export cost, X, H
using MultipleViewGeometry.ModuleTransform
using StaticArrays
export cost, X, H, covariance_matrix, covariance_matrix_debug, covariance_matrix_normalised
include("cost_functions.jl")
end
Loading

0 comments on commit c366e34

Please sign in to comment.