<jupyter_start><jupyter_text>Face Detection Test`OpenCV`로 Face Detection 테스트한 기록입니다. References* [opencv install](https://pypi.org/project/opencv-python/)* [FACE DETECTION USING OPENCV AND PYTHON: A BEGINNER’S GUIDE](https://www.superdatascience.com/opencv-face-detection/)* [How to Display a Matplotlib RGB Image](https://www.pyimagesearch.com/2014/11/03/display-matplotlib-rgb-image/) Source of Data* [네이버 영화: 다크나이트](https://movie.naver.com/movie/bi/mi/photoView.nhn?code=62586)* [OpenCV xml data](https://github.com/informramiz/Face-Detection-OpenCV)<jupyter_code>import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread("./joker.jpg")
plt.imshow(img)
type(img)
img.shape
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.imshow(img)
#load cascade classifier training file for haarcascade 
haar_face_cascade = cv2.CascadeClassifier('./haarcascade_frontalface_alt.xml')
def detect_faces(f_cascade, colored_img, scaleFactor = 1.1):
    #just making a copy of image passed, so that passed image is not changed 
    img_copy = colored_img.copy()          

    #convert the test image to gray image as opencv face detector expects gray images
    gray = cv2.cvtColor(img_copy, cv2.COLOR_RGB2GRAY)          

    #let's detect multiscale (some images may be closer to camera than others) images
    faces = f_cascade.detectMultiScale(gray, scaleFactor=scaleFactor, minNeighbors=5);          

    #go over list of faces and draw them as rectangles on original colored img
    for (x, y, w, h) in faces:
        print(x, y, w, h)
        cv2.rectangle(img_copy, (x, y), (x+w, y+h), (0, 255, 0), 2)              

    return img_copy
img_face = detect_faces(haar_face_cascade, img)
plt.imshow(img_face)<jupyter_output>113 61 77 77
{'fraction_non_alphanumeric': 0.11174785100286533, 'fraction_numerical': 0.02349570200573066, 'mean_word_length': 4.2119402985074625, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 5, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '623650', 'license': 'MIT', 'n_tokens_mistral': 664, 'n_tokens_neox': 632, 'n_words': 160, 'path': 'test/face_detection_and_cropped/face_detection_test.ipynb', 'repo_name': 'minkukjo/TiredFace-Server', 'size': '1745'}