1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| import cv2 import requests import os
def video_post(files): response = requests.post("http://127.0.0.1:5000/upload", data=None, files=files, verify=False, stream=True) print("picture upload state: ", response.status_code)
def read_video_show(videoName): ''' opencv 读取视频
cv2.VideoCapture(filename) #读取本地视频 cv2.VideoCapture(index) #获取摄像头 '''
cap = cv2.VideoCapture(videoName)
while cap.isOpened():
ret, frame = cap.read() img_path = os.path.join(os.getcwd(), "results", "result.png") cv2.imwrite(img_path, frame) files = {'file': open(img_path, 'rb')} video_post(files)
if ret: cv2.imshow('frame', frame) key = cv2.waitKey(25) if key == ord(' ') or key == ord('q'): break
cap.release() cv2.destroyAllWindows()
if __name__ == "__main__": read_video_show("static/video.mp4")
|