DOURNAC.ORG
Français  English
Home
Astronomy
Sciences
Philosophy
Coding
Cv

Coding > Image Processing GUI with C++/Qt/OpenCV - Canny Edge



  • 1.Introduction
  • 2.General method
  • 3.Reducing noise by gaussian convolution
  • 4.Edge detection with Sobel operators
  • 5.Application to video streaming with OpenCV

1.Introduction :

We purpose to carry out here a graphical user interface allowing to visualize and process images of standard format (bmp, png, gif, jpeg...). This gui has been coded in C++ with Qt framework. The image processing makes firstly reduce noise, detects vertical, horizontal gradients and edges. This chain is called "Canny Edge Detector". Thereafter, we will present another functionality whose goal is to apply this chain to video streaming with OpenCV library.

"Canny_Edge" application is available for Linux and MacOS :

  •    Canny_Edge_Linux.tar.gz (compiled and tested on Debian Wheezy 7.0)
  •    Canny_Edge_MacOS.tar.gz (compiled and tested on OS X 10.9.5)

It needs Qt4 and OpenCV libraries. Once program is running, we load an image (the famous "lena.gif"). here's the result :



2.General method :

For each step of processing chain, we apply a filter on 2D array which represents image. This linear filtering is performed with a discrete convolution operation on every pixel $X_{i,j}$ of original image :

\begin{equation} Y_{i,j} = \sum_{k=-\infty}^{+\infty}\sum_{l=-\infty}^{+\infty}H_{k,l}\,X_{i-k,j-l} = \sum_{k=-(n-1)/2}^{(n-1)/2}\sum_{l=-(n-1)/2}^{(n-1)/2}H_{k,l}\,X_{i-k,j-l} \end{equation}

with output image and filter (of size $n\,\text{x}\,n$) respectively represented by $Y$ and $H$ matrices. We can see in below parts the filters used like the blur mask and the horizontal/vertical gradient mask.

3.Reducing noise by gaussian convolution :

Before the gradients and edges detection by Sobel operators, we must first establish a procedure for Gaussian filtering with a "blur" mask (see Canny edge detector) size "5x5" which allows to remove disparities on image and reduce noise. Here's this filter :

\begin{equation} H=\dfrac{1}{159}\,\, \begin{pmatrix} 2 & 4 & 5 & 4 & 2 \\ 4 & 9 & 12 & 9 & 4 \\ 5 & 12 & 15 & 12 & 5 \\ 4 & 9 & 12 & 9 & 4 \\ 2 & 4 & 5 & 4 & 2 \end{pmatrix} \end{equation}

$159$ factor normalizes the computed value for output pixel in order to remain into [$0,255$] range. We get the following image :



4.Edge detection with Sobel operators :

At this step, we implement edges detection with Sobel operators. Firstly, on uses $H_{x}$ filter for horizontal gradients and $H_{y}$ for vertical gradients :

\begin{equation} H_{x}= \begin{pmatrix} -1 & 0 & 1 \\ -2 & 0 & 2\\ -1 & 0 & 1 \end{pmatrix} \qquad H_{y}= \begin{pmatrix} -1 & -2 & -1 \\ 0 & 0 & 0\\ 1 & 2 & 1 \end{pmatrix} \end{equation}

Then, one combines the result of these 2 filtering to compute the gradient norm; for each pixel $X_{i,j}$ computed with $H_{x}$ and $Y_{i,j}$ with $H_{y}$, the output value $Z_{i,j}$ for pixel $(i,j)$ is equal to :

\begin{equation} Z_{i,j}=\sqrt{X_{i,j}^{2}+Y_{i,j}^{2}} \end{equation}

Here the output image :



5.Application to video streaming with OpenCV :

Now comes the "Webcam" feature showing "Canny Edge" processing on a webcam streaming. This video has been made with MacOS version of project :


Video not playing? Download file instead.

ps : join like me the Cosmology@Home project whose aim is to refine the model that best describes our Universe

    Home | Astronomy | Sciences | Philosophy | Coding | Cv    
- dournac.org © 2003 by fab -

Back to Top