As the title says I want to calculate the surface normals of a given depth image by using the cross product of neighboring pixels. However, I do not really understand the procedure. Does anyone have any experience?
Lets say that we have the following image:

what are the steps to follow?
---------------------------
**Update:**
I am trying to translate the following pseudocode from [this answer](http://stackoverflow.com/a/34644939/1476932) to opencv.
dzdx=(z(x+1,y)-z(x-1,y))/2.0;
dzdy=(z(x,y+1)-z(x,y-1))/2.0;
direction=(-dxdz,-dydz,1.0)
magnitude=sqrt(direction.x**2 + direction.y**2 + direction.z**2)
normal=direction/magnitude
where z(x,y) is my depth image. However, the output of the following does not seem correct to me:
for(int x = 0; x < depth.rows; ++x)
{
for(int y = 0; y < depth.cols; ++y)
{
double dzdx = (depth.at(y+1, x) - depth.at(y-1, x)) / 2.0;
double dzdy = (depth.at(y, x+1) - depth.at(y, x-1)) / 2.0;
Vec3d d = (dzdx, dzdy, 1.0);
Vec3d n = normalize(d);
}
}
↧