• Latest
  • Trending
Get Started with Face Detection with Python

Get Started with Face Detection with Python

May 3, 2022
Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025
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
  • Consumer Watch
  • Kids Page
  • Directory
  • Events
  • Reviews
Thursday, 16 July, 2026
  • 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

French Telco Orange Hit by Cyber-Attack

ATC Ghana supports Girls-In-ICT Program

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
ShareTweet

Get real time update about this post categories directly on your device, subscribe now.

Unsubscribe

Search

No Result
View All Result

Recent News

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025
ATC Ghana supports Girls-In-ICT Program

ATC Ghana supports Girls-In-ICT Program

April 25, 2023

About What We Do

itechnewsonline.com

We bring you the best Premium Tech News.

Recent News With Image

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025

Recent News

  • Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa July 29, 2025
  • French Telco Orange Hit by Cyber-Attack July 29, 2025
  • ATC Ghana supports Girls-In-ICT Program April 25, 2023
  • Vice President Dr. Bawumia inaugurates ICT Hub April 2, 2023
  • Home
  • InfoSec
  • Opinion
  • Africa Tech
  • Data Storage

© Copyright 2026, All Rights Reserved | 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

Add New Playlist

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

© Copyright 2026, All Rights Reserved | iTechNewsOnline.Com - Powered by BackUPDataSystems

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
Go to mobile version