def update(): colors = ((1.0, 1.0, 1.0, 1.0)) # out = cv2.imread('car_depth.png') # out = out.astype(float) # out = out/16 # colors = cv2.imread('car.png') # colors = colors.astype(float) # colors = colors/255 # ret, frame = cap.read() #gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) retL, left_img = capL.read() retR, right_img = capR.read() # left_img = frame[:,0:(width/2)] # right_img = frame[:,(width/2):width] disparity_img1 = df.disparity_with_filter(left_img, right_img, 32, 5) disparity_img2, max_val = df.disparity_without_filter(left_img, right_img, 64, 9) disparity_img1 = cv2.normalize(src=disparity_img1, dst=disparity_img1, beta=0, alpha=255, norm_type=cv2.NORM_MINMAX); disparity_img1 = np.uint8(disparity_img1) depthMapImg = cv2.reprojectImageTo3D(disparity_img1, Q) colors = left_img.astype(float) colors = colors/255 sp2.setData(pos=np.array(depthMapImg, dtype=np.float64), color=colors, size=2)
def update(): colors = ((1.0, 1.0, 1.0, 1.0)) # retL, imgL = capL.read() # retR, imgR = capR.read() nameL = sys.argv[1] nameR = sys.argv[2] imgL = cv2.imread(nameL) imgR = cv2.imread(nameR) left_img = cv2.remap(imgL, left_maps[0], left_maps[1], cv2.INTER_LINEAR) right_img = cv2.remap(imgR, right_maps[0], right_maps[1], cv2.INTER_LINEAR) left_img_gray = cv2.cvtColor(left_img, cv2.COLOR_BGR2GRAY) right_img_gray = cv2.cvtColor(right_img, cv2.COLOR_BGR2GRAY) disparity_img = df.disparity_with_filter(left_img_gray, right_img_gray, 160, 5) disparity_img = disparity_img/16 disparity_img[disparity_img < 50] = 50 depth_img = ((724*20)/disparity_img) * math.cos(math.atan2(26,37)) xyz = np.copy(xyz_init) xyz[:,:,0] = np.multiply(xyz[:,:,0], depth_img) xyz[:,:,0] = xyz[:,:,0] / 724 xyz[:,:,1] = np.multiply(xyz[:,:,1], depth_img) xyz[:,:,1] = xyz[:,:,1] / 724 xyz[:,:,2] = depth_img colors = left_img.astype(float) colors = colors/255 temp_clr = colors[:,:,0] colors[:,:,0] = colors[:,:,2] colors[:,:,2] = temp_clr sp2.setData(pos=np.array(xyz, dtype=np.float64), color=colors, size=2)
import numpy as np import cv2 import sys from matplotlib import pyplot as plt import scipy.io as sio Q = np.float32([[1, 0, 0, -3.77753695e+02], [0, 1, 0, -2.06903945e+02], [0, 0, 0, 6.74158207e+02], [0, 0, 4.97033865e-02, 0]]) left_img = cv2.imread(sys.argv[1]) right_img = cv2.imread(sys.argv[2]) #print sys.argv[0] #print left_img.shape disparity_img = df.disparity_with_filter(left_img, right_img, 160, 5) #disparity_img2, max_val = df.disparity_without_filter(left_img, right_img, 32, 9) disparity_img1 = np.copy(disparity_img) disparity_img1 = disparity_img1 / 16 disparity_img = cv2.normalize(src=disparity_img, dst=disparity_img, beta=0, alpha=255, norm_type=cv2.NORM_MINMAX) disparity_img = np.uint8(disparity_img) print np.amax(disparity_img) print np.amin(disparity_img) print np.amax(disparity_img1) print np.amin(disparity_img1)
import disparity_functions as df import numpy as np import cv2 import sys Q = np.float32([[1, 0, 0, 4.95838611e+02], [0, 1, 0, 2.24740481e+01], [0, 0, 0, 4.23789559e+00], [0, 0, 4.66947240e-03, 0]]) left_img = cv2.imread('resources/left_image/left_img6.png') right_img = cv2.imread('resources/right_image/right_img6.png') disparity_img1 = df.disparity_with_filter(left_img, right_img, 32, 5) disparity_img2, max_val = df.disparity_without_filter(left_img, right_img, 32, 9) disparity_img1 = cv2.normalize(src=disparity_img1, dst=disparity_img1, beta=0, alpha=255, norm_type=cv2.NORM_MINMAX); disparity_img1 = np.uint8(disparity_img1) disparity_img2 = cv2.normalize(src=disparity_img2, dst=disparity_img2, beta=0, alpha=255, norm_type=cv2.NORM_MINMAX); disparity_img2 = np.uint8(disparity_img2) cv2.imshow('with filter', disparity_img1) cv2.imshow('without filter', disparity_img2) cv2.waitKey(0)