Congrats, you now know how to compute the gradient magnitude representation of an image (Laplacian and Sobel) followed by detecting actual edges in an image (the Canny edge detector).

Just like thresholding is a common method for segmenting foreground objects from background objects, the same can be said for edge detection — only instead of obtaining a large blob representing the foreground, the Canny detector gives us the outline.

Tuning canny edge detector parameters

In order to obtain an accurate edge map, you’ll need to tune the cv2.Canny  edge detection parameters, specifically the lower and upper thresholds by hand. If the image you are working with comes from semi-controlled lighting conditions, then you’ll likely be able to find a set of edge detection parameters that work well across the dataset.

However, for “natural” images with no restrictions on lighting conditions, it can become very challenging to define a set of parameters that obtains decent accuracy.

Because of this, you might want to try applying the automatic Canny edge detector:

auto_canny_dolphin

While this detector may not obtain the optimal results in every situation, it will guarantee that your edge maps are computed in a consistent manner (based on the defined heuristic) across the entire dataset.

Histogram of Oriented Gradients

Gradients also play a big role in object detection, especially when using the Histogram of Oriented Gradients and Linear SVM framework:

hog_object_detection_nms

It turns out we can actually utilize the gradient magnitude and orientation representation of an image to train a HOG + Linear SVM detector that detects various patterns in an image.

An example HOG pattern of a stop sign can be seen below:

object_detection_easy_stop_sign

Regions of images that have similar gradient patterns as the example above will be classified as “stop sign”.

To learn more about the HOG + Linear SVM object detection system, be sure to take a look at the PyImageSearch Gurus course:

https://www.pyimagesearch.com/pyimagesearch-gurus/

Lesson Content
0% Complete
0/18 Steps