Skip to content

Commit

Permalink
add a take_screenshot_from_video function
Browse files Browse the repository at this point in the history
  • Loading branch information
pythontoday committed May 10, 2021
1 parent 2c6c96f commit d84b687
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 1 deletion.
Binary file added dataset_from_video/0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dataset_from_video/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dataset_from_video/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dataset_from_video/3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dataset_from_video/4_extra_scr.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 43 additions & 1 deletion training_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pickle
import sys
import face_recognition
from cv2 import cv2


def train_model_by_img(name):
Expand Down Expand Up @@ -53,8 +54,49 @@ def train_model_by_img(name):
return f"[INFO] File {name}_encodings.pickle successfully created"


def take_screenshot_from_video():
cap = cv2.VideoCapture("video.mp4")
count = 0

if not os.path.exists("dataset_from_video"):
os.mkdir("dataset_from_video")

while True:
ret, frame = cap.read()
fps = cap.get(cv2.CAP_PROP_FPS)
multiplier = fps * 3
# print(fps)

if ret:
frame_id = int(round(cap.get(1)))
# print(frame_id)
cv2.imshow("frame", frame)
k = cv2.waitKey(20)

if frame_id % multiplier == 0:
cv2.imwrite(f"dataset_from_video/{count}.jpg", frame)
print(f"Take a screenshot {count}")
count += 1

if k == ord(" "):
cv2.imwrite(f"dataset_from_video/{count}_extra_scr.jpg", frame)
print(f"Take an extra screenshot {count}")
count += 1
elif k == ord("q"):
print("Q pressed, closing the app")
break

else:
print("[Error] Can't get the frame...")
break

cap.release()
cv2.destroyAllWindows()


def main():
print(train_model_by_img("person_name"))
# print(train_model_by_img("person_name"))
take_screenshot_from_video()


if __name__ == '__main__':
Expand Down
Binary file added video.mp4
Binary file not shown.

0 comments on commit d84b687

Please sign in to comment.