Understanding stereo_match.py sample

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()

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

1

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

@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.

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

@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.

"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)

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 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...