SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
Python programming with Open CV Page 1
" PYTHON OPEnCV real time
Projects "
Prepared by:
AMARjeetsingh thakur
Python programming with Open CV Page 2
1.The Face & Eyes Detection
Step1: Open The Pycharm IDE
Python programming with Open CV Page 3
Step2: Source Code
import numpy as np
import cv2 #Import Open Source Computer Vision Package
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
cap = cv2.VideoCapture(0) #Capture video from front camera of our laptop
while 1:
ret, img = cap.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #By default in CV the image is read in BGR format
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2) #Rectangular box size initialization
roi_gray = gray[y:y + h, x:x + w]
roi_color = img[y:y + h, x:x + w]
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('img', img)
k = cv2.waitKey(30) & 0xff # cv2.waitKey() will show the image for assigned time duration
if k == 27: #If user presses Esc Key then video capturing will be terminated
break
cap.release() #Its mandatory to release video capture
cv2.destroyAllWindows()#Once the task completes then we will close all the opened windows
Step3: Run the code
Result:
1. Showing my face and eyes detected and enclosed in a box
Python programming with Open CV Page 4
2. Showing face and eyes of mine and the person in my cell
phone and also in photo detected and enclosed in a box
Python programming with Open CV Page 5
2. Nose Detection of Human
Source Code:
import cv2
import numpy as np
nose_cascade = cv2.CascadeClassifier('haarcascade_mcs_nose.xml')
cap = cv2.VideoCapture(0)
ds_factor = 0.5
while True:
ret, frame = cap.read()
frame = cv2.resize(frame, None, fx=ds_factor, fy=ds_factor, interpolation=cv2.INTER_AREA)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
nose_rects = nose_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in nose_rects:
cv2.rectangle(frame, (x,y), (x+w,y+h), (0,255,0), 3)
break
cv2.imshow('Nose Detected', frame)
c = cv2.waitKey(1)
if c == 27:
break
cap.release()
cv2.destroyAllWindows()
Result: Nose being detected
Python programming with Open CV Page 6
3. Mouth Detection of Human
Source Code:
import cv2
import numpy as np
mouth_cascade = cv2.CascadeClassifier('haarcascade_mcs_mouth.xml')
cap = cv2.VideoCapture(0)
ds_factor = 0.5
while True:
ret, frame = cap.read()
frame = cv2.resize(frame, None, fx=ds_factor, fy=ds_factor, interpolation=cv2.INTER_AREA)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
mouth_rects = mouth_cascade.detectMultiScale(gray, 1.7, 11)
for (x,y,w,h) in mouth_rects:
y = int(y - 0.15*h)
cv2.rectangle(frame, (x,y), (x+w,y+h), (0,255,0), 3)
break
cv2.imshow('Mouth Detected', frame)
c = cv2.waitKey(1)
if c == 27:
break
cap.release()
cv2.destroyAllWindows()
Result: Mouth being detected
Python programming with Open CV Page 7
For more information contact:
amarjeetsinght@gmail.com
linkedin.com/in/amarjeetsingh-thakur-54915955
Mob: +91-9035508516

More Related Content

What's hot (20)

PPT
comp1
franzneri
 
PPT
Lecture 3 c++
emailharmeet
 
PPTX
comp2
franzneri
 
PDF
Project_Euler_No_104_Pandigital_Fibonacci_ends
? ?
 
PDF
1 borland c++ 5.02 by aramse
Aram SE
 
PDF
Python openCV codes
Amarjeetsingh Thakur
 
PPT
Lab 1
emailharmeet
 
PDF
Dsa lab manual version 2
Dwight Sabio
 
PDF
C++ How I learned to stop worrying and love metaprogramming
cppfrug
 
PPT
Code readability in r
hzhbcl
 
DOCX
Code for program to draw a circle using mid point circle algorithm in c
Ossa2015
 
PDF
11 1 포인터
Changwon National University
 
DOCX
Assignment#1
NA000000
 
DOCX
Dam31303 dti2143 lab sheet 7
alish sha
 
DOC
Labsheet 5
rohassanie
 
DOCX
C++ assignment
Zohaib Ahmed
 
PPTX
MFC Cosinus
Razvan Raducanu, PhD
 
DOCX
เฉลยแบบฝึกหัดบทที่ 1
โทโม๊ะจัง นานะ
 
PPTX
Arithmetic operators
Sumayyiah .
 
