From e696250c005d202a240761ce0d4a9f7d3fbfc3a4 Mon Sep 17 00:00:00 2001 From: Mauzum Shamil <151765060+mauzumshamil@users.noreply.github.com> Date: Sun, 21 Apr 2024 14:10:06 +0400 Subject: [PATCH] Add files via upload --- ...FACE CAPTURE AND LIVE FACE DETECTION.ipynb | 166 ++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 A PROJECT WITH OPENCV ON LIVE FACE CAPTURE AND LIVE FACE DETECTION.ipynb diff --git a/A PROJECT WITH OPENCV ON LIVE FACE CAPTURE AND LIVE FACE DETECTION.ipynb b/A PROJECT WITH OPENCV ON LIVE FACE CAPTURE AND LIVE FACE DETECTION.ipynb new file mode 100644 index 0000000..d2a2a1d --- /dev/null +++ b/A PROJECT WITH OPENCV ON LIVE FACE CAPTURE AND LIVE FACE DETECTION.ipynb @@ -0,0 +1,166 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 7, + "id": "2e4261c0", + "metadata": {}, + "outputs": [], + "source": [ + "import cv2\n", + "import matplotlib.pyplot as plt" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "bc8b5e14", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "< cv2.VideoCapture 0000014A9D92E010>" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "vid = cv2.VideoCapture(0)\n", + "vid" + ] + }, + { + "cell_type": "markdown", + "id": "be4c1cf5", + "metadata": {}, + "source": [ + " Live Capturing" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "fbd53b2b", + "metadata": {}, + "outputs": [], + "source": [ + "import cv2\n", + "\n", + "vid = cv2.VideoCapture(0)\n", + "\n", + "while True:\n", + " success, frame = vid.read()\n", + " if not success:\n", + " # If unable to read frame, break the loop\n", + " break\n", + " \n", + " cv2.imshow(\"Video\", frame)\n", + " if cv2.waitKey(1) & 0xFF == 27:\n", + " break\n", + "\n", + "vid.release()\n", + "cv2.destroyAllWindows()\n" + ] + }, + { + "cell_type": "markdown", + "id": "a3bf1372", + "metadata": {}, + "source": [ + "Live capturing with face detections" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "f58e6f0d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "< cv2.VideoCapture 0000014A9D92E290>" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "vid = cv2.VideoCapture(0)\n", + "vid" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "d660da44", + "metadata": {}, + "outputs": [], + "source": [ + "face_cascade =cv2.CascadeClassifier('haarcascade_frontalface_default .xml')" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "a8131c25", + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "vid = cv2.VideoCapture(0)\n", + "\n", + "while True:\n", + " success, frame = vid.read()\n", + " \n", + " if frame is not None and frame.shape[0] > 0 and frame.shape[1] > 0:\n", + " faces = face_cascade.detectMultiScale(frame)\n", + " for (x,y,w,h) in faces:\n", + " cv2.rectangle(frame,(x,y),(x+w,y+h),color=(255,0,255),thickness=3)\n", + " \n", + " cv2.imshow(\"Video\", frame)\n", + "\n", + " if cv2.waitKey(1) & 0xFF == 27:\n", + " break\n", + "\n", + "vid.release()\n", + "cv2.destroyAllWindows()\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4427271d", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.4" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}