Hi there @hOz, sorry to bump an old topic. I am currently working with OpenCV and it's my first time playing around with this stuff. I was wondering what parameters you used with your StereoVar examples? I have an example here of my point cloud but it is really noisy.
With regards to the actual topic, I put the distortion map into OpenCV like this:
public static Map<String,Mat> initDistortionMat(Image image){
Mat distortionX = new Mat();
Mat distortionY = new Mat();
distortionX = Mat.ones(image.height(),image.width(),CvType.CV_32F);
distortionY = Mat.ones(image.height(),image.width(),CvType.CV_32F);
for(int y = 0; y < image.height(); ++y){
for(int x = 0; x < image.width();++x){
Vector input = new Vector((float)x/image.width(), (float)y/image.height(), 0);
input.setX((input.getX() - image.rayOffsetX()) / image.rayScaleX());
input.setY((input.getY() - image.rayOffsetY()) / image.rayScaleY());
Vector pixel = image.warp(input);
if(pixel.getX() >= 0 && pixel.getX() < image.width() && pixel.getY() >= 0 && pixel.getY() < image.height()) {
distortionX.put(y, x, pixel.getX());
distortionY.put(y, x, pixel.getY());
} else {
distortionX.put(y, x, -1);
distortionY.put(y, x, -1);
}
}
}
Map<String, Mat> distortionMats = new HashMap<>();
distortionMats.put("x", tempX);
distortionMats.put("y", tempY);
return distortionMats;
}
You do this once when you initialise the leap motion, then you can just call:
Imgproc.remap(imageToUndistort, undistortedImage, distortionX, distortionY, Imgproc.INTER_LINEAR);
I get a distortion map from both a left and a right image. Then process them separately using the images id(). This is in java but is the same idea in all languages.