Created
March 25, 2017 07:33
-
-
Save dyama/277e23c35bdfd8d8d4b5b992c03683e5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# coding: utf-8 | |
import numpy as np | |
import cv2 | |
from matplotlib import pyplot as plt | |
img_left = cv2.imread("l.jpg",0) | |
img_right = cv2.imread("r.jpg",0) | |
img_left = cv2.GaussianBlur(cv2.equalizeHist(img_left), (3,3), 0) | |
img_right = cv2.GaussianBlur(cv2.equalizeHist(img_right) ,(3,3), 0) | |
window_size = 1 | |
stereo = cv2.StereoSGBM( | |
minDisparity = 0, # 視差の下限 | |
numDisparities = 32, # 最大の上限 | |
SADWindowSize = window_size,# SADの窓サイズ | |
uniquenessRatio = 2, # パーセント単位で表現されるマージン | |
speckleWindowSize = 2, # 視差領域の最大サイズ | |
speckleRange = 16, # それぞれの連結成分における最大視差値 | |
disp12MaxDiff = 2, # left-right 視差チェックにおけて許容される最大の差 | |
P1 = 8*3*window_size**2, # 視差のなめらかさを制御するパラメータ1 | |
P2 = 32*3*window_size**2, # 視差のなめらかさを制御するパラメータ2 | |
fullDP = True # 完全な2パス動的計画法を使うならTrue | |
) | |
disp = stereo.compute(img_left, img_right) | |
disp = cv2.normalize(disp, alpha = 0, beta = 255, norm_type = cv2.NORM_MINMAX, dtype = cv2.CV_8U) | |
cv2.imshow("disp", disp) | |
cv2.waitKey(0) | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment