Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
yakir12 committed Dec 18, 2024
1 parent 1dc8bd6 commit a6f3033
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 18 deletions.
35 changes: 35 additions & 0 deletions main.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Revise, CameraCalibrations
using ImageBase, ImageTransformations, Interpolations, ImageView, FileIO, StaticArrays, ImageDraw

function get_img(n_corners)
ratio = 50
corners = SVector{2, Float64}.(reverse.(Tuple.(CartesianIndices(n_corners)))) .+ Ref(SVector(0.5, 0.5))
corners .*= ratio

img = Matrix{Gray{N0f8}}(undef, n_corners)
for ij in eachindex(IndexCartesian(), img)
i, j = Tuple(ij)
img[ij] = if isodd(i)
isodd(j) ? Gray(1) : Gray(0)
else
isodd(j) ? Gray(0) : Gray(1)
end
end
w, h = n_corners .+ 2
img2 = imresize(PaddedView(Gray(1), img, (w, h), (2, 2)); ratio, method = Constant())
return corners, img2
end
n_corners = (6, 9)
corners, img = get_img(n_corners .+ 1)
sz = size(img)
file = "img.png"

FileIO.save(file, img)

_, xys = CameraCalibrations._detect_corners(file, n_corners, sz)

imgc = RGB.(img)
for xy in xys
draw!(imgc, Cross(Point(200,150), 50),


5 changes: 0 additions & 5 deletions src/detect_fit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,12 @@ end
Wraps OpenCV function to fit a camera model to given object and image points.
"""
function fit_model(sz, objpoints, imgpointss, n_corners, with_distortion, aspect)


# imgpointss = [pop.(objpoints) for _ in imgpointss]

nfiles = length(imgpointss)

objectPoints = OpenCV.InputArray[Float32.(reshape(stack(objpoints), 3, 1, :)) for _ in 1:nfiles]
imagePoints = OpenCV.InputArray[Float32.(reshape(stack(imgpoints), 2, 1, :)) for imgpoints in imgpointss]
imageSize = OpenCV.Size{Int32}(sz...)


cammat = collect(I(3))
cammat[1,:] .= aspect
cameraMatrix = OpenCV.Mat(Float32.(reshape(cammat, 1, 3, 3)))
Expand Down
8 changes: 0 additions & 8 deletions src/io.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
const AM = AffineMap{SDiagonal{2, Float64}, SVector{2, Float64}}
const AMext = AffineMap{RotationVec{Float64}, SVector{3, Float64}}
const LM3 = LinearMap{SDiagonal{3, Float64}}

# StructTypes.StructType(::Type{<:SVector}) = StructTypes.CustomStruct()
# StructTypes.lower(x::SVector) = x.data
# StructTypes.lowertype(::Type{SVector{N, T}}) where {N, T} = NTuple{N, T}

# StructTypes.StructType(::Type{<:Diagonal}) = StructTypes.CustomStruct()
# StructTypes.lower(x::Diagonal) = x.diag
# StructTypes.lowertype(::Type{Diagonal{T, V}}) where {T, V} = V

StructTypes.StructType(::Type{<:Diagonal}) = StructTypes.CustomStruct()
StructTypes.lower(x::Diagonal) = x.diag
StructTypes.lowertype(::Type{Diagonal{T, V}}) where {T, V} = V
Expand Down
6 changes: 1 addition & 5 deletions src/meta.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const AM = AffineMap{Diagonal{Float64, SVector{2, Float64}}, SVector{2, Float64}}

const AM = AffineMap{SDiagonal{2, Float64}, SVector{2, Float64}}
const AMext = AffineMap{RotationVec{Float64}, SVector{3, Float64}}

const LM3 = LinearMap{SDiagonal{3, Float64}}

"""
Expand All @@ -26,8 +24,6 @@ struct Calibration
image2real::Vector{ComposedFunction}
end



function Calibration(intrinsic, extrinsics, scale, k, files)
distort(rc) = lens_distortion(rc, k)
real2image = .∘(Ref(intrinsic), distort, Ref(PerspectiveMap()), extrinsics, Ref(scale))
Expand Down

0 comments on commit a6f3033

Please sign in to comment.