0% found this document useful (0 votes)
14 views1 page

New Text Document

The document shows code for importing OpenCV and reading an image. It converts the image to grayscale and loads a classifier to detect faces. It applies the classifier to the grayscale image and draws rectangles around any detected faces.

Uploaded by

vo truong son
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views1 page

New Text Document

The document shows code for importing OpenCV and reading an image. It converts the image to grayscale and loads a classifier to detect faces. It applies the classifier to the grayscale image and draws rectangles around any detected faces.

Uploaded by

vo truong son
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

# Importing OpenCV package

import cv2
import numpy
# Reading the image
img = cv2.imread('japan.jpg')
# Converting image to grayscale
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Loading the required haar-cascade xml classifier file
haar_cascade = cv2.CascadeClassifier('Haarcascade_frontalface_default.xml')
# Applying the face detection method on the grayscale image
faces_rect = haar_cascade.detectMultiScale(gray_img, 1.1, 9)
# Iterating through rectangles of detected faces
for (x, y, w, h) in faces_rect:
cv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 2)
cv2.imshow('Detected faces', img)
cv2.waitKey(0)
==========================
import cv2
import numpy
# Reading the image
img= cv2.imread('japan.jpg')
#Coverting image to grayscale
gray_ing = cv2.cvtColor(img,cv2.CORLOR_BGR2GRAY)
#loading the required haar - cascade xml classifier

You might also like