Skip to main content

HOW TO DETECT FACES IN PYTHON USING OPENCV (face detection in python)

hello guys in this tutorial we will take a look at how to detect faces in python using opencv
code : -
###########################################
#robokishan
#don't just copy and paste it will never work  install opencv and also modules required for it
#then just download opencv from git and copy this file "haarcascade_frontalface_default.xml"


#if you have such a brain this code speaks lot more than i show just figure out what else you can do
#uncomment some useful stuffs


#!/usr/bin/python
import cv2
import numpy as np

face_cascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
# eye_cascade = cv2.CascadeClassifier("haarcascade_eye.xml")
# smile = cv2.CascadeClassifier("haarcascade_smile.xml")
cap = cv2.VideoCapture(0)

while True:
ret , frame  = cap.read()
gray = cv2.cvtColor(frame , cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray , 1.3 , 5)
for (x,y,w,h) in faces:
cv2.rectangle(frame , (x,y) , (x+w , y+h) , (255 , 0, 0) , 2)
roi_gray = gray[y:y+h , x:x+w]
roi_color = frame[y:y+h , x:x+w]
# smiles=smile.detectMultiScale(roi_gray)
# for(ex,ey,ew,eh) in smiles:
# cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
# eyes = eye_cascade.detectMultiScale(roi_gray)
# for(ex,ey,ew,eh) in eyes:
# cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
cv2.imshow('frame' , frame)
k = cv2.waitKey(30) & 0xff
if k == 27: #esc key
break
cap.release()
cv2.destroyAllWindows()

###########################################





if you find out it is usefull please can you comment for more my information. something useful for me.
related to python, java, linux, android programming challenges.
thank you

Comments

Popular posts from this blog

Python Reads gmail

This is tutorial on how to read gmail emails with python programme : ----------------- #!/usr/bin/python __author__ = 'Robokishan' import email import imaplib import ctypes import getpass mail = imaplib.IMAP4_SSL('imap.gmail.com',993) unm = raw_input("insert Email : ") #pwd = raw_input("insert password : ") pwd = getpass.getpass("input : ") mail.login(unm,pwd) mail.select("INBOX") def loop():    mail.select("INBOX")    n=0    (retcode, messages) = mail.search(None, '(UNSEEN)')    if retcode == 'OK':             for num in messages[0].split() :          #print 'Processing '          n=n+1          print n          typ, data = mail.fetch(num,'(RFC822)')          for response_part in data:             if isinstance(response_part, tuple): ...

How to make stoppable thread in python

Python multi threading: stoppable thread:     many of you heard about threading in python is very bad. its not easy to stop it but there are several method to do that thing happen .     so lets get started.     create file name called <filename>.py then paste this code in your text editor. import threading import time ##writer = Robokishan ##stopable thread class ThreadingExample(object):     """ Threading example class     The run() method will be started and it will run in the background     until the application exits.     """     #NOTE: STOPING THREAD IS BAD METHOD     def __init__(self, interval=1):         """ Constructor         :type interval: int         :param interval: Check interval, in seconds       ...

All Android Manifest permissions

<uses-permission android:name="android.permission.ACCESS_CACHE_FILESYSTEM"/> <uses-permission android:name="android.permission.ACCESS_CHECKIN_PROPERTIES"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_CONTENT_PROVIDERS_EXTERNALLY"/> <uses-permission android:name="android.permission.ACCESS_DRM_CERTIFICATES"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FM_RADIO"/> <uses-permission android:name="android.permission.ACCESS_IMS_CALL_SERVICE"/> <uses-permission android:name="android.permission.ACCESS_INPUT_FLINGER"/> <uses-permission android:name="android.permission.ACCESS_KEYGUARD_SECURE_STORAGE"/> <uses-permission android:name="an...