-
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
1f493aa
commit c0c56fd
Showing
1 changed file
with
87 additions
and
0 deletions.
There are no files selected for viewing
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,87 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import cv2\n", | ||
"\n", | ||
"#load some pretrained data on face frontals opencv supplied\n", | ||
"trained_face_data= cv2.CascadeClassifier('haarcascade_frontalface_default.xml')\n", | ||
"\n", | ||
"#to read an image to detect faces\n", | ||
"#img=cv2.imread('MSD.jpg')\n", | ||
"webcam=cv2.VideoCapture(0)\n", | ||
"\n", | ||
"\n", | ||
"\n", | ||
"while True:\n", | ||
" \n", | ||
" success_frame_read, frame=webcam.read()\n", | ||
"#to show img\n", | ||
"#cv2.imshow('face detec',img)\n", | ||
"\n", | ||
"#got to make image black as we are using harcascade algo , it uses gray scale \n", | ||
"\n", | ||
" grayscaled_img=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)\n", | ||
"\n", | ||
" cv2.imshow('images',grayscaled_img)\n", | ||
"\n", | ||
"#now we need to plug our image to the algo, so we use trained data\n", | ||
"#detect faces\n", | ||
"#face_coordinates=trained_face_data.detectMultiScale(grayscaled_img)\n", | ||
"\n", | ||
"#print(face_coordinates)\n", | ||
"#detectmultiscale detects objects of diff sizes in the input img. and returned as rectangles\n", | ||
"\n", | ||
"\n", | ||
"#draw rectangles around the faces (x,y,w,h) coordinates\n", | ||
"#cv2.rectangle(img,(x,y),(x+w,y+h),(r,g,b), rect thickness)\n", | ||
"\n", | ||
"#cv2.rectangle(img,(660,62),(660+349,62+349),(0,255,0),3)\n", | ||
"\n", | ||
"\n", | ||
"#cv2.imshow('show',img) to show img with rec\n", | ||
"#waits for image to open\n", | ||
" key=cv2.waitKey(2)\n", | ||
" \n", | ||
" if key==81 or key==113:\n", | ||
" break\n", | ||
" \n", | ||
"webcam.release()\n", | ||
"\n", | ||
"#if you have images next to next use for loop \n", | ||
"#for (x,y,w,h) in face_coordinates:\n", | ||
" # cv2.rectangle(img,(x,y),(x+w,y+h),(r,g,b), rect thickness)\n", | ||
"\n", | ||
"#to capture video from webcam\n", | ||
"\n", | ||
" \n", | ||
" \n", | ||
" \n", | ||
"\n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"q\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |