/playVideo.py

https://gitlab.com/argenos/VirtualBlackboard
Python | 89 lines | 66 code | 14 blank | 9 comment | 10 complexity | a9a8c9fb80c52320c3f3f831b7b03a84 MD5 | raw file
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Sat Jan 10 10:02:05 2015
  4. @author: Argen
  5. """
  6. import glob
  7. import cv2
  8. import numpy as np
  9. import Color as color
  10. path = 'images/frames/demo_class/'
  11. length = glob.glob(path+'*.png').__len__()/2
  12. def playSingleVideo(path, mask=True):
  13. #print length
  14. i = 0
  15. cv2.namedWindow("Frame sequence")
  16. print 'Press any key to play...'
  17. cv2.waitKey(0)
  18. while True:
  19. im = cv2.imread(path+'c1_image%.3d.png'%i)
  20. if mask:
  21. img = cv2.resize(im,(640,480))
  22. img = color.getColorMask(img,'b')
  23. cv2.imshow("Frame sequence",img)
  24. i = i + 1
  25. if i >= length:
  26. i = 0
  27. if cv2.waitKey(1) & 0xFF == ord('q'):
  28. break
  29. cv2.destroyAllWindows()
  30. def playTwoVideos(path, mask=False, marker=True):
  31. i = 0
  32. small = (320,240)
  33. big = (640,480)
  34. demo = 'demo_302'
  35. detect = 'images/results/'+demo+'/detection/'
  36. board = 'images/results/'+demo+'/board/'
  37. fourcc = cv2.cv.FOURCC('m','p','4','v')
  38. out = cv2.VideoWriter('video/demo_302.mov',fourcc,3,(1280,480),True)
  39. cv2.namedWindow("Frame sequence")
  40. print 'Press any key to play...'
  41. cv2.waitKey(0)
  42. while True:
  43. im1 = cv2.imread(path+'c1_image%.3d.png'%i)
  44. im2 = cv2.imread(path+'c2_image%.3d.png'%i)
  45. d1 = cv2.imread(detect+'c1_%.3d.jpg'%i)
  46. d2 = cv2.imread(detect+'c2_%.3d.jpg'%i)
  47. b = cv2.imread(board+'board_%.3d.jpg'%i)
  48. if mask:
  49. img1 = cv2.resize(im1,(640,480))
  50. img2 = cv2.resize(im2,(640,480))
  51. img1 = color.getColorMask(img1,'b')
  52. img2 = color.getColorMask(img2,'b')
  53. else:
  54. img1 = cv2.resize(im1,small)
  55. img2 = cv2.resize(im2,small)
  56. d1 = cv2.resize(d1,small)
  57. d2 = cv2.resize(d2,small)
  58. b = cv2.resize(b,big)
  59. img = np.hstack((img1,img2))
  60. d = np.hstack((d1,d2))
  61. result = np.hstack((np.vstack((img,d)),b))
  62. out.write(result)
  63. cv2.imshow("Frame sequence",result)
  64. i = i + 1
  65. if i >= length:
  66. break
  67. #i = 0
  68. if cv2.waitKey(1) & 0xFF == ord('q'):
  69. break
  70. out.release()
  71. cv2.destroyAllWindows()
  72. if __name__ == '__main__':
  73. #playSingleVideo(path)
  74. playTwoVideos(path)