Open yan99033 opened 4 years ago
Hi again,
After looking into the shape from shading example, I think I have completed the re-projection part. The only problem I have is the sampling of the image pixels in order to compute the photometric errors.
Similar to #151 , the image indexing won't work using
I_hat(u_hat, v_hat)
,
where u_hat
and v_hat
are the reprojected pixel locations. The error message is as follows:
bad argument #1 to 'Offset' expected 'number*' but found 'table' at list index 1 (metatable = Class(Apply))
Update: The code works without a problem. The warping should work because I tested using with its equivalent Python code. However, the energy won't go down. It says "Function tolerance reached, exiting".
Again, I don't need babysitting. You can just simply point me to the root of the problem, and I don't mind looking into the source code and modifying the source code. My only problem is the pixel sampling.
Thanks!
local I_target_hat = SampledImage(I_source, I_source_du, I_source_dv)
--- Image warping
-- Depth and image coordinates
local d = D(0, 0) -- This is the depth map to be optimized
local i = posX
local j = posY
-- Pointcloud
local X = ((i - cx) / fx) * d
local Y = ((j - cy) / fy) * d
local Z = d
-- Transformation
local X_hat = r11 * X + r12 * Y + r13 * Z + t1
local Y_hat = r21 * X + r22 * Y + r23 * Z + t2
local Z_hat = r31 * X + r32 * Y + r33 * Z + t3
-- Re-project
u_hat = ((fx * X) / Z_hat) + cx
v_hat = ((fy * Y) / Z_hat) + cy
-- Mask out out-of-bound re-projections (image size: 640, 480)
valid_u = and_(greatereq(u_hat, 0.0), less(u_hat, 640.0))
valid_v = and_(greatereq(v_hat, 0.0), less(v_hat, 480.0))
valid = and_(valid_u, valid_u)
--- Energy
Energy( Select( valid, I_target(0, 0) - I_target_hat(u_hat, v_hat), 0.0 ) )
Hi,
I am having difficulty with defining my Energy.
Here is the problem: I would like to perform image warping via known depth map and camera pose. The algorithm should look like this:
To convert the algorithm to the Terra/Lua code, I need the matrix multiplication and matrix slicing techniques, assuming I can create mesh grid and matrix broadcasting in my C++ code. I would also need bilinear interpolation to get the pixel intensities at sub-pixel locations (I presume that the optical flow example is already doing that, how can I use the code without the autodiff stuff?). I am a total beginner in Lua/Terra language, I hope that you can point me to the right resources.
Alternatively, can I just create an API to perform inverse_warp using Pytorch and spit out the inverse warped image for energy computation? If it is possible, how should I create the pipeline so that the datatypes match in both ends (i.e., the .t file and the .py file)?