-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from zygmuntszpak/demo_fundamental
Adds demonstration of fundamental matrix estimation
- Loading branch information
Showing
6 changed files
with
129 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using MultipleViewGeometry, Images | ||
using BenchmarkTools, Compat | ||
using StaticArrays, MAT, Plots | ||
|
||
# Load MATLAB matrices that represent a pair of images and that contain | ||
# a set of manually matched corresponding points. | ||
file = matopen("./data/sene-adelaideRMF.mat") | ||
img1 = colorview(RGB, normedview(permutedims(read(file,"img1"),[3,1,2]))) | ||
img2 = colorview(RGB, normedview(permutedims(read(file,"img2"),[3,1,2]))) | ||
inlier_pts1 = read(file,"inlierPts1") | ||
inlier_pts2 = read(file,"inlierPts2") | ||
close(file) | ||
|
||
# Conver the images to Grayscale. | ||
img1g = Gray.(img1) | ||
img2g = Gray.(img2) | ||
|
||
plotlyjs() | ||
|
||
_, npts1 = size(inlier_pts1) | ||
_, npts2 = size(inlier_pts2) | ||
|
||
# Construct a set of corresponding points expressed in homogeneous coordinates. | ||
β³ = [ Point2DH(vcat(inlier_pts1[:,n],1)) for n in 1:npts1] | ||
β³ΚΉ = [ Point2DH(vcat(inlier_pts2[:,n],1)) for n in 1:npts2] | ||
|
||
# Estimate the Fundamental matrix from the corresponding points using the | ||
# Direct Linear Transform algorithm. | ||
π β = estimate(FundamentalMatrix(),DirectLinearTransform(), (β³, β³ΚΉ)) | ||
|
||
# Plot Keypoints, epipole and concomitant epipolar lines in the first view. | ||
p1 = Plots.plot(img1g,grid = false, box = :none, legend = false, size = (455,341)) | ||
for n = 1:25:npts1 | ||
m = β³[n] | ||
# Epipolar line in the first image. | ||
l = π(π β'*β³ΚΉ[n]) | ||
draw!(EpipolarLineGraphic(), l, size(img1), p1) | ||
# Keypoint. | ||
Plots.plot!([m[1]],[m[2]], grid = false, box = :none, legend = false, | ||
seriestype = :scatter, w = 5, aspect_ratio = :equal) | ||
end | ||
e = epipole(π β) | ||
Plots.plot!([e[1]],[e[2]], grid = false, box = :none, legend = false, | ||
seriestype = :scatter, markershape = :diamond, markerstrokecolor = :red, | ||
markersize = 5, aspect_ratio = :equal) | ||
|
||
# Plot Keypoints and concomitant epipolar lines in the second view. | ||
p2 = Plots.plot(img2g,grid = false, box = :none, legend = false) | ||
for n = 1:25:npts2 | ||
mΚΉ = β³ΚΉ[n] | ||
# Epipolar line in the second image. | ||
l = π(π β*β³[n]) | ||
draw!(EpipolarLineGraphic(), l, size(img2), p2) | ||
Plots.plot!([mΚΉ[1]],[mΚΉ[2]], grid = false, box = :none, legend = false, | ||
seriestype = :scatter, w = 5, aspect_ratio = :equal) | ||
end | ||
eΚΉ = epipole(π β') | ||
Plots.plot!([eΚΉ[1]],[eΚΉ[2]], grid = false, box = :none, legend = false, | ||
seriestype = :scatter, markershape = :diamond, markerstrokecolor = :red, | ||
markersize = 5, aspect_ratio = :equal) | ||
|
||
|
||
# Display both views simultaneously. | ||
p3 = Plots.plot(p1,p2,layout=(1,2), legend = false) | ||
display(p3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module ModuleDraw | ||
using MultipleViewGeometry.ModuleTypes, MultipleViewGeometry.ModuleOperators, MultipleViewGeometry.ModuleMathAliases | ||
using StaticArrays | ||
using Plots, Plotly | ||
using Juno | ||
|
||
export draw!, EpipolarLineGraphic | ||
include("draw.jl") | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
abstract type GraphicEntity end | ||
|
||
type EpipolarLineGraphic <: GraphicEntity | ||
end | ||
|
||
|
||
function draw!(g::EpipolarLineGraphic, l::AbstractVector, dim::Tuple{<:Number,<:Number}, p::RecipesBase.AbstractPlot{<:RecipesBase.AbstractBackend}) | ||
|
||
top = intersection(l, [0 ; -1 ; 0]) | ||
bottom = intersection(l, [0 ; -1 ; dim[1]]) | ||
left = intersection(l, [-1 ; 0 ; 0]) | ||
right = intersection(l, [-1 ; 0 ; dim[2]]) | ||
|
||
x = Float64[] | ||
y = Float64[] | ||
|
||
if is_inbounds(top,dim) | ||
push!(x, top[1]) | ||
push!(y, top[2]) | ||
end | ||
|
||
if is_inbounds(bottom,dim) | ||
push!(x, bottom[1]) | ||
push!(y, bottom[2]) | ||
end | ||
|
||
if is_inbounds(left,dim) | ||
push!(x, left[1]) | ||
push!(y, left[2]) | ||
end | ||
|
||
if is_inbounds(right,dim) | ||
push!(x, right[1]) | ||
push!(y, right[2]) | ||
end | ||
|
||
Plots.plot!(x,y,w=3) | ||
end | ||
|
||
function intersection(l1::AbstractArray, l2::AbstractArray) | ||
l = π(cross(l1,l2)) | ||
l[1:2] | ||
end | ||
|
||
function is_inbounds(pt::AbstractVector, dim::Tuple{<:Number,<:Number}) | ||
nrow, ncol = dim | ||
pt[1] >= -1.5 && pt[1] < ncol+1.5 && pt[2] >= -1.5 && pt[2] <= nrow + 1.5 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
function epipole(π ::AbstractArray) | ||
π, π, π = svd(π ) | ||
π = π(MVector(π[:,end])) | ||
π = π(MVector{3}(π[:,end])) | ||
Point2DH(π) | ||
end |