<jupyter_start><jupyter_text>EyeDetection using OpenCV This Code Template is for Eye Detection using OpenCV in Python.  **Required Packages**<jupyter_code>!pip install opencv-python
import os
import cv2
import numpy as np
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Initialization Path of the image to be loaded<jupyter_code>#image path variable
img_path = ''<jupyter_output><empty_output><jupyter_text>Path for classifier xml file<jupyter_code>filter_path = ''<jupyter_output><empty_output><jupyter_text>Image Fetching OpenCV-Python is a library of Python bindings designed to solve computer vision problems. We use the the "**cv2.imread()**" method to load an image from the specified file path.<jupyter_code>def plot_image(path):
    image = cv2.imread(path) 
    img = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    plt.figure(figsize=(12,12))
    plt.imshow(img) 
    plt.axis("off")
    plt.show()
plot_image(img_path)<jupyter_output><empty_output><jupyter_text>Haar-cascade Classifier Haar-cascade Classifier is a machine learning algorithm where we train a cascade function with tons of images. There are different types of cascade classifiers according to different target objects and here we will use a classifier that considers the image of an eye to recognize it as the target object. You can find the the trained classifier XML file for face detection [here](https://github.com/opencv/opencv/blob/master/data/haarcascades/haarcascade_eye.xml)<jupyter_code># load the haarcascade classifier xml file
eye_cascade = cv2.CascadeClassifier(filter_path)<jupyter_output><empty_output><jupyter_text>Eye Detection For detecting the eyes in the image, we use the detectMultiScale() function. It detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles which can be then plotted around the detected target objects. Tuning Parameters>**image** -	Matrix of the type CV_8U containing an image where objects are detected.>**objects** - Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image.>**scaleFactor** - Parameter specifying how much the image size is reduced at each image scale.>**minNeighbors** - Parameter specifying how many neighbors each candidate rectangle should have to retain it.For more details [click here](https://docs.opencv.org/3.4/d1/de5/classcv_1_1CascadeClassifier.htmlaaf8181cb63968136476ec4204ffca498)<jupyter_code>def eye_detect(path):    
    img = cv2.imread(path)
    eyes = eye_cascade.detectMultiScale(image = img, scaleFactor = 1.1, minNeighbors = 10)
    for (x, y, w, h) in eyes:
        cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)
    
    print(len(eyes),"Eyes detected!")

    finalimg = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
    plt.figure(figsize=(12,12))
    plt.imshow(finalimg) 
    plt.axis("off")
    plt.show()
eye_detect(img_path)<jupyter_output>2 Eyes detected!
{'fraction_non_alphanumeric': 0.08733624454148471, 'fraction_numerical': 0.020154517971111858, 'mean_word_length': 5.473913043478261, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 28, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '132133', 'license': 'Apache-2.0', 'n_tokens_mistral': 970, 'n_tokens_neox': 910, 'n_words': 302, 'path': 'Audio Visual/Problems/EyeDetection_OpenCV.ipynb', 'repo_name': 'shreepad-nade/ds-seed', 'size': '2977'}