Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code to save the results #526

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion Object_detection_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@
# Open video file
video = cv2.VideoCapture(PATH_TO_VIDEO)

# PropIds of the video frame required to save the video
frame_width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))

# FourCC Codec to identify the data format of the video file
fourcc = cv2.VideoWriter_fourcc(*"XVID")

# Save the video file to .mp4 using cv2.VideoWriter() class which takes 5 arguments viz. filename, fourcc code, fps and size of the window
saved_video = cv2.VideoWriter("object_detector.mp4", fourcc, 20.0, (frame_width, frame_height))

while(video.isOpened()):

# Acquire frame and expand frame dimensions to have shape: [1, None, None, 3]
Expand All @@ -116,11 +126,15 @@

# All the results have been drawn on the frame, so it's time to display it.
cv2.imshow('Object detector', frame)


# Save the results
saved_video.write(frame)

# Press 'q' to quit
if cv2.waitKey(1) == ord('q'):
break

# Clean up
video.release()
saved_video.release()
cv2.destroyAllWindows()