Last active
August 29, 2015 14:03
-
-
Save nileshtrivedi/0ba3224d470479619c02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# You need stereovision package to run this. Try "sudo pip install stereovision" | |
import cv2 | |
from stereovision.blockmatchers import StereoBM, StereoSGBM | |
from stereovision.calibration import StereoCalibration | |
from stereovision.stereo_cameras import CalibratedPair | |
from stereovision.ui_utils import STEREO_BM_FLAG, BMTuner | |
# Specify paths to left and right camera images below. They must be calibrated and rectified. | |
image_pair = [cv2.imread(image) for image in ["left.pnm", "right.pnm"]] | |
block_matcher = StereoBM() # or StereoSGBM() which is a semi-global block matcher | |
# You will need to tune the block matcher to get better results | |
# This blog post describes how to do it: | |
# http://erget.wordpress.com/2014/03/13/building-an-interactive-gui-with-opencv/ | |
bm_tuner_gui = BMTuner(block_matcher, None, image_pair) | |
# Generate point cloud from the disparity map and generate a point cloud in the PLY format to view in MeshLab | |
# We need Disparity to depth mapping matrix (4x4 matrix, Q) | |
# disparity = block_matcher.get_disparity(image_pair) | |
# points = block_matcher.get_3d(disparity,calibration.disp_to_depth_mat) | |
# colors = cv2.cvtColor(image_pair[0], cv2.COLOR_BGR2RGB) | |
# pcloud = PointCloud(points, colors) | |
# pcloud = pcloud.filter_infinity() | |
# pcloud.write_ply(args.output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment