added more cascades for better detection rates
This commit is contained in:
parent
b1eba5ea2d
commit
24c4c31656
7 changed files with 211385 additions and 0 deletions
99
NN_dataset_generator.py
Normal file
99
NN_dataset_generator.py
Normal file
|
@ -0,0 +1,99 @@
|
|||
import cv2
|
||||
import numpy as np
|
||||
|
||||
|
||||
multiplication_factor = 0.05
|
||||
|
||||
def get_adjustment_amount(imgSize, currentX, currentY, currentW, currentH):
|
||||
|
||||
current_top_left = [currentX, currentY]
|
||||
current_bottom_right = [currentX + currentW, currentY + currentH]
|
||||
|
||||
current_top_right = [currentX + currentW, currentY]
|
||||
|
||||
# find the difference between the left gap and the right gap, divide it by two, and multiply it by the speed scale
|
||||
horizontal_adjustment = multiplication_factor * (currentX - (imgSize[0] - current_top_right[0])) / 2
|
||||
vertical_adjustment = multiplication_factor * (currentY - (imgSize[0] - current_bottom_right[1])) / 2
|
||||
|
||||
return [horizontal_adjustment, vertical_adjustment]
|
||||
|
||||
cap = cv2.VideoCapture(0, cv2.IMREAD_GRAYSCALE) # instead of grayscale you can also use -1, 0, or 1.
|
||||
faceCascade = cv2.CascadeClassifier(r"./lbpcascade_frontalface.xml") # CHECK THIS FIRST TROUBLE SHOOTING
|
||||
faceCascade_default = cv2.CascadeClassifier(r"./haarcascade_frontalface_default.xml")
|
||||
faceCascade_alt = cv2.CascadeClassifier(r"./haarcascade_frontalface_alt.xml")
|
||||
faceCascade_alt2 = cv2.CascadeClassifier(r"./haarcascade_frontalface_alt2.xml")
|
||||
faceCascade_alttree = cv2.CascadeClassifier(r"./haarcascade_frontalface_alt_tree.xml")
|
||||
profileFaceCascade = cv2.CascadeClassifier(r"./haarcascade_profileface.xml")
|
||||
|
||||
|
||||
tmp, frm = cap.read()
|
||||
height, width, channels = frm.shape
|
||||
print(f"{height*.25}, {width}")
|
||||
del tmp, frm
|
||||
|
||||
#Color is 1, grayscale is 0, and the unchanged is -1
|
||||
while(True):
|
||||
ret, frame = cap.read()
|
||||
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
||||
|
||||
# Detect faces in the image
|
||||
faces = faceCascade.detectMultiScale(
|
||||
gray,
|
||||
scaleFactor=1.1,
|
||||
minNeighbors=5,
|
||||
minSize=(30, 30)
|
||||
)
|
||||
|
||||
if len(faces) == 0:
|
||||
faces = faceCascade_default.detectMultiScale(
|
||||
gray,
|
||||
scaleFactor=1.1,
|
||||
minNeighbors=5,
|
||||
minSize=(30,30)
|
||||
)
|
||||
|
||||
if len(faces) == 0:
|
||||
faces = profileFaceCascade.detectMultiScale(
|
||||
gray,
|
||||
scaleFactor=1.1,
|
||||
minNeighbors=5,
|
||||
minSize=(30,30)
|
||||
)
|
||||
|
||||
if len(faces) == 0:
|
||||
faces = faceCascade_alt.detectMultiScale(
|
||||
gray,
|
||||
scaleFactor=1.1,
|
||||
minNeighbors=5,
|
||||
minSize=(30,30)
|
||||
)
|
||||
|
||||
if len(faces) == 0:
|
||||
faces = faceCascade_alt2.detectMultiScale(
|
||||
gray,
|
||||
scaleFactor=1.1,
|
||||
minNeighbors=5,
|
||||
minSize=(30,30)
|
||||
)
|
||||
|
||||
if len(faces) == 0:
|
||||
faces = faceCascade_alttree.detectMultiScale(
|
||||
gray,
|
||||
scaleFactor=1.1,
|
||||
minNeighbors=5,
|
||||
minSize=(30,30)
|
||||
)
|
||||
|
||||
|
||||
# Draw a rectangle around the faces
|
||||
for (x, y, w, h) in faces:
|
||||
adjustment_required = get_adjustment_amount([width, height], x, y, w, h)
|
||||
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 255, 255))
|
||||
print(f"Adjust right: {adjustment_required[0]}")
|
||||
print(f"Adjust up : {adjustment_required[1]}")
|
||||
cv2.imshow('frame', frame)
|
||||
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
break
|
||||
|
||||
cap.release()
|
24350
haarcascade_frontalface_alt.xml
Normal file
24350
haarcascade_frontalface_alt.xml
Normal file
File diff suppressed because it is too large
Load diff
20719
haarcascade_frontalface_alt2.xml
Normal file
20719
haarcascade_frontalface_alt2.xml
Normal file
File diff suppressed because it is too large
Load diff
96484
haarcascade_frontalface_alt_tree.xml
Normal file
96484
haarcascade_frontalface_alt_tree.xml
Normal file
File diff suppressed because it is too large
Load diff
33314
haarcascade_frontalface_default.xml
Normal file
33314
haarcascade_frontalface_default.xml
Normal file
File diff suppressed because it is too large
Load diff
29690
haarcascade_profileface.xml
Normal file
29690
haarcascade_profileface.xml
Normal file
File diff suppressed because it is too large
Load diff
6729
haarcascade_smile.xml
Normal file
6729
haarcascade_smile.xml
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue