Search This Blog

Showing posts with label facial recognition. Show all posts
Showing posts with label facial recognition. Show all posts

Monday, 18 November 2024

Augmented Reality and Computer Vision with OpenCV

Augmented Reality and Computer Vision with OpenCV



Introduction

Augmented reality (AR) is a technology that superimposes virtual content onto the real world. This can be used for a variety of applications, such as facial recognition, object mapping, and immersive experiences. Computer vision is a field of computer science that deals with the understanding of images and videos. OpenCV is a popular open-source library for computer vision. It provides a wide range of functions for image processing, feature extraction, and object recognition.

Uses of this Project

This project will teach you how to use OpenCV to build an augmented reality application. You will learn how to: * Load and display an image * Detect and track objects in the image * Superimpose virtual content onto the image This project can be used for a variety of applications, such as: * Creating a virtual try-on app * Developing a navigation app that overlays directions onto the real world * Building an interactive game that uses AR

Requirements

To complete this project, you will need: * A computer with a webcam * Python 3 * OpenCV

Step-by-Step to Build

1. Install OpenCV OpenCV can be installed using pip: 

pip install opencv-python

2. Import the necessary libraries 

python import cv2 import numpy as np 

3. Load and display an image

python image = cv2.imread('image.jpg') 

cv2.imshow('Image', image) 

cv2.waitKey(0) cv2.destroyAllWindows()

4. Detect and track objects in the image 

python detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') 

while True: 

ret, frame = camera.read() 

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

faces = detector.detectMultiScale(gray, 1.1, 4) 

for (x, y, w, h) in faces: 

cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2) 

cv2.imshow('Frame', frame) 

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

    break camera.release()

cv2.destroyAllWindows()


5. Superimpose virtual content onto the image 

overlay = cv2.imread('overlay.png', cv2.IMREAD_UNCHANGED) 

while True: ret, frame = camera.read() 

# Resize the overlay to fit the frame 

overlay_resized = cv2.resize(overlay, (frame.shape[1], frame.shape[0])) 

# Create a mask for the overlay 

mask = overlay_resized[:, :, 3] / 255.0 

# Create a masked image 

masked_image = frame * (1 - mask) + overlay_resized * mask 

cv2.imshow('Frame', masked_image) 

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

    break camera.release() 

cv2.destroyAllWindows()

Conclusion

In this project, you learned how to use OpenCV to build an augmented reality application. You learned how to load and display an image, detect and track objects in the image, and superimpose virtual content onto the image. This project can be used for a variety of applications, such as creating a virtual try-on app, developing a navigation app that overlays directions onto the real world, or building an interactive game that uses AR. ```

**Augmented Reality and Computer Vision with OpenCV** Augmented reality (AR) is a technology that superimposes virtual content onto the real world. This can be used for a variety of applications, such as facial recognition, object mapping, and immersive experiences. Computer vision is a field of computer science that deals with the understanding of images and videos. OpenCV is a popular open-source library for computer vision. It provides a wide range of functions for image processing, feature extraction, and object recognition. This project teaches you how to use OpenCV to build an augmented reality application. You will learn how to load and display an image, detect and track objects in the image, and superimpose virtual content onto the image. This project can be used for a variety of applications, such as: * Creating a virtual try-on app * Developing a navigation app that overlays directions onto the real world * Building an interactive game that uses AR **Requirements:** * A computer with a webcam * Python 3 * OpenCV **Difficulty:** Intermediate **Time to complete:** 2-3 hours

Friday, 19 November 2021

Object tracking with OpenCV Python

 Contents:

1) Introduction to the Project
2) Uses of Object Tracking
3) Tools and Softwares used
4) Python Program.

Introduction to the Project:

Object tracking is an application of deep learning where the program takes an initial set of object detections and develops a unique identification for each of the initial detections and then tracks the detected objects as they move around frames in a video.

In other words, object tracking is the task of automatically identifying objects in a video and interpreting them as a set of trajectories with high accuracy

Uses of Object Tracking:

Object tracking is used for a variety of use cases involving different types of input footage. Whether or not the anticipated input will be an image or a video, or a real-time video vs. a prerecorded video, impacts the algorithms used for creating object tracking applications.

The kind of input also impacts the category, use cases, and applications of object tracking. Here, we will briefly describe a few popular uses and types of object tracking, such as video tracking, visual tracking, and image tracking

Tools and Softwares needer:

1) Python 3.x

2) OpenCV-Python

Hardware requirements: Camera


MAIN PROGRAM:


import cv2
cam = cv2.VideoCapture(0)
track = cv2.TrackerCSRT_create()
suc,img=cam.read()
img = cv2.flip(img,1)
bbox = cv2.selectROI("Tracking",img,False)
track.init(img,bbox)

def drawbox(img):
x,y,w,h=int(bbox[0]),int(bbox[1]),int(bbox[2]),int(bbox[3])
cv2.rectangle(img,(x,y),(x+w,y+h),(0,0,255),2)

while 1:
suc,img = cam.read()
img = cv2.flip(img,1)
suc,bbox=track.update(img)
if suc:
drawbox(img)
else:
pass
cv2.imshow("Tracking",img)
if cv2.waitkey(1) & 0xff == ord('q'):
break


Tutorial:




Thursday, 18 November 2021

Mask Detection for COVID-19 disease

Contents:

1) Introduction of the Project
2) Functions and Module Used
3) Software requirements to run the Program
4) Main Program

1) Introduction of the Project

In today’s world, all the things have become
computerized.

As we all know, COVID-19 can spread when
People breathe, talk, cough or sneeze.
Wearing a mask keeps the virus from reaching
Others. It also can stop the virus from reaching
You.

So this program simply Detect all Faces
Camera, then detect Mask on their faces with
The help of Artificial Intelligence (A.1.)
Machine Learning (M.L.).

If someone found without Mask on his/her face
Then “Be Safe Mask not Found” text will be
printed on screen or Custom

required action can be taken by that
Organization who using this Program.

For example: If someone is without Mask then
By using SSH and Arduino this Program will
Close the door or whatever we will set.

2) Functions and Module used:

cv2.VideoCapture(0):

Cv2 is the module for real-time computer vision.
VideoCapture(0) used for capturing frames from
Camera on number (0).

cv2.CascadeClassifier(“Haarcascade.xml”):

This function reads the trained file for
Mask Detection. Haarcascade.xml is the file
contains all Coordinates codings of AI and ML for
Mask Points. We can train this our Own.

cv2.read():

This function reads the frames from Camera
Number (0) which we set above using VideoCapture

detectMultiScale():

This function detect Co-ordinates for Masks which
we trained from above function CascadeClassifer.

cv2.imshow():

This function Displays the Captured Frames which
We captured from cv2.read() function.

3) Software/Hardware Requirements to run the Program:

1) OpenCV-Python, This is Most Important because This is the main library we use in this program
2) Python 3.x, This is required because, I have tested on this only.
3) Pip3, This is required because packages we install will be installed by this program
4) Camera required, We can change this later by using real-time or from saved Image
5) Windows,Linux,Mac any OS support this because python is Cross-Platform
6) NumPy Library, We will not use this library but This will Installed with OpenCV-Python

Files for Downloading:

1) Haarcascade for Mask Trained by Me, Click Here
2) Haarcascade for Face come with OpenCV-Python by default. Click here for Download Manually

4) Main Program:

import cv2
import numpy as np
cam = cv2.VideoCapture(0)

obj = cv2.CascadeClassifier("myhaar.xml")
face = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")

while 1:
r,img = cam.read()
img = cv2.flip(img,3)
mask = obj.detectMultiScale(img,1.3,5)
faces = face.detectMultiScale(img,1.3,5)
for (x,y,w,h) in mask:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
cv2.putText(img,"Very Good! Keep it Up",(50,50),cv2.FONT_HERSHEY_SIMPLEX,1,(0,255,0),3,cv2.LINE_AA)
if len(mask) == 0:
print("Mask Not Found! Be Safe from CORONA.")
for (x1,y1,w1,h1) in faces:
cv2.rectangle(img,(x1,y1),(x1+w1,y1+h1),(0,0,255),2)
cv2.putText(img,"Be Safe! Mask Not Found.",(50,50),cv2.FONT_HERSHEY_SIMPLEX,1,(0,0,255),3,cv2.LINE_AA)
cv2.imshow("A",img)
if cv2.waitKey(1) == ord('q'):
break
cv2.destroyAllWindows()


Tutorial:






how to implement YOLOv3 using Python and TensorFlow

Object Detection with YOLOv3 Introduction YOLOv3 (You Only Look Once version 3) is a real-time object detection algorithm that can detect ob...