PPTX
Open gl polygon code review
SANURI KARUNARATHNA
 
comp1
franzneri
 
Lecture 3 c++
emailharmeet
 
comp2
franzneri
 
Project_Euler_No_104_Pandigital_Fibonacci_ends
? ?
 
1 borland c++ 5.02 by aramse
Aram SE
 
Python openCV codes
Amarjeetsingh Thakur
 
Dsa lab manual version 2
Dwight Sabio
 
C++ How I learned to stop worrying and love metaprogramming
cppfrug
 
Code readability in r
hzhbcl
 
Code for program to draw a circle using mid point circle algorithm in c
Ossa2015
 
Assignment#1
NA000000
 
Dam31303 dti2143 lab sheet 7
alish sha
 
Labsheet 5
rohassanie
 
C++ assignment
Zohaib Ahmed
 
เฉลยแบบฝึกหัดบทที่ 1
โทโม๊ะจัง นานะ
 
Arithmetic operators
Sumayyiah .
 
Open gl polygon code review
SANURI KARUNARATHNA
 

Similar to Python OpenCV Real Time projects (20)

PPTX
Creating a brain to outsmart a baby
Marianne Schimmel
 
PPTX
Python Open CV
Tarun Bamba
 
PDF
OpenCV Introduction
Zachary Blair
 
PDF
Introduction to Computer Vision using OpenCV
Dylan Seychell
 
PPTX
OpenCV with Python
fsxflyer789Productio
 
PDF
You are task to add a yawning detection to the programme below;i.pdf
sales223546
 
PPTX
502021435-12345678Minor-Project-Ppt.pptx
shrey4922
 
PPTX
Python Project.pptx
TimePass720676
 
PDF
Computer vision and face recognition using python
Ratnakar Pandey
 
PPTX
PYTHON-OOOOOOOOOOPPPPPPEEEEEEEEN-CV.pptx
CharimaineMarquez2
 
PPTX
29-kashyap-mask-detaction.pptx
KASHYAPPATHAK7
 
PPTX
PYTHON-OPEEEEEEEEEEEEEEN-CV (1) kgjkg.pptx
CharimaineMarquez2
 
PPTX
ppt 20BET1024.pptx
ManeetBali
 
PPTX
Open Computer Vision Based Image Processing
NEEVEE Technologies
 
PPTX
Open CV library In Python_Vahid ebrahimian.pptx
vahid67ebrahimian
 
PPTX
Face recognition system
ShitanshuRanjanSriva2
 
PDF
CE344L-200365-Lab5.pdf
UmarMustafa13
 
PDF
IRJET- Number Plate Recognition by using Open CV- Python
IRJET Journal
 
PPTX
introduction to computer vision part00-1
AhMeDRaGaB946680
 
PPTX
Introduction_____to______ OpenCV___.pptx
jintojosephjo
 
Creating a brain to outsmart a baby
Marianne Schimmel
 
Python Open CV
Tarun Bamba
 
OpenCV Introduction
Zachary Blair
 
Introduction to Computer Vision using OpenCV
Dylan Seychell
 
OpenCV with Python
fsxflyer789Productio
 
You are task to add a yawning detection to the programme below;i.pdf
sales223546
 
502021435-12345678Minor-Project-Ppt.pptx
shrey4922
 
Python Project.pptx
TimePass720676
 
Computer vision and face recognition using python
Ratnakar Pandey
 
PYTHON-OOOOOOOOOOPPPPPPEEEEEEEEN-CV.pptx
CharimaineMarquez2
 
29-kashyap-mask-detaction.pptx
KASHYAPPATHAK7
 
PYTHON-OPEEEEEEEEEEEEEEN-CV (1) kgjkg.pptx
CharimaineMarquez2
 
ppt 20BET1024.pptx
ManeetBali
 
Open Computer Vision Based Image Processing
NEEVEE Technologies
 
Open CV library In Python_Vahid ebrahimian.pptx
vahid67ebrahimian
 
Face recognition system
ShitanshuRanjanSriva2
 
CE344L-200365-Lab5.pdf
UmarMustafa13
 
IRJET- Number Plate Recognition by using Open CV- Python
IRJET Journal
 
introduction to computer vision part00-1
AhMeDRaGaB946680
 
Introduction_____to______ OpenCV___.pptx
jintojosephjo
 
Ad

