-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3012b2f
commit e696250
Showing
1 changed file
with
166 additions
and
0 deletions.
There are no files selected for viewing
166 changes: 166 additions & 0 deletions
166
A PROJECT WITH OPENCV ON LIVE FACE CAPTURE AND LIVE FACE DETECTION.ipynb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |