Created
April 30, 2019 09:48
-
-
Save OlafenwaMoses/d5c09d1d814fa40adf3fc8bc998a8a49 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
import requests | |
cap = cv2.VideoCapture('furious.mp4') | |
out = cv2.VideoWriter("scene_recognition_from_video_to_file.avi", cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'), | |
24,((int(cap.get(3)), int(cap.get(4))))) | |
progress_tracker = 0 | |
response_label = "" | |
skip_frame = 20 | |
while(cap.isOpened()): | |
valid, frame = cap.read() | |
if valid == True: | |
progress_tracker += 1 | |
if(progress_tracker % skip_frame == 0): | |
retval, new_frame = cv2.imencode('.jpg', frame) | |
response = requests.post("http://localhost:80/v1/vision/scene", | |
files={"image":new_frame}).json() | |
response_label = response['label'] | |
print(response_label) | |
font = cv2.FONT_HERSHEY_PLAIN | |
frame = cv2.putText(frame, '{}'.format(response_label), (25, 35), font, 3, (255, 255, 0), 1, cv2.LINE_AA) | |
out.write(frame) | |
else: | |
break | |
print('<==============Video file as been full written with face bounding boxes============>') | |
cap.release() | |
out.release() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment