## Revision f53f2f740c4c92c86b84005d339451a33c435c57 (click the page title to view the current version)

# Edge Detection

**Date** 13 or 14 October

**Briefing** Status on the Tracker Project.

If we need the Thursday session for this only, the Edge Detction will be postponed to the Friday.

**Briefing** Edge Lecture

**Reading** Ma (2004) Ch 4.4; Tutorials on OpenCV: Canny Edge Detection; Hough Circle Transform

**Debrief** We look at Hough Circle Transform as an example of reading mathematical texts.

# Exercises

## Python API

This is based on Ma (2004) Exercise 4.9, which is written for Matlab.

### The Canny

- Find a test image.
- Test the
`Canny`

edge detector in OpenCV. See the tutorial for an example. What kind of data does it generate? What do the data look like? - Experiment with different thresholds and different window sizes (apertures). See the docs for overview of the parameters for
`Canny`

.

It is not difficult to implement your own Canny edge detector. The exercise would be very similar to the Harris corner detector, and add little new.

### Connected Components

The edge detector gives a binary image. How can you find collections of pixels forming edges?

You can either,

- implement your own connected components function, using the ideas from the briefing, or
- test the
`ConnectedComponents`

function in OpenCV.

Visualise the components you find, for instance by using different colours Do they correspond to the objects *you* see in the image?

### Line fitting

If you do not have time to try both approaches, that’s all right, but you should at least try one. Feel free to choose,

#### Basic approach

- Implement a simple line fitter using the ideas from the briefing.
- Can you identify straight lines among the components?
- Calculate the angle \(\theta\) and the distance \(\rho\) from the origin for each component.

#### Hough transform

- Run through the tutorial to Hough Circle Transform
- Tweak the code to print out the co-ordinates of the lines detected, that is \(\theta\) and \(\rho\)
- Write a function to find the lines intersect the \(x\)- and \(y\)-axes, and list this information too.
- Can you see (easily) where each edge ought to be in the visual image?
- Write a routine, using OpenCV or otherwise, to plot the lines from the Hough transform on top of the image from the Canny detector. Do they match? It is probably best if you use different colours.
- You can make an RGB image and copy the result from Canny into one colour channel, and write the edges in a different one.

## Project

- Take an image of a box on a table (or use another simple image with straight lines).
- Use the techniques discussed above. Can you identify some of the edges on the box?
- Can you find edges that are connect to each other, possible finding a face on the box, delimited by four edges?
- Can you tell edges on the box apart from other edges in any way?

If you have time, you can start to make a prototype detecting an object (the box) and tracking it from one frame to the next.