Understanding stereo_match.py sample

asked 2016-01-24 09:52:56 -0600

Sagar DV gravatar image

updated 2016-01-24 21:04:45 -0600

Hello there,

I am using the Nodejs port of Opencv for a 3D reconstruction project. So im trying to convert the sample stereo_match.py given in OpenCV source code to javascript. First, I am trying to understand the code and the problem is that, I am stuck at a step where the mask is found, and the out_points and out_colors are calculated. The code related to that is given below:

mask = disp > disp.min()
out_points = points[mask]
out_colors = colors[mask]

Im just not able to understand what is going on when calculating the out_points and out_colors. I know that the mask, points and colors are numpy arrays of size 555x641. But when the above operation is done, the out_points and out_colors obtained are 3000000x3 arrays. Now the question is, what is logic behind the above code, and how do you achieve this in pure python?(that is, lets say we have mask, points and colors as normal arrays, and we need to do the above operation without using numpy and calculate out_points and out_colors).

Thank you

P.S : Here is my JS code that I was able to do uptill now given here : http://pastebin.com/0JELgFZg

edit retag flag offensive close merge delete

Comments

1

just be aware, that 3rd party wrappers like node.js tend to be quite off-topic here.

berak gravatar imageberak ( 2016-01-24 10:20:21 -0600 )edit

@berak Actually at first, I also thought it might be off topic, but the question that I want to ask is related to the python code given in the sample.... What I understood is that, the points and colors are 555x641 arrays, but when the above operation is done with the mask, they turn into 300000x3 arrays. I just dont know what that operation is doing. So my Question is related to that and I think it not off topic. If there is pure python version available for that above operation, that is appreciated.

Sagar DV gravatar imageSagar DV ( 2016-01-24 12:35:56 -0600 )edit

^^ no fear, my only point there is, that we probably can't help with the js side of it.

berak gravatar imageberak ( 2016-01-24 20:34:15 -0600 )edit

@berak, I will edit the question so that, it would stick to only python then, if I can get a pure python implementation of the code, then I might be able to convert it later in my own way.

Sagar DV gravatar imageSagar DV ( 2016-01-24 20:57:59 -0600 )edit

"and we need to do the above operation without using numpy" - there's the crux, i guess.

but isn't it all about filtering ? you only want to retain points, where the resp. disparity is larger than the min value (to filter out NaN values from the prev. reprojectImageTo3D step)

berak gravatar imageberak ( 2016-01-24 21:36:14 -0600 )edit

your js code is already iterating though the disparity values, right ?

maybe, - instead of writing a mask(i don't think you need it !), try to make a new Point and Colour array there, and only insert if disp > min

berak gravatar imageberak ( 2016-01-24 21:42:36 -0600 )edit

@berak if I do that, I would be getting the out_points and out_colors as arrays of size smaller than 555x641, but in the python version, it gives out 300000x3 arrays. I dont know how that is happening...

Sagar DV gravatar imageSagar DV ( 2016-01-24 21:50:03 -0600 )edit