Skip to content

Commit 7bd32da

Browse files
committed
PixelIndex valid
1 parent 83d6e60 commit 7bd32da

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/ExportAPI.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export CameraSkewDistortion
99

1010
export Ray, PixelIndex
1111
export pixel2ray, point2pixel, canreproject, sensorsize #, origin, direction,
12+
export project, projectHomogeneous
13+
export backproject, backprojectHomogeneous
1214

1315
export lookdirection, updirection #, columns, rows
1416

src/entities/GeneralTypes.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11

22

3-
struct PixelIndex{T <: Real}
3+
struct PixelIndex{VALID, T <: Real}
44
row::T
55
col::T
66
end
7+
PixelIndex(u::T,v::T;valid::Bool=true) where {T <: Real} = PixelIndex{valid,T}(u,v)
78

89
function Base.getindex(p::PixelIndex,i::Int)
910
if i === 1

src/services/CameraServices.jl

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,25 @@ function project(
6767
row = c_h(model) - f_h(model) * pointincamera[2] / pointincamera[3]
6868
return PixelIndex(column, row)
6969
end
70+
7071
## homogeneous point coords xyzw (stereo cameras)
71-
# # xyzw are in the camera frame, i.e. x-columns, y-rows, z-forward
72-
# # left cam
73-
# fz = _f / z
74-
# u = x * fz + center[1] # add center to get PixelCoordinate
75-
# v = y * fz + center[2]
72+
# xyzw are in the camera frame (c_), i.e. x-columns, y-rows, z-forward
73+
function projectHomogeneous(
74+
cam::AbstractCameraModel,
75+
c_Ph::SVector{4,Float64}
76+
)
77+
# left cam
78+
x,y,z,w = (c_Ph...,)
79+
fxz = f_w(cam) / z
80+
fyz = f_h(cam) / z
81+
w = x * fxz + c_w(cam) # add center to get PixelIndex
82+
h = y * fyz + c_h(cam)
83+
if (w==0&&0<z) || 0 < (z/w)
84+
PixelIndex(w,h)
85+
else
86+
PixelIndex(0.,0.; valid=false)
87+
end
88+
end
7689
# # right cam
7790
# u2 = (x - w*baseline) * fz + center[1]
7891
# # infront or behind

0 commit comments

Comments
 (0)