ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

processing kinect depth frame is very slow

asked 2015-07-27 10:00:16 -0500

Samer gravatar image

updated 2015-07-27 18:09:10 -0500

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 flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2015-07-28 11:53:19 -0500

A few comments:

  • 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.
edit flag offensive delete link more
0

answered 2015-07-27 12:50:24 -0500

duck-development gravatar image

How fast is your mashine? for each pexel you have 5 trigonometrik operations.

edit flag offensive delete link more

Comments

please note my recent edit to the question. Thanks

Samer gravatar image Samer  ( 2015-07-27 18:08:26 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2015-07-27 09:57:22 -0500

Seen: 652 times

Last updated: Jul 28 '15