Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
name = "CameraModels"
uuid = "0d57b887-6120-40e6-8b8c-29d3116bc0c1"
keywords = ["camera", "model", "pinhole", "distortion", "robotics", "images"]
keywords = ["camera", "model", "pinhole", "distortion", "robotics", "images", "vision"]
version = "0.2.4"

[deps]
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
Manifolds = "1cead3c2-87b3-11e9-0ccd-23c62b72b94e"
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
Rotations = "6038ab10-8711-5258-84ad-4b1120ba62dc"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
DocStringExtensions = "0.8, 0.9"
LoopVectorization = "0.12.173"
Manifolds = "0.10, 0.11"
RecursiveArrayTools = "3.27.0"
Rotations = "1"
Expand Down
3 changes: 1 addition & 2 deletions src/CameraModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ using StaticArrays
import Rotations as Rot_
import Base: getindex, getproperty, show
using RecursiveArrayTools: ArrayPartition
using LoopVectorization: @tturbo

# exports
include("ExportAPI.jl")
Expand All @@ -26,6 +27,4 @@ include("services/CameraServices.jl")
include("services/Utils.jl")




end # module
165 changes: 79 additions & 86 deletions src/Deprecated.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

## ================================================================================================
## consolidated types from various repos in Julia ecosystem
## ================================================================================================

@deprecate project(cm::CameraModelFull, pt::AbstractVector{<:Real}) project(cm.ci,pt) # drops extrinsics
@deprecate project(cm::CameraModelFull, pt::AbstractVector{<:Real}) project(cm.ci, pt) # drops extrinsics

