From 86aefe67b8362c8db4fdb0f42d91ee838dd837be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=B6=E6=89=8D=20=E7=8E=8B?= Date: Thu, 2 May 2019 16:23:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E5=8F=AF=E4=BB=A5=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E8=A7=86=E5=B7=AE=E5=92=8C=E8=BF=90=E5=8A=A8=E7=9F=A2?= =?UTF-8?q?=E9=87=8F=E4=BA=86=EF=BC=9A=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StereoVidComfort.py | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/StereoVidComfort.py b/StereoVidComfort.py index 3b15c9b..421d0fe 100644 --- a/StereoVidComfort.py +++ b/StereoVidComfort.py @@ -8,7 +8,8 @@ from matplotlib import pyplot as plt def openVid(): - fileName = input("video path:") + fileName = "./vid/zootopia.mkv" + #fileName = input("video path:") while not os.path.isfile(fileName): print("file doesn't exist!") fileName = input("video path:") @@ -40,21 +41,42 @@ if __name__ == "__main__": cap = openVid() frameRate = getFrameRate(cap) frameCount = getFrameCount(cap) - - - for frameID in range(int(frameRate), int(frameCount), int(frameRate*100)): + ret, img = cap.read() + imgR = np.split(img, 2, 1)[1] + prvs = cv2.cvtColor(imgR, cv2.COLOR_BGR2GRAY) + hsv = np.zeros_like(imgR) + hsv[..., 1] = 255 + cap.set(cv2.CAP_PROP_POS_FRAMES,12000) + for frameID in range(int(cap.get(cv2.CAP_PROP_POS_FRAMES)), int(frameCount), int(frameRate/2)): cap.set(cv2.CAP_PROP_POS_FRAMES, frameID) isSuccess, img = cap.read() if isSuccess: - cv2.namedWindow("img", cv2.WINDOW_NORMAL) - cv2.imshow('img', img) + imgL = np.split(img, 2, 1)[0] imgR = np.split(img, 2, 1)[1] + next = cv2.cvtColor(imgR, cv2.COLOR_BGR2GRAY) + flow = cv2.calcOpticalFlowFarneback(prvs, next, None, 0.5, 3, 15, 3, 5, 1.2, 0) + mag, ang = cv2.cartToPolar(flow[..., 0], flow[..., 1]) + hsv[..., 0] = ang*180/np.pi/2 + hsv[..., 2] = cv2.normalize(mag, None, 0, 255, cv2.NORM_MINMAX) + bgr = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR) + + cv2.namedWindow("imgR", cv2.WINDOW_NORMAL) + cv2.imshow('imgR', imgR) + cv2.namedWindow("MotionVector",cv2.WINDOW_NORMAL) + cv2.imshow("MotionVector",bgr) + prvs = next + stereo = cv2.StereoSGBM_create(numDisparities=96, blockSize=11) disparity = stereo.compute(imgL, imgR) + #cv2.waitKey(1) plt.title("DepthMap") plt.imshow(disparity) plt.pause(0.5) + else: + print("video read error") + print("success") +