opencv_recode.py 1013 B

1234567891011121314151617181920212223242526272829303132333435
  1. import numpy as np
  2. import cv2
  3. import time
  4. #cap = cv2.VideoCapture('rtsp://192.168.50.181/av0_0')
  5. cap = cv2.VideoCapture('http://192.168.50.177:81/stream')
  6. #cap = cv2.VideoCapture(0)
  7. fourcc = cv2.VideoWriter_fourcc(*'XVID')
  8. # 建立 VideoWriter 物件,輸出影片至 output.avi
  9. # FPS 值為 20.0,解析度為 640x360
  10. #out = cv2.VideoWriter('output_test.avi', fourcc, 25.0, (1920, 1080))
  11. out = cv2.VideoWriter('outputtest.avi', fourcc, 25.0, (320, 240))
  12. while(True):
  13. ret, frame = cap.read()
  14. if ret == True:
  15. out.write(frame)
  16. frame = cv2.resize(frame, (800, 600))
  17. cv2.imshow('frame',frame)
  18. if cv2.waitKey(1) & 0xFF == ord('p'):
  19. now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
  20. cv2.imwrite('C:\\Users\\User\\Desktop\\company_files\\opencv\\' + now + ".jpg", frame)
  21. elif cv2.waitKey(1) & 0xFF == ord('q'):
  22. break
  23. # When everything done, release the capture
  24. cap.release()
  25. cv2.destroyAllWindows()