More from Amarjeetsingh Thakur (20)

PPTX
“Introduction to MATLAB & SIMULINK”
Amarjeetsingh Thakur
 
PDF
Python code for servo control using Raspberry Pi
Amarjeetsingh Thakur
 
PDF
Python code for Push button using Raspberry Pi
Amarjeetsingh Thakur
 
PDF
Python code for Buzzer Control using Raspberry Pi
Amarjeetsingh Thakur
 
PDF
Arduino programming part 2
Amarjeetsingh Thakur
 
PDF
Arduino programming part1
Amarjeetsingh Thakur
 
PDF
Python Numpy Source Codes
Amarjeetsingh Thakur
 
PDF
Steemit html blog
Amarjeetsingh Thakur
 
PPTX
Adafruit_IoT_Platform
Amarjeetsingh Thakur
 
PDF
Core python programming tutorial
Amarjeetsingh Thakur
 
PDF
Python openpyxl
Amarjeetsingh Thakur
 
PPTX
Introduction to Internet of Things (IoT)
Amarjeetsingh Thakur
 
PPTX
Introduction to Node MCU
Amarjeetsingh Thakur
 
PPTX
Introduction to Things board (An Open Source IoT Cloud Platform)
Amarjeetsingh Thakur
 
PPTX
Introduction to MQ Telemetry Transport (MQTT)
Amarjeetsingh Thakur
 
PPTX
Arduino Interfacing with different sensors and motor
Amarjeetsingh Thakur
 
PPTX
Image processing in MATLAB
Amarjeetsingh Thakur
 
PPTX
Introduction to Arduino
Amarjeetsingh Thakur
 
PPTX
Introduction to Arduino
Amarjeetsingh Thakur
 
PPTX
Image Processing Using MATLAB
Amarjeetsingh Thakur
 
“Introduction to MATLAB & SIMULINK”
Amarjeetsingh Thakur
 
Python code for servo control using Raspberry Pi
Amarjeetsingh Thakur
 
Python code for Push button using Raspberry Pi
Amarjeetsingh Thakur
 
Python code for Buzzer Control using Raspberry Pi
Amarjeetsingh Thakur
 
Arduino programming part 2
Amarjeetsingh Thakur
 
Arduino programming part1
Amarjeetsingh Thakur
 
Python Numpy Source Codes
Amarjeetsingh Thakur
 
Steemit html blog
Amarjeetsingh Thakur
 
Adafruit_IoT_Platform
Amarjeetsingh Thakur
 
Core python programming tutorial
Amarjeetsingh Thakur
 
Python openpyxl
Amarjeetsingh Thakur
 
Introduction to Internet of Things (IoT)
Amarjeetsingh Thakur
 
Introduction to Node MCU
Amarjeetsingh Thakur
 
Introduction to Things board (An Open Source IoT Cloud Platform)
Amarjeetsingh Thakur
 
Introduction to MQ Telemetry Transport (MQTT)
Amarjeetsingh Thakur
 
Arduino Interfacing with different sensors and motor
Amarjeetsingh Thakur
 
Image processing in MATLAB
Amarjeetsingh Thakur
 
Introduction to Arduino
Amarjeetsingh Thakur
 
Introduction to Arduino
Amarjeetsingh Thakur
 
Image Processing Using MATLAB
Amarjeetsingh Thakur
 
Ad

Recently uploaded (20)

PPTX
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
PDF
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
PPTX
MODULE 05 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PPTX
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
PDF
Digital water marking system project report
Kamal Acharya
 
PDF
Electrical Engineer operation Supervisor
ssaruntatapower143
 
PPTX
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
PPTX
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
PDF
Bachelor of information technology syll
SudarsanAssistantPro
 
PPTX
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
PDF
20ES1152 Programming for Problem Solving Lab Manual VRSEC.pdf
Ashutosh Satapathy
 
PDF
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
PPTX
Distribution reservoir and service storage pptx
dhanashree78
 
PPTX
MODULE 04 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PPTX
Alan Turing - life and importance for all of us now
Pedro Concejero
 
PDF
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
PPTX
仿制LethbridgeOffer加拿大莱斯桥大学毕业证范本,Lethbridge成绩单
Taqyea
 
PPTX
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
PDF
NTPC PATRATU Summer internship report.pdf
hemant03701
 
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
MODULE 05 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
Digital water marking system project report
Kamal Acharya
 
