Skip to content

Commit

Permalink
Bump required Julia to >=1.9
Browse files Browse the repository at this point in the history
By requiring a higher Julia version, the package extension mechanism
will be available and can be used always (no need for Requires.jl
anymore). This makes the implementation easier.
The `get_plot_backend()` function is still contained to avoid method
overwrite warnings. Usually, a package extension does type piracy and
dispatches on a new type. We only have the demo functions, which cannot
dispatch on the type.
This now can be extended to different plotting backends (Makie for
example), which in turn could be selected in the `get_plot_backend()`
function.
  • Loading branch information
PaulDebus committed Dec 27, 2023
1 parent 76808d7 commit 5084e4c
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.4' # Min Julia version supported
- '1.9' # Min Julia version supported
- '1' # Expands to latest version
os:
- ubuntu-latest
Expand Down
19 changes: 8 additions & 11 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ImageProjectiveGeometry"
uuid = "b9d14576-938f-5430-9d4c-b7d7de1409d6"
author = ["Peter Kovesi <peter.kovesi@gmail.com>"]
version = "0.3.6"
version = "0.4.0"

[deps]
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
Expand All @@ -16,20 +16,17 @@ Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[weakdeps]
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"

[extensions]
ImageProjectiveGeometryPyPlotExt = "PyPlot"

[compat]
DSP = "0.5 - 0.7"
FileIO = "1"
ImageFiltering = "0.4 - 0.7"
Images = "0.20 - 0.25"
Interpolations = "0.10 - 0.14"
PyPlot = "2.5 - 2.11"
julia = "1.4"

[extensions]
ImageProjectiveGeometryPyPlotExt = "PyPlot"

[extras]
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"

[weakdeps]
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
julia = "1.9"
4 changes: 2 additions & 2 deletions ext/ImageProjectiveGeometryPyPlotExt.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module ImageProjectiveGeometryPyPlotExt
using LinearAlgebra
using Random
using PyPlot

isdefined(Base, :get_extension) ? (using ImageProjectiveGeometry) : (using ..ImageProjectiveGeometry)
using ImageProjectiveGeometry

include("ransacdemo.jl")

Expand Down
6 changes: 0 additions & 6 deletions ext/ransacdemo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ PK March 2016
---------------------------------------------------------------------=#

# export fitlinedemo, fitplanedemo
# export fitfunddemo, fithomogdemo

# using ImageProjectiveGeometry, PyPlot, Printf, FileIO

#-----------------------------------------------------------------------
"""
fitlinedemo - Demonstrates RANSAC line fitting.
Expand Down
10 changes: 0 additions & 10 deletions src/ImageProjectiveGeometry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,4 @@ include("utilities.jl")
include("geometry.jl")
include("plotting.jl")

# This symbol is only defined on Julia versions that support extensions
if !isdefined(Base, :get_extension)
using Requires
end
function __init__()
@static if !isdefined(Base, :get_extension)
Requires.@require PyPlot="d330b81b-6aea-500a-939a-2ce795aea3ee" include("../ext/ImageProjectiveGeometryPyPlotExt.jl")
end
end

end # module
99 changes: 93 additions & 6 deletions src/plotting.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@

export fitlinedemo, fitplanedemo
export fitfunddemo, fithomogdemo
export hline, plotcamera
export plot_briefcoords, plot_nonmaxsuppts


# This function is used to not have the extensions have to overwrite the dfferent
# plotting fucntions, which would raise a precompilation warning.
# This also allows implementing a smarter way to select the correct plutting
# backend in case multiple backends are loaded (I would however doubt this
# would ever happen).
# If another extension module is implemented (Makie for example), implement
# checking for it here.
function get_plot_backend()
if !isdefined(Base, :get_extension)
error("PyPlot extension not loaded...")
end

ext = Base.get_extension(@__MODULE__, :ImageProjectiveGeometryPyPlotExt)
# TODO: add different plotting backends
if ext === nothing
error("PyPlot extension not loaded...")
else
Expand Down Expand Up @@ -86,22 +93,102 @@ function plotcamera(Ci, l; col=[0,0,1], plotCamPath=false, fig=nothing)
return ext.plotcamera(Ci, l, col, plotCamPath, fig)
end

"""
fitlinedemo - Demonstrates RANSAC line fitting.
Function generates a noisy set of data points with outliers and uses
RANSAC to fit a line.
```
Usage: fitlinedemo(outliers, sigma, t, feedback=false)
Arguments:
outliers - Fraction specifying how many points are to be
outliers.
sigma - Standard deviation of inlying points from the
true line.
t - Distance threshold to be used by the RANSAC
algorithm for deciding whether a point is an
inlier.
feedback - Optional Boolean flag turn on RANSAC feedback
information.
Try using: fitlinedemo(0.3, 0.05, 0.05)
```
See also: ransacfitplane(), fitplane()
"""
function fitlinedemo(outliers, sigma, t::Real, feedback::Bool = false)
ext = get_plot_backend()
return ext.fitlinedemo(outliers, sigma, t, feedback)
end

"""
fitplanedemo - Demonstrates RANSAC plane fitting
Function generates a noisy set of data points with outliers and uses
RANSAC to fit a plane.
```
Usage: fitplanedemo(outliers, sigma, t, feedback)
Arguments:
outliers - Fraction specifying how many points are to be
outliers.
sigma - Standard deviation of inlying points from the
true plane.
t - Distance threshold to be used by the RANSAC
algorithm for deciding whether a point is an
inlier.
feedback - Optional flag 0 or 1 to turn on RANSAC feedback
information.
Try using: fitplanedemo(0.3, 0.02, 0.05)
```
See also: ransacfitplane(), fitplane()
"""
function fitplanedemo(outliers, sigma, t, feedback::Bool = false)
ext = get_plot_backend()
return ext.fitplanedemo(outliers, sigma, t, feedback)
end

"""
fitfunddemo - Example of fundamental matrix computation
Demonstration of feature matching via simple correlation, and then using
RANSAC to estimate the fundamental matrix and at the same time identify
(mostly) inlying matches
```
Usage: fitfunddemo - Demonstrates fundamental matrix calculation
on two default images.
funddemo(img1,img2) - Computes fundamental matrix on two supplied
images.
```
Edit code as necessary to tweak parameters
See also: ransacfitfundmatrix(), fundmatrix()
"""
function fitfunddemo(img1=[], img2=[])
ext = get_plot_backend()
return ext.fitfunddemo(img1, img2)
end

"""
fithomogdemo - Example of finding a homography
Demonstration of feature matching via simple correlation, and then using
RANSAC to estimate the homography between two images and at the same time
identify (mostly) inlying matches
```
Usage: fithomogdemo - Demonstrates homography calculation on two
default images
fithomogdemo(img1,img2) - Computes homography on two supplied images
Edit code as necessary to tweak parameters
```
See also: ransacfithomography(), homography2d()
"""
function fithomogdemo(img1=[], img2=[])
ext = get_plot_backend()
return ext.fithomogdemo(img1, img2)
end

0 comments on commit 5084e4c

Please sign in to comment.