ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org

# processing kinect depth frame is very slow

I am processing depth frame from Kinect try to find the ground floor, I am using simple method of computing for each pixel whether they belong to the equation of ground surface or not, I already computed a,b,c,d parameters of the equation of the ground, and I would like to process each pixel to be able to accept it as a ground pixel or now. Here is a snippet of my code for processing each frame:

for i in xrange(rows):
for j in xrange(cols):
x0 = frame[i, j]*math.cos((j-midx)*ax)*math.sin((i-midy)*ay)
y0 = frame[i, j]*math.sin((j-midx)*ax)*math.sin((i-midy)*ay)
z0 = frame[i, j]*math.cos((i-midy)*ay)
if abs(self.a*x0+self.b*y0+self.c*z0-self.d) < 0.0002:
frame[i,j] = 10


for some reason each frame take more than 10 seconds to finish. This seems extremely slow. I am not sure why. Any help would be appreciate it.
EDIT: Here are my computer info:

Processor: Intel® Core™2 Duo CPU T6400 @ 2.00GHz × 2

Ram: 3GB

edit retag close merge delete

Sort by » oldest newest most voted

• If you want speed, especially when processing point clouds, you'll have a better time with C++
• That hardware is pretty old
• There are a bunch of computations that you do multiple times per iteration in the inner loop. I'm not sure exactly what optimizations the python interpreter will do, but here are things that might help:
• Don't do multiple lookups of frame[i, j]. Assign it to a variable and then use that variable
• Only compute (j-midx)*ax, (i-midy)*ay, math.sin((i-midy)*ay), etc. once
• Rather than looping, try to use numpy's array operations. They'll be much faster. meshgrid will probably be very useful here.
more How fast is your mashine? for each pexel you have 5 trigonometrik operations.

more

please note my recent edit to the question. Thanks