Electrical Engineer operation Supervisor
ssaruntatapower143
 
2025 CGI Congres - Surviving agile v05.pptx
Derk-Jan de Grood
 
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
Bachelor of information technology syll
SudarsanAssistantPro
 
Water Resources Engineering (CVE 728)--Slide 4.pptx
mohammedado3
 
20ES1152 Programming for Problem Solving Lab Manual VRSEC.pdf
Ashutosh Satapathy
 
AI TECHNIQUES FOR IDENTIFYING ALTERATIONS IN THE HUMAN GUT MICROBIOME IN MULT...
vidyalalltv1
 
Distribution reservoir and service storage pptx
dhanashree78
 
MODULE 04 - CLOUD COMPUTING AND SECURITY.pptx
Alvas Institute of Engineering and technology, Moodabidri
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
Alan Turing - life and importance for all of us now
Pedro Concejero
 
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
仿制LethbridgeOffer加拿大莱斯桥大学毕业证范本,Lethbridge成绩单
Taqyea
 
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
NTPC PATRATU Summer internship report.pdf
hemant03701
 

Python OpenCV Real Time projects

  • 1. Python programming with Open CV Page 1 " PYTHON OPEnCV real time Projects " Prepared by: AMARjeetsingh thakur
  • 2. Python programming with Open CV Page 2 1.The Face & Eyes Detection Step1: Open The Pycharm IDE
  • 3. Python programming with Open CV Page 3 Step2: Source Code import numpy as np import cv2 #Import Open Source Computer Vision Package face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml') cap = cv2.VideoCapture(0) #Capture video from front camera of our laptop while 1: ret, img = cap.read() gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #By default in CV the image is read in BGR format faces = face_cascade.detectMultiScale(gray, 1.3, 5) for (x, y, w, h) in faces: cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2) #Rectangular box size initialization roi_gray = gray[y:y + h, x:x + w] roi_color = img[y:y + h, x:x + w] 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('img', img) k = cv2.waitKey(30) & 0xff # cv2.waitKey() will show the image for assigned time duration if k == 27: #If user presses Esc Key then video capturing will be terminated break cap.release() #Its mandatory to release video capture cv2.destroyAllWindows()#Once the task completes then we will close all the opened windows Step3: Run the code Result: 1. Showing my face and eyes detected and enclosed in a box
  • 4. Python programming with Open CV Page 4 2. Showing face and eyes of mine and the person in my cell phone and also in photo detected and enclosed in a box
  • 5. Python programming with Open CV Page 5 2. Nose Detection of Human Source Code: import cv2 import numpy as np nose_cascade = cv2.CascadeClassifier('haarcascade_mcs_nose.xml') cap = cv2.VideoCapture(0) ds_factor = 0.5 while True: ret, frame = cap.read() frame = cv2.resize(frame, None, fx=ds_factor, fy=ds_factor, interpolation=cv2.INTER_AREA) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) nose_rects = nose_cascade.detectMultiScale(gray, 1.3, 5) for (x,y,w,h) in nose_rects: cv2.rectangle(frame, (x,y), (x+w,y+h), (0,255,0), 3) break cv2.imshow('Nose Detected', frame) c = cv2.waitKey(1) if c == 27: break cap.release() cv2.destroyAllWindows() Result: Nose being detected
  • 6. Python programming with Open CV Page 6 3. Mouth Detection of Human Source Code: import cv2 import numpy as np mouth_cascade = cv2.CascadeClassifier('haarcascade_mcs_mouth.xml') cap = cv2.VideoCapture(0) ds_factor = 0.5 while True: ret, frame = cap.read() frame = cv2.resize(frame, None, fx=ds_factor, fy=ds_factor, interpolation=cv2.INTER_AREA) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) mouth_rects = mouth_cascade.detectMultiScale(gray, 1.7, 11) for (x,y,w,h) in mouth_rects: y = int(y - 0.15*h) cv2.rectangle(frame, (x,y), (x+w,y+h), (0,255,0), 3) break cv2.imshow('Mouth Detected', frame) c = cv2.waitKey(1) if c == 27: break cap.release() cv2.destroyAllWindows() Result: Mouth being detected
  • 7. Python programming with Open CV Page 7 For more information contact: [email protected] linkedin.com/in/amarjeetsingh-thakur-54915955 Mob: +91-9035508516