A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_files_driver::open($save_path, $name) should either be compatible with SessionHandlerInterface::open(string $path, string $name): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_files_driver.php

Line Number: 132

Backtrace:

File: /home/infovistar/public_html/application/controllers/opencv/Opencv.php
Line: 7
Function: __construct

File: /home/infovistar/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_files_driver::close() should either be compatible with SessionHandlerInterface::close(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_files_driver.php

Line Number: 292

Backtrace:

File: /home/infovistar/public_html/application/controllers/opencv/Opencv.php
Line: 7
Function: __construct

File: /home/infovistar/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_files_driver::read($session_id) should either be compatible with SessionHandlerInterface::read(string $id): string|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_files_driver.php

Line Number: 166

Backtrace:

File: /home/infovistar/public_html/application/controllers/opencv/Opencv.php
Line: 7
Function: __construct

File: /home/infovistar/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_files_driver::write($session_id, $session_data) should either be compatible with SessionHandlerInterface::write(string $id, string $data): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_files_driver.php

Line Number: 235

Backtrace:

File: /home/infovistar/public_html/application/controllers/opencv/Opencv.php
Line: 7
Function: __construct

File: /home/infovistar/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_files_driver::destroy($session_id) should either be compatible with SessionHandlerInterface::destroy(string $id): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_files_driver.php

Line Number: 315

Backtrace:

File: /home/infovistar/public_html/application/controllers/opencv/Opencv.php
Line: 7
Function: __construct

File: /home/infovistar/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: 8192

Message: Return type of CI_Session_files_driver::gc($maxlifetime) should either be compatible with SessionHandlerInterface::gc(int $max_lifetime): int|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

Filename: drivers/Session_files_driver.php

Line Number: 356

Backtrace:

File: /home/infovistar/public_html/application/controllers/opencv/Opencv.php
Line: 7
Function: __construct

File: /home/infovistar/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Session ini settings cannot be changed after headers have already been sent

Filename: Session/Session.php

Line Number: 282

Backtrace:

File: /home/infovistar/public_html/application/controllers/opencv/Opencv.php
Line: 7
Function: __construct

File: /home/infovistar/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_set_cookie_params(): Session cookie parameters cannot be changed after headers have already been sent

Filename: Session/Session.php

Line Number: 294

Backtrace:

File: /home/infovistar/public_html/application/controllers/opencv/Opencv.php
Line: 7
Function: __construct

File: /home/infovistar/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Session ini settings cannot be changed after headers have already been sent

Filename: Session/Session.php

Line Number: 304

Backtrace:

File: /home/infovistar/public_html/application/controllers/opencv/Opencv.php
Line: 7
Function: __construct

File: /home/infovistar/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Session ini settings cannot be changed after headers have already been sent

Filename: Session/Session.php

Line Number: 314

Backtrace:

File: /home/infovistar/public_html/application/controllers/opencv/Opencv.php
Line: 7
Function: __construct

File: /home/infovistar/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Session ini settings cannot be changed after headers have already been sent

Filename: Session/Session.php

Line Number: 315

Backtrace:

File: /home/infovistar/public_html/application/controllers/opencv/Opencv.php
Line: 7
Function: __construct

File: /home/infovistar/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Session ini settings cannot be changed after headers have already been sent

Filename: Session/Session.php

Line Number: 316

Backtrace:

File: /home/infovistar/public_html/application/controllers/opencv/Opencv.php
Line: 7
Function: __construct

File: /home/infovistar/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Session ini settings cannot be changed after headers have already been sent

Filename: Session/Session.php

Line Number: 317

Backtrace:

File: /home/infovistar/public_html/application/controllers/opencv/Opencv.php
Line: 7
Function: __construct

File: /home/infovistar/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Session ini settings cannot be changed after headers have already been sent

Filename: Session/Session.php

Line Number: 375

Backtrace:

File: /home/infovistar/public_html/application/controllers/opencv/Opencv.php
Line: 7
Function: __construct

File: /home/infovistar/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_set_save_handler(): Session save handler cannot be changed after headers have already been sent

Filename: Session/Session.php

Line Number: 110

Backtrace:

File: /home/infovistar/public_html/application/controllers/opencv/Opencv.php
Line: 7
Function: __construct

File: /home/infovistar/public_html/index.php
Line: 315
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_start(): Session cannot be started after headers have already been sent

Filename: Session/Session.php

Line Number: 143

Backtrace:

File: /home/infovistar/public_html/application/controllers/opencv/Opencv.php
Line: 7
Function: __construct

File: /home/infovistar/public_html/index.php
Line: 315
Function: require_once

Face Detection using OpenCV Python
For any queries you can reach us at infovistarindia@gmail.com / WhatsApp us: +919158876092

Face Detection using OpenCV Python

Overview

In this tutorial, we will learn how to detect a face from a webcam using the Haar Cascades classifier. For the well-known tasks, the classifiers / detectors already exists, for example: detecting things like faces, cars, smiles, eyes and license plates.

Object Detection using Haar feature-based cascade classifiers is an effective object detection approach recommended by Paul Viola and Michael Jones in their paper, "Rapid Object Detection using a Boosted Cascade of Simple Features" in 2001.

Installing the modules

To install the OpenCV module and some other associated dependencies, we can use the pip command:

pip install opencv-python

Download the Haar Cascades

  1. Follow the URL:
    https://github.com/opencv/opencv/tree/master/data/haarcascades/
  2. Click on haarcascade_frontalface_default.xml
  3. Click on Raw and then press Ctrl + S. This will help you save the Haar Cascade file for eyes.

The Code

import cv2
import sys

cascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")

video_capture = cv2.VideoCapture(0)

while True:
    res, frame = video_capture.read()

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    faces = cascade.detectMultiScale(
        gray, 
        scaleFactor = 1.1,
        minNeighbors = 5,
        minSize = (30, 30),
        flags = cv2.CASCADE_SCALE_IMAGE
    )

    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (155, 155, 0), 2)

    cv2.imshow('Video', frame)

    if cv2.waitKey(0) & 0xFF == ord('q'):
        break

video_capture.release()
cv2.destroyAllWindows()

The Output

Face Detection using OpenCV Python