# function project(
# cm::CameraModelFull,
# cm::CameraModelFull,
# pt::AbstractVector{<:Real}
# )
# res = Vector{Float64}(2)
Expand All @@ -21,7 +20,7 @@ A Union type for users to implement against both `struct`` and `mutable struct`
"""
CameraCalibrationT = Union{<:CameraCalibration, <:CameraCalibrationMutable}

@deprecate CameraExtrinsic(R::AbstractMatrix=[1 0 0; 0 1 0; 0 0 1.], t::AbstractVector=[0,0,0.]) ArrayPartition(SVector(t...),SMatrix(R))
@deprecate CameraExtrinsic(R::AbstractMatrix = [1 0 0; 0 1 0; 0 0 1.0], t::AbstractVector = [0, 0, 0.0]) ArrayPartition(SVector(t...), SMatrix(R))

# Camera extrinsic must be world in camera frame (cRw)
# Base.@kwdef struct CameraExtrinsic{T <: Real}
Expand All @@ -30,7 +29,7 @@ CameraCalibrationT = Union{<:CameraCalibration, <:CameraCalibrationMutable}
# end


@deprecate PixelCoordinate(row,col) PixelIndex(row,col)
@deprecate PixelCoordinate(row, col) PixelIndex(row, col)

# CameraCalibration(
# height::Int= 480,
Expand All @@ -52,7 +51,6 @@ CameraCalibrationT = Union{<:CameraCalibration, <:CameraCalibrationMutable}
# ) = CameraCalibrationMutable(height, width, kc, MMatrix{3,3}(K), MMatrix{3,3}(inv(K)) )



@deprecate point2pixel(model, pt) project(model, pt[[1;3;2]])
@deprecate pixel2ray(model, px) backproject(model, px)[[1;3;2]]

Expand All @@ -61,7 +59,7 @@ CameraCalibrationT = Union{<:CameraCalibration, <:CameraCalibrationMutable}
# point2pixel(model::Pinhole, pointincamera::$(Point3))

# Return a transformation that converts real-world coordinates
# to camera coordinates. This currently ignores any tangential
# to camera coordinates. This currently ignores any tangential
# distortion between the lens and the image plane.
# """
# function point2pixel(model::CameraCalibrationT, pointincamera::Point3)
Expand All @@ -75,7 +73,7 @@ CameraCalibrationT = Union{<:CameraCalibration, <:CameraCalibrationMutable}
# pixel2ray(model::Pinhole, pixelcoordinate::$(PixelCoordinate))

# Return a transformation that converts real-world coordinates
# to camera coordinates. This currently ignores any tangential
# to camera coordinates. This currently ignores any tangential
# distortion between the lens and the image plane.
# """
# function pixel2ray(model::CameraCalibrationT, pixelcoordinate::PixelCoordinate)
Expand All @@ -86,19 +84,19 @@ CameraCalibrationT = Union{<:CameraCalibration, <:CameraCalibrationMutable}


export CameraModel # being replaced by AbstractCameraModel
CameraModel = (@warn("CameraModels.CameraModel is deprecated, use CameraModels.AbstractCameraModel instead");AbstractCameraModel)
# abstract type CameraModel end
CameraModel = (@warn("CameraModels.CameraModel is deprecated, use CameraModels.AbstractCameraModel instead"); AbstractCameraModel)
# abstract type CameraModel end

@warn "RadialDistortion is deprecated, use CameraCalibration instead"
# Base.@kwdef struct RadialDistortion{N, R <: Real, K <: AbstractVector}
# Ki::SVector{N,R} = SVector(0.0) #
# Ki::SVector{N,R} = SVector(0.0) #
# center::SVector{2,R} = SVector{2,R}(0.0,0.0) # SVector{2,R} # [h,w]
# # _radius2::Matrix{R} # perhaps SizedArray{R,2} or StaticArray{R,2} or GPUArray{R,2} depending on performance
# end


@deprecate columns(w...;kw...) width(w...;kw...)
@deprecate rows(w...;kw...) height(w...;kw...)
@deprecate columns(w...; kw...) width(w...; kw...)
@deprecate rows(w...; kw...) height(w...; kw...)

# sensorsize(cameramodel::CameraModel) = SVector{2}(width(cameramodel), height(cameramodel))

Expand All @@ -107,22 +105,21 @@ export CameraModelandParameters
# const CameraModelandParameters = (@warn("CameraModels.CameraModelandParameters is deprecated, use CameraModels.CameraCalibration instead.");CameraCalibration)

function CameraModelandParameters(
width::Int,
height::Int,
fc::AbstractVector{<:Real},
cc::AbstractVector{<:Real},
skew::Real,
kc::AbstractVector{<:Real},
K::AbstractMatrix{<:Real} = [[fc[1];skew;cc[1]]';[0.0;fc[2];cc[2]]';[0.0;0;1]'], # legacy constructor
Ki::AbstractMatrix{<:Real} = inv(K)
)
#
@warn("CameraModels.CameraModelandParameters is deprecated, use CameraModels.CameraCalibration instead.")
CameraCalibration(;width,height,K=SMatrix{3,3}(K))
width::Int,
height::Int,
fc::AbstractVector{<:Real},
cc::AbstractVector{<:Real},
skew::Real,
kc::AbstractVector{<:Real},
K::AbstractMatrix{<:Real} = [[fc[1];skew;cc[1]]';[0.0;fc[2];cc[2]]';[0.0;0;1]'], # legacy constructor
Ki::AbstractMatrix{<:Real} = inv(K)
)
#
@warn("CameraModels.CameraModelandParameters is deprecated, use CameraModels.CameraCalibration instead.")
return CameraCalibration(; width, height, K = SMatrix{3, 3}(K))
end



# """
# Data structure for a Camera model with parameters.
# Use `CameraModel(width,height,fc,cc,skew,kc)` for easy construction.
Expand All @@ -139,7 +136,6 @@ end
# end



export PinholeCamera

# ## From JuliaRobotics/Caesar.jl
Expand All @@ -152,7 +148,7 @@ export PinholeCamera
# - https://en.wikipedia.org/wiki/Pinhole_camera
# - Standard Julia *[Images.jl](https://juliaimages.org/latest/)-frame* convention is, `size(img) <==> (i,j) <==> (height,width) <==> (y,x)`,
# - Common *camera-frame* in computer vision and robotics, `(x,y) <==> (width,height) <==> (j,i)`,
# - Using top left corner of image as `(0,0)` in all cases.
# - Using top left corner of image as `(0,0)` in all cases.
# - Direct comparison with [OpenCV convention](https://docs.opencv.org/3.4/d9/d0c/group__calib3d.html) is:
# - `(x,y) [CamXYZ] <==> (j,i) [Images.jl] <==> (u,v) [OpenCV]` -- look very carfully at `(u,v) <==> (j,i)` in *image-frame*
# - Always follow right hand rule for everything.
Expand All @@ -168,23 +164,23 @@ export PinholeCamera
# const PinholeCamera = (@warn("CameraModels.PinholeCamera is deprecated, use CameraModels.CameraCalibrationMutable instead."); CameraCalibration)

function PinholeCamera(
K_::AbstractMatrix=[[510;0;320.0]';[0.0;510;240]';[0.0;0;1]']; # legacy constructor
width::Int=round(Int, K_[1,3]*2),
height::Int=round(Int, K_[2,3]*2),
f_w::Real=K_[1,1],
f_h::Real=K_[2,2],
c_w::Real=K_[1,3],
c_h::Real=K_[2,3],
shear::Real=K_[1,2],
K::AbstractMatrix=[[f_w;shear;c_w]';[0.0;f_h;c_h]';[0.0;0;1]'], # consolidated matrix K
)
#
@warn "CameraModels.PinholeCamera is deprecated, use CameraModels.CameraCalibrationMutable instead."
if 3 < size(K_,1)
@warn "PinholeCamera(arg), 3 < size(arg,1), assuming legacy constructor as img as input argument."
return CameraCalibrationMutable(K_) # as though img=K_
end
CameraCalibrationMutable(;width,height,K=MMatrix{3,3}(K))
K_::AbstractMatrix = [[510;0;320.0]';[0.0;510;240]';[0.0;0;1]']; # legacy constructor
width::Int = round(Int, K_[1, 3] * 2),
height::Int = round(Int, K_[2, 3] * 2),
f_w::Real = K_[1, 1],
f_h::Real = K_[2, 2],
c_w::Real = K_[1, 3],
c_h::Real = K_[2, 3],
shear::Real = K_[1, 2],
K::AbstractMatrix = [[f_w;shear;c_w]';[0.0;f_h;c_h]';[0.0;0;1]'], # consolidated matrix K
)
#
@warn "CameraModels.PinholeCamera is deprecated, use CameraModels.CameraCalibrationMutable instead."
if 3 < size(K_, 1)
@warn "PinholeCamera(arg), 3 < size(arg,1), assuming legacy constructor as img as input argument."
return CameraCalibrationMutable(K_) # as though img=K_
end
return CameraCalibrationMutable(; width, height, K = MMatrix{3, 3}(K))
end

# @deprecate PinholeCamera(img::AbstractMatrix) CameraCalibrationMutable(img)
Expand Down Expand Up @@ -216,28 +212,28 @@ export Pinhole

## From yakir12/CameraModels.jl
# const Pinhole = (@warn("CameraModels.Pinhole is deprecated, use CameraModels.CameraCalibration instead."); CameraCalibration)
function Pinhole(columns::Int,rows::Int,prinicipalpoint,focallength::Vector2 )
@warn "CameraModels.Pinhole is deprecated, use CameraModels.CameraCalibration instead."
f_w,f_h = focallength[1], focallength[2]
c_w,c_h = prinicipalpoint[1], prinicipalpoint[2]
K = SMatrix{3,3}([[f_w;0.0;c_w]';[0.0;f_h;c_h]';[0.0;0;1.]'] )
CameraCalibration(;
height=rows,
width=columns,
K
)
function Pinhole(columns::Int, rows::Int, prinicipalpoint, focallength::Vector2)
@warn "CameraModels.Pinhole is deprecated, use CameraModels.CameraCalibration instead."
f_w, f_h = focallength[1], focallength[2]
c_w, c_h = prinicipalpoint[1], prinicipalpoint[2]
K = SMatrix{3, 3}([[f_w;0.0;c_w]';[0.0;f_h;c_h]';[0.0;0;1.0]'])
return CameraCalibration(;
height = rows,
width = columns,
K
)
end

function CameraIntrinsic(
K_::AbstractMatrix=[[510;0;320.0]';[0.0;510;240]';[0.0;0;1]']; # legacy constructor
x0=320.0,y0=240.0,fx=510.0,fy=510.0,s=0.0, # legacy function support
K::AbstractMatrix=[[fx;s;x0]';[0.0;fy;y0]';[0.0;0;1]'], # consolidated matrix K
width::Int=round(Int, K[1,3]*2),
height::Int=round(Int, K[2,3]*2),
)
#
@warn "CameraModels.CameraIntrinsic is deprecated, use CameraModels.CameraCalibration instead."
CameraCalibration(;width,height,K)
K_::AbstractMatrix = [[510;0;320.0]';[0.0;510;240]';[0.0;0;1]']; # legacy constructor
x0 = 320.0, y0 = 240.0, fx = 510.0, fy = 510.0, s = 0.0, # legacy function support
K::AbstractMatrix = [[fx;s;x0]';[0.0;fy;y0]';[0.0;0;1]'], # consolidated matrix K
width::Int = round(Int, K[1, 3] * 2),
height::Int = round(Int, K[2, 3] * 2),
)
#
@warn "CameraModels.CameraIntrinsic is deprecated, use CameraModels.CameraCalibration instead."
return CameraCalibration(; width, height, K)
end
export CameraIntrinsic

Expand All @@ -251,23 +247,23 @@ export CameraIntrinsic


function Base.getproperty(
x::CameraCalibration, # Union{<:Pinhole, CameraModelandParameters},
f::Symbol,
)
if f == :skew
getfield(x, :K)[1,2]
elseif f == :columns
getfield(x, :width)
elseif f == :rows
getfield(x, :height)
elseif f == :prinicipalpoint || f == :cc
SA[(getfield(x, :K)[1:2, 3])...]
elseif f == :focallength || f == :fc
K = getfield(x, :K)
SA[K[1,1];K[2,2]]
else
getfield(x, f)
end
x::CameraCalibration, # Union{<:Pinhole, CameraModelandParameters},
f::Symbol,
)
return if f == :skew
getfield(x, :K)[1, 2]
elseif f == :columns
getfield(x, :width)
elseif f == :rows
getfield(x, :height)
elseif f == :prinicipalpoint || f == :cc
SA[(getfield(x, :K)[1:2, 3])...]
elseif f == :focallength || f == :fc
K = getfield(x, :K)
SA[K[1, 1];K[2, 2]]
else
getfield(x, f)
end
end
# function Base.getproperty(x::CameraModelandParameters, f::Symbol)
# if f == :skew
Expand All @@ -280,7 +276,7 @@ end
# SA[(getfield(x, :K)[1:2, 3])...]
# elseif f == :focallength || f == :fc
# K = getfield(x, :K)
# SA[K[1,1];K[2,2]]
# SA[K[1,1];K[2,2]]
# else
# getfield(x, f)
# end
Expand All @@ -296,7 +292,4 @@ end
# end





#
#
7 changes: 2 additions & 5 deletions src/ExportAPI.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@



export AbstractCameraModel

export CameraCalibration, CameraCalibrationMutable
Expand All @@ -10,7 +7,7 @@ export CameraSkewDistortion

export undistortPoint
export Ray, PixelIndex
export pixel2ray, point2pixel, canreproject, sensorsize #, origin, direction,
export pixel2ray, point2pixel, canreproject, sensorsize #, origin, direction,
export project, projectHomogeneous
export backproject, backprojectHomogeneous
export pp_w, pp_h, f_w, f_h
Expand All @@ -21,4 +18,4 @@ export intersectLineToPlane3D, intersectRayToPlane

# suppressing super general signatures likely to have conflicts.
# TODO adopt common Julia definition for points and vectors, maybe something from JuliaGeometry, etc.
# export Vector3, Vector2, Point3
# export Vector3, Vector2, Point3
Loading
Loading