File: tutorial-imgproc-cht.dox

package info (click to toggle)
visp 3.6.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 119,296 kB
  • sloc: cpp: 500,914; ansic: 52,904; xml: 22,642; python: 7,365; java: 4,247; sh: 482; makefile: 237; objc: 145
file content (152 lines) | stat: -rw-r--r-- 6,529 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/**

\page tutorial-imgproc-cht Tutorial: Gradient-based Circle Hough Transform
\tableofcontents

\section imgproc_cht_intro Introduction

The Circle Hough Transform (*CHT*) is an image processing algorithm that permits to
detect circles in an image. We refer the interested reader to the
[Wikipedia page](https://en.wikipedia.org/wiki/Circle_Hough_Transform) to have a better
understanding on the principles of the algorithm.

The ViSP implementation relies on the Gradient-based implementation of the
algorithm.

During the step where the algorithm votes for center candidates, we use the gradient information
in order to reduce the dimensionality of the search space. Instead of voting in circular pattern,
we vote along a straight line that follows the gradient.

\image html img-tutorial-cht-center-votes.png

Then, during the step where the algorithm votes for radius candidates for each center candidate,
we check the colinearity between the gradient at a considered point and the line which links the
point towards the center candidate. If they are "enough" colinear, we increment the corresponding
radius bin vote by 1. The "enough" characteristic is controlled by the circle perfectness
parameter.

\image html img-tutorial-cht-radius-votes.png

\section imgproc_cht_requirements Requirements

With the current implementation, the `vpCircleHoughTransform` requires ViSP to be compiled with OpenCV.
If you do not know how to do it, please refer to the installation guidelines of \ref soft_vision_opencv.

\section imgproc_cht_howto How to use the tutorial

It is possible to configure the `vpCircleHoughTransform` class using a JSON file.
To do so, you need to install [JSON for modern C++](https://visp-doc.inria.fr/doxygen/visp-daily/supported-third-parties.html#soft_tool_json)
and compile ViSP with it.

You can also configure the `vpCircleHoughTransform` class using command line arguments.
To know what are the different command line arguments the software accept, please run:
```
$ cd tutorial/imgproc/hough-transform
$ ./tutorial-circle-hough --help
```

\subsection imgproc_cht_howto_synthetic How to use synthetic images


To run the software on the synthetic images using a JSON configuration file,
please run:
```
$ TARGET=full # or TARGET=half # or TARGET=quarter
$ ./tutorial-circle-hough --input ${TARGET}_disks --config config/detector_${TARGET}.json
```

To run the software on the synthetic images using the default parameters,
please run:
```
$ TARGET=full # or TARGET=half # or TARGET=quarter
$ ./tutorial-circle-hough --input ${TARGET}_disks
```

\subsection imgproc_cht_howto_images How to use actual images

To run the software on an actual image like `coins2.jpg` provided with the tutorial and using a JSON configuration file, please run:
```
$ ./tutorial-circle-hough --input coins2.jpg --config config/detector_img.json
```

\note The configuration file `config/detector_img.json` has been tuned to detect circles in the image `coins2.jpg`.
If the detections seem a bit off, you might need to change the parameters in `config/detector_img.json`.

To run the software on an actual image using command line arguments instead, please run:
```
$ ./tutorial-circle-hough --input /path/to/my/image --gaussian-kernel 5 --gaussian-sigma 1 --canny-thresh -1. --dilatation-repet 1 --center-thresh 200 --radius-bin 2 --radius-thresh 2 --radius-limits 80 90 --merging-thresh 15 2 --circle-perfectness 0.9
```

If the detections seem a bit off, you might need to change the parameters

\subsection imgproc_cht_howto_video How to use a video

You can use the software to run circle detection on a video saved as a
sequence of images that are named `${BASENAME}%d.png`.
For instance with `${BASENAME}` = `video_`, you can have the following list
of images: `video_0001.png`, `video_0002.png` and so on.

To run the software using a JSON configuration file, please run:
```
$ ./tutorial-circle-hough --input /path/to/video/${BASENAME}%d.png --config config/detector_img.json
```

To run the software using the command arguments, please run:
```
./tutorial-circle-hough --input /path/to/video/${BASENAME}%d.png --gaussian-kernel 5 --gaussian-sigma 1 --canny-thresh -1. --dilatation-repet 1 --center-thresh 200 --radius-bin 2 --radius-thresh 2 --radius-limits 80 90 --merging-thresh 15 2 --circle-perfectness 0.9
```

\section imgproc_cht_explanations Detailed explanations about the tutorial

An enumeration permits to choose between the different types of synthetic images
or using actual images or videos:

\snippet tutorial-circle-hough.cpp Enum input

You can choose the type you want using the command line arguments. To know how to do it,
please run:
```
$ ./tutorial-circle-hough --help
```

If you decide to use a video as input, the relevant piece of code that permits to
perform circle detection on the successive images of the video is the following:
\snippet tutorial-circle-hough.cpp Manage video

If you decide to use a single image as input, the relevant piece of code that permits to
perform circle detection on the image is the following:
\snippet tutorial-circle-hough.cpp Manage single image

If you decide to use a synthetic image as input, the relevant piece of code that
launches the detection on the synthetic image is the following:
\snippet tutorial-circle-hough.cpp Manage synthetic image

The function that draws the synthetic image is the following:
\snippet tutorial-circle-hough.cpp Draw synthetic

It relies on the following function to draw the disks:
\snippet tutorial-circle-hough.cpp Draw disks

If you did not use a JSON file to configure the `vpCircleHoughTransform` detector,
the following structure defines the parameters of the algorithm based on the
command line arguments:
\snippet tutorial-circle-hough.cpp Algo params

The initialization of the algorithm is performed in the following piece of code.
If a JSON configuration file is given as input configuration, it will be preferred
to the command line arguments:
\snippet tutorial-circle-hough.cpp Algo init

To run the circle detection, you must call the following method:
\snippet tutorial-circle-hough.cpp Run detection

You could have also used the following method to get only the `num_best` best
detections:
\code
int num_best; // Set it to the number of circles you want to keep
std::vector<vpImageCircle> detections = detector.detect(I, num_best);
\endcode

Then, you can iterate on the vector of detections using a synthax similar to the following:
\snippet tutorial-circle-hough.cpp Iterate detections
*/