From 70a24ff8c532468892375fc5e67a68c5b7b62423 Mon Sep 17 00:00:00 2001 From: "Mr.B" <114798102+MrB141107@users.noreply.github.com> Date: Wed, 4 Oct 2023 21:08:32 +0530 Subject: [PATCH] Create Selfie_with_Python.py --- Selfie_with_Python/Selfie_with_Python.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Selfie_with_Python/Selfie_with_Python.py diff --git a/Selfie_with_Python/Selfie_with_Python.py b/Selfie_with_Python/Selfie_with_Python.py new file mode 100644 index 0000000..7865aa0 --- /dev/null +++ b/Selfie_with_Python/Selfie_with_Python.py @@ -0,0 +1,23 @@ +import cv2 +cam = cv2.VideoCapture(0) +cv2.namedWindow("Take selfie with python") +img=0 +while True: + ret, frame = cam.read() + + if not ret: + print("Failed to grab frame") + break + + cv2.imshow("Take selfie with python",frame) + k = cv2.waitKey(1) + if k%256 == 27: + print("Escape hit, closing the window") + break + if k%256 == 32: + img_name = f"Selfie_{img}.jpg" + cv2.imwrite(img_name,frame) + print("Selfie taken!") + img+=1 +cam.release +cv2.destroyAllWindows()