Thanks for the suggestion!
However, here is a more complete MWE that illustrates a problem with your suggestion.
The following works:
using PythonCall
using CondaPkg
CondaPkg.add.(["numpy", "opencv"])
np = pyimport("numpy")
cv2 = pyimport("cv2")
nc = (5, 8) # number of corners in the calibration checkerboard
n = 9 # number of images of the checkerboard
sz = (10, 10) # image dimensions
objp = np.zeros((1, *(nc...), 3), np.float32)
# the following just populates the object points with real-world coordinates
for (i, v) in enumerate(repeat(1:nc[1], outer = nc[2]))
objp[0][i - 1][0] = v - 1
end
for (i, v) in enumerate(repeat(1:nc[2], inner = nc[1]))
objp[0][i - 1][1] = v - 1
end
objectPoints = fill(objp, n)
imgp = np.zeros((*(nc...), 1, 2), np.float32)
# the following just populates the image points with random pixel coordinates
for i in 1:*(nc...)
imgp[i - 1] = rand()
end
imagePoints = fill(imgp, n)
# the following call works
cv2.calibrateCamera(objectPoints, imagePoints, sz, nothing, nothing)
But if I replace objp
with your suggestion:
objp = zeros(Float32, (1, *(nc...), 3))
# and fill it with the same real-world coordinates
objp[1, :, 1] .= repeat(0:nc[1] - 1, outer = nc[2])
objp[1, :, 2] .= repeat(0:nc[2] - 1, inner = nc[1])
the call to cv2.calibrateCamera
fails with:
julia> cv2.calibrateCamera(objectPoints, imagePoints, sz, nothing, nothing)
ERROR: Python: error: OpenCV(4.7.0) :-1: error: (-5:Bad argument) in function 'calibrateCamera'
> Overload resolution failed:
> - Can't parse 'objectPoints'. Sequence item with index 0 has a wrong type
> - Can't parse 'objectPoints'. Sequence item with index 0 has a wrong type
Python stacktrace: none
Stacktrace:
[1] pythrow()
@ PythonCall ~/.julia/packages/PythonCall/3GRYN/src/err.jl:94
[2] errcheck
@ ~/.julia/packages/PythonCall/3GRYN/src/err.jl:10 [inlined]
[3] pycallargs(f::Py, args::Py)
@ PythonCall ~/.julia/packages/PythonCall/3GRYN/src/abstract/object.jl:210
[4] pycall(::Py, ::Vector{Array{Float32, 3}}, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ PythonCall ~/.julia/packages/PythonCall/3GRYN/src/abstract/object.jl:228
[5] pycall(::Py, ::Vector{Array{Float32, 3}}, ::Vararg{Any})
@ PythonCall ~/.julia/packages/PythonCall/3GRYN/src/abstract/object.jl:218
[6] (::Py)(::Vector{Array{Float32, 3}}, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ PythonCall ~/.julia/packages/PythonCall/3GRYN/src/Py.jl:352
[7] (::Py)(::Vector{Array{Float32, 3}}, ::Vararg{Any})
@ PythonCall ~/.julia/packages/PythonCall/3GRYN/src/Py.jl:352
[8] top-level scope
@ REPL[103]:1
To me, Can't parse 'objectPoints'. Sequence item with index 0 has a wrong type
seems to suggest that the type of the elements in objectPoints
is wrong.