movie3d.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import numpy as np
  2. import cv2
  3. CamL_id = "data/stereoL.mp4"
  4. CamR_id = "data/stereoR.mp4"
  5. CamL= cv2.VideoCapture(CamL_id)
  6. CamR= cv2.VideoCapture(CamR_id)
  7. print("Reading parameters ......")
  8. cv_file = cv2.FileStorage("data/params_py.xml", cv2.FILE_STORAGE_READ)
  9. Left_Stereo_Map_x = cv_file.getNode("Left_Stereo_Map_x").mat()
  10. Left_Stereo_Map_y = cv_file.getNode("Left_Stereo_Map_y").mat()
  11. Right_Stereo_Map_x = cv_file.getNode("Right_Stereo_Map_x").mat()
  12. Right_Stereo_Map_y = cv_file.getNode("Right_Stereo_Map_y").mat()
  13. cv_file.release()
  14. while True:
  15. retR, imgR= CamR.read()
  16. retL, imgL= CamL.read()
  17. if retL and retR:
  18. imgR_gray = cv2.cvtColor(imgR,cv2.COLOR_BGR2GRAY)
  19. imgL_gray = cv2.cvtColor(imgL,cv2.COLOR_BGR2GRAY)
  20. Left_nice= cv2.remap(imgL,Left_Stereo_Map_x,Left_Stereo_Map_y, cv2.INTER_LANCZOS4, cv2.BORDER_CONSTANT, 0)
  21. Right_nice= cv2.remap(imgR,Right_Stereo_Map_x,Right_Stereo_Map_y, cv2.INTER_LANCZOS4, cv2.BORDER_CONSTANT, 0)
  22. output = Right_nice.copy()
  23. output[:,:,0] = Right_nice[:,:,0]
  24. output[:,:,1] = Right_nice[:,:,1]
  25. output[:,:,2] = Left_nice[:,:,2]
  26. # output = Left_nice+Right_nice
  27. output = cv2.resize(output,(700,700))
  28. cv2.namedWindow("3D movie",cv2.WINDOW_NORMAL)
  29. cv2.resizeWindow("3D movie",700,700)
  30. cv2.imshow("3D movie",output)
  31. cv2.waitKey(1)
  32. else:
  33. break