- Detects the pupil of an eye based on largest contour technique.
- Each frame/image is processed in grayscale format and then converted to binary image.
- Detects the maximum contour (i.e the pupil area) and creates a circle bounding box around it.
- OpenCV v3.4
- Numpy v1.15
- os
- shutil
- Loop through all the images from the input folder
- Convert the images from BGR colorspace to grayscale
- Use
cv2.GaussianBlur
with kernel size (9, 9) to remove noise to an extent - Use
cv2.medianBlur
to reduce the noise further - Threshold the image to get the contours
- Use
cv2.findContours
to find all the contours visible after thresholding and select the largest contour out of them only, as it is the pupil. - Get the
x
,y
,w
,h
from thecv2.boundingRect
. - Draw a circle using
cv2.circle
- Save the results in the output folder
- Capture the video file using
cv2.VideoCapture
- Loop the video continuously and save the frames of the video using
read()
- Get the exact area of the eye (ROI) from the whole frame.
- Convert the ROI region into Grayscale then use GaussianBlur as well as medianBlur to reduce the noise.
- Threshold the ROI region to get the contours and select only the largest contour as it will be pupil.
- Once, contour is detected using
cv2.findContours
, get thex
,y
,w
,h
from thecv2.boundingRect
- Draw a circle using
cv2.circle
NOTE
: use cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
to loop back the video from beginning otherwise, it will throw error as there is no frame to capture.
NOTE
: At the end release()
the video file.