[PYTHON] Cascade classification machine [Note] [Opencv]

Overview

memorandum. There is no explanation for each argument.

Sample code

test.py


import cv2

cap = cv2.VideoCapture(0)
#Model file? Is in opencv's github repositories
cascade = cv2.CascadeClassifier("./data/haarcascades/haarcascade_frontalface_default.xml")


if (cap is not None):
    print('cap ok')
else:
    return -1

while(True):    
    _, frame = cap.read()#Get frame information from camera
    
    #Grayscale conversion
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    
    #Search for the face area.
    face = cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=3, minSize=(30, 30))        
    for (x, y, w, h) in face:#Draw the detected face area on the original screen as a square
        cv2.rectangle(frame, (x, y), (x + w, y+h), (0,0,200), 3)

    cv2.imshow("test", frame)#Screen display
    key = cv2.waitKey(10)#Accepts keyboard input. As some of you may know, imshow will not be possible without it.

    if key == ord('q'):#End processing end when q is pressed
        break
cap.release()#Return camera resources
cv2.destroyAllWindows() #Delete the screen displayed by imshow
print("finish")

Recommended Posts

Cascade classification machine [Note] [Opencv]
[Note] openCV + python
Machine learning classification
Machine learning / classification related techniques
Supervised machine learning (classification / regression)
Cascade classifier creation with opencv
Introduction to machine learning Note writing
Machine learning with python (1) Overall classification
Classification and regression in machine learning