INTRODUCTION
OpenCV has functionalities for running deep learning models as inference. This module lets you use pre-trained neural networks from popular frameworks like TensorFlow, PyTorch, Caffe, etc,and use those models directly in OpenCV, which we can carry out several deep learning functionalities.
Deep neural networks (DNNs) are the neural networks that have a large number of layers. There is no specific number of layers used to classify a deep neural network, but general consensus appears to be that they are neural networks with more than three hidden layers.
WATCH ON YOUTUBE 😃👇
Complete Age Gender Detection Project Using DNN & OPENCV 2024
SOURCE CODE
#import packages
import cv2
import math
import argparse
def highlightFace(net, frame, conf_threshold=0.7):
frameOpencvDnn = frame.copy()
frameHeight = frameOpencvDnn.shape[0]
frameWidth = frameOpencvDnn.shape[1]
blob = cv2.dnn.blobFromImage(frameOpencvDnn, 1.0, (300, 300), [104, 117, 123], True, False)
net.setInput(blob)
detections = net.forward()
faceBoxes = []
for i in range(detections.shape[2]):
confidence = detections[0, 0, i, 2]
if confidence > conf_threshold:
x1 = int(detections[0, 0, i, 3] * frameWidth)
y1 = int(detections[0, 0, i, 4] * frameHeight)
x2 = int(detections[0, 0, i, 5] * frameWidth)
y2 = int(detections[0, 0, i, 6] * frameHeight)
faceBoxes.append([x1, y1, x2, y2])
cv2.rectangle(frameOpencvDnn, (x1, y1), (x2, y2), (0, 255, 0), int(round(frameHeight / 150)), 8)
return frameOpencvDnn, faceBoxes
parser = argparse.ArgumentParser()
parser.add_argument('--image')
args = parser.parse_args()
faceProto = "opencv_face_detector.pbtxt"
faceModel = "opencv_face_detector_uint8.pb"
ageProto = "age_deploy.prototxt"
ageModel = "age_net.caffemodel"
genderProto = "gender_deploy.prototxt"
genderModel = "gender_net.caffemodel"
MODEL_MEAN_VALUES = (78.4263377603, 87.7689143744, 114.895847746)
ageList = ['(45)', '(50)', '(35)', '(54)', '(45)', '(38)', '(48)', '(60-100)']
genderList = ['Male', 'Female']
faceNet = cv2.dnn.readNet(faceModel, faceProto)
ageNet = cv2.dnn.readNet(ageModel, ageProto)
genderNet = cv2.dnn.readNet(genderModel, genderProto)
video = cv2.VideoCapture(args.image if args.image else 0)
padding = 20
while cv2.waitKey(1) < 0:
hasFrame, frame = video.read()
if not hasFrame:
cv2.waitKey()
break.............
............
FULL SOURCE CODE AND RESOURCES 😃👇
FOLLOW US :
1.FREETECH YOUTUBE CHANNEL →
https://www.youtube.com/@FREETECH-xu1ob
2. ALL PRODUCTS →
https://linktr.ee/rockstararun
3. ALL COURSES →
https://linktr.ee/Freetech2024
GAMING LAPTOP 😊🔥:
K7 ANTIVIRUS 😃👇
CONTACT ME AT FIVERR 😃👇
PRODUCTS:
THANKS FOR READING 😁😁
No comments:
Post a Comment