• Latest
  • Trending
Get Started with Face Detection with Python

Get Started with Face Detection with Python

May 3, 2022
ATC Ghana supports Girls-In-ICT Program

ATC Ghana supports Girls-In-ICT Program

April 25, 2023
Vice President Dr. Bawumia inaugurates  ICT Hub

Vice President Dr. Bawumia inaugurates ICT Hub

April 2, 2023
Co-Creation Hub’s edtech accelerator puts $15M towards African startups

Co-Creation Hub’s edtech accelerator puts $15M towards African startups

February 20, 2023
Data Leak Hits Thousands of NHS Workers

Data Leak Hits Thousands of NHS Workers

February 20, 2023
EU Cybersecurity Agency Warns Against Chinese APTs

EU Cybersecurity Agency Warns Against Chinese APTs

February 20, 2023
How Your Storage System Will Still Be Viable in 5 Years’ Time?

How Your Storage System Will Still Be Viable in 5 Years’ Time?

February 20, 2023
The Broken Promises From Cybersecurity Vendors

Cloud Infrastructure Used By WIP26 For Espionage Attacks on Telcos

February 20, 2023
Instagram and Facebook to get paid-for verification

Instagram and Facebook to get paid-for verification

February 20, 2023
YouTube CEO Susan Wojcicki steps down after nine years

YouTube CEO Susan Wojcicki steps down after nine years

February 20, 2023
Inaugural AfCFTA Conference on Women and Youth in Trade

Inaugural AfCFTA Conference on Women and Youth in Trade

September 6, 2022
Instagram fined €405m over children’s data privacy

Instagram fined €405m over children’s data privacy

September 6, 2022
8 Most Common Causes of a Data Breach

5.7bn data entries found exposed on Chinese VPN

August 18, 2022
  • Consumer Watch
  • Kids Page
  • Directory
  • Events
  • Reviews
Friday, 11 July, 2025
  • Login
itechnewsonline.com
  • Home
  • Tech
  • Africa Tech
  • InfoSEC
  • Data Science
  • Data Storage
  • Business
  • Opinion
Subscription
Advertise
No Result
View All Result
itechnewsonline.com
No Result
View All Result

Get Started with Face Detection with Python

by ITECHNEWS
May 3, 2022
in Data Science, Leading Stories
0 0
0
Get Started with Face Detection with Python

NOTE: Used a pre-trained model
Face detection in photos can be performed using the classical feature-based cascade classifier using the OpenCV library (cv2).

Used packages

YOU MAY ALSO LIKE

ATC Ghana supports Girls-In-ICT Program

Vice President Dr. Bawumia inaugurates ICT Hub

import cv2
import time
import os

OpenCV provides the CascadeClassifier class that creates a cascade classifier for face detection. The constructor can take a filename as an argument that specifies the XML file for a pre-trained model.

Download a pre-trained model (file here) for frontal face detection from the OpenCV GitHub project – to be placed in your working directory.

Setup the image directory

# function to get images from folder 
def get_images(dir_name):
    list_images = os.listdir(dir_name)
    all_images =list()

    for entry in list_images:
        full_path =os.path.join(dir_name, entry)
        if os.path.isdir(full_path):
            all_images.all_images + get_images(full_path)
        else: all_images.append(full_path)
    return all_images

Load the model that will perform face detection on photographs by calling the detectMultiScale() function.

# Face Detection

def  main():
    dir_name = 'images' # directory for images
    list_images = get_images(dir_name)

    for i in range(20): #20 images
        image_path = list_images[i]

        print(image_path)

        # load the pre-trained model
        case_path = "haarcascade_frontalface_default.xml" # define the model used for recognition detection
        faceCascade= cv2.CascadeClassifier(case_path)
        image=cv2.imread(image_path)
        gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) # make the picture to gray from color

        # face detection 
        faces = faceCascade.detectMultiScale(gray,
                                            scaleFactor = 1.1,
                                            minNeighbors=5,
                                            minSize = (30, 30))

        for (x, y, w, h) in faces: # draw rectangles on the faces when detected
            cv2.rectangle(image, (x,y), (x + w, y+h), (0, 255, 0), 2)

        #Load the detected faces
        cv2.imshow("Face Found", image)
        cv2.waitKey(5)
        time.sleep(5)
        cv2.destroyAllWindows()

if __name__ == '__main__':
    main()

Running the model loads the images and configures the cascade classifier; faces are detected, and each bounding box gets printed.

The model only works for faces directly at the camera (in front).

Face detection 1

Face detection 2

Source: Ochwada Linda
Via: dev.to
ShareTweetShare
Plugin Install : Subscribe Push Notification need OneSignal plugin to be installed.

Search

No Result
View All Result

Recent News

ATC Ghana supports Girls-In-ICT Program

ATC Ghana supports Girls-In-ICT Program

April 25, 2023
Vice President Dr. Bawumia inaugurates  ICT Hub

Vice President Dr. Bawumia inaugurates ICT Hub

April 2, 2023
Co-Creation Hub’s edtech accelerator puts $15M towards African startups

Co-Creation Hub’s edtech accelerator puts $15M towards African startups

February 20, 2023

About What We Do

itechnewsonline.com

We bring you the best Premium Tech News.

Recent News With Image

ATC Ghana supports Girls-In-ICT Program

ATC Ghana supports Girls-In-ICT Program

April 25, 2023
Vice President Dr. Bawumia inaugurates  ICT Hub

Vice President Dr. Bawumia inaugurates ICT Hub

April 2, 2023

Recent News

  • ATC Ghana supports Girls-In-ICT Program April 25, 2023
  • Vice President Dr. Bawumia inaugurates ICT Hub April 2, 2023
  • Co-Creation Hub’s edtech accelerator puts $15M towards African startups February 20, 2023
  • Data Leak Hits Thousands of NHS Workers February 20, 2023
  • Home
  • InfoSec
  • Opinion
  • Africa Tech
  • Data Storage

© 2021-2022 iTechNewsOnline.Com - Powered by BackUPDataSystems

No Result
View All Result
  • Home
  • Tech
  • Africa Tech
  • InfoSEC
  • Data Science
  • Data Storage
  • Business
  • Opinion

© 2021-2022 iTechNewsOnline.Com - Powered by BackUPDataSystems

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Go to mobile version