Practicing OpenCV, to avoid getting rusty, using the free-online course given by awsomeness Adrian, creator of the PyImageSearch platform.
Perform fast, accurate face detection with OpenCV using a pre-trained deep learning face detector model shipped with the library.
- Run it:
- For video:
python detect_faces_video.py -p deploy.prototxt.txt -m res10_300x300_ssd_iter_140000.caffemodel
- For images:
python face_detection_w_OpenCV.py -i sample_0.jpg -p deploy.prototxt.txt -m res10_300x300_ssd_iter_140000.caffemodel
- For video:
Learning OpenCV isn’t as hard as it used to be. And in fact, I’ll go as far as to say studying OpenCV has become significantly easier.
- Run it:
- Basic Image Manipulation:
python opencv_01.py -i jp.png
- Basic Color Image Manipulation:
python opencv_02.py -i tetris_blocks.png
- Basic Image Manipulation:
Building a document scanner with OpenCV can be accomplished in just three simple steps:
- Detect edges.
- Use the edges in the image to find the contour (outline) representing the piece of paper being scanned.
- Apply a perspective transform to obtain the top-down view of the document.
- Run it:
python scanner.py -i final-bill.jpg
Build a bubble sheet scanner and test grader using Python and OpenCV.
- Detect the exam in an image.
- Apply a perspective transform to extract the top-down, birds-eye-view of the exam.
- Extract the set of bubbles (i.e., the possible answer choices) from the perspective transformed exam.
- Sort the questions/bubbles into rows.
- Determine the marked (i.e., “bubbled in”) answer for each row.
- Determine if the mark was done once in the same question.
- Detemine if the answer was done.
- Lookup the correct answer in our answer key to determine if the user was correct in their choice.
- Repeat for all questions in the exam.
- Run it:
python test_grader.py -i omr_test_01.png
[Change the correct answers in the exam on Line 17, to see how it works.]
The goal here is:
- Detect the presence of a colored ball using computer vision techniques.
- Track the ball as it moves around in the video frames, drawing its previous positions as it moves.
- Run it:
python object_tracking.py
[Change color range on Lines 19 and 20, to see how it works.]
We need to determine our “pixels per metric” ratio, which describes the number of pixels that can “fit” into a given number of inches, millimeters, meters, etc.
To compute this ratio, we need a reference object with some properties:
Property #1: The reference object should have known dimensions (such as width or height) in terms of a measurable unit (inches, millimeters, etc.).
Property #2: The reference object should be easy to find, either in terms of location of the object or in its appearance.
Property #3: All of the objects to be measured be co-planar with the reference object.
- Run it:
python .\object_size.py -i .\example_03.png -w 3.5
Reducing the requirement of tracking pen speed and pressure:
- Eliminates the need for additional hardware when performing the test.
- Makes it far easier to automatically detect Parkinson’s.
- Run it:
python detect_parkinsons.py --dataset dataset/spiral
Facial landmarks are used to localize and represent salient regions of the face, such as:
- Eyes
- Eyebrows
- Nose
- Mouth
- Jawline
More info here
- Run it:
python facial_landmarks.py -p shape_predictor_68_face_landmarks.dat --image img_1.jpg
To build our blink detector, we’ll be computing a metric called the eye aspect ratio (EAR), introduced by Soukupová and Čech in their 2016 paper, Real-Time Eye Blink Detection Using Facial Landmarks.
The eye aspect ratio is approximately constant while the eye is open, but will rapidly fall to zero when a blink is taking place.
We can avoid image processing techniques and simply rely on the ratio of eye landmark distances to determine if a person is blinking.
- Run it:
python detect_blinks.py -p shape_predictor_68_face_landmarks.dat
The general flow of our drowsiness detection algorithm is fairly straightforward.
-
We'll setup a camera that monitors a stream for faces. If a face is found, we apply facial landmark detection and extract the eye regions.
-
Now that we have the eye regions, we compute the eye aspect ratio to determine if the eyes are closed.
-
If the aspect ratio indicates that the eyes have been closed for a sufficiently long enough amount of time, we'll sound an alarm to wake up the driver.
- Run it:
python detect_drowsiness.py -p shape_predictor_68_face_landmarks.dat
Writing some Python code to define our feedforward neural network and specifically apply it to the Kaggle Dogs vs. Cats classification challenge. The goal of this challenge is to correctly classify whether a given image contains a dog or a cat.
Classifying images using neural networks with Python and Keras
- Run it:
python simple_neural_network.py --dataset kaggle_dogs_vs_cats --model output/simple_neural_network.hdf5
Classifying images using our Keras model
- Run it:
python test_network.py --model output/simple_neural_network.hdf5 --test-images test_images