Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
8f01f2cc
Commit
8f01f2cc
authored
Jun 28, 2011
by
Ana Huaman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added 02 tutorials for Hough Lines and Circle detection in tutorial_code -- based on code existent
parent
773654e1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
183 additions
and
0 deletions
+183
-0
HoughCircle_Demo.cpp
samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp
+55
-0
HoughLines_Demo.cpp
samples/cpp/tutorial_code/ImgTrans/HoughLines_Demo.cpp
+128
-0
No files found.
samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp
0 → 100644
View file @
8f01f2cc
/**
* @file HoughCircle_Demo.cpp
* @brief Demo code for Hough Transform
* @author OpenCV team
*/
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using
namespace
cv
;
/**
* @function main
*/
int
main
(
int
argc
,
char
**
argv
)
{
Mat
src
,
src_gray
;
/// Read the image
src
=
imread
(
argv
[
1
],
1
);
if
(
!
src
.
data
)
{
return
-
1
;
}
/// Convert it to gray
cvtColor
(
src
,
src_gray
,
CV_BGR2GRAY
);
/// Reduce the noise so we avoid false circle detection
GaussianBlur
(
src_gray
,
src_gray
,
Size
(
9
,
9
),
2
,
2
);
vector
<
Vec3f
>
circles
;
/// Apply the Hough Transform to find the circles
HoughCircles
(
src_gray
,
circles
,
CV_HOUGH_GRADIENT
,
1
,
src_gray
.
rows
/
8
,
200
,
100
,
0
,
0
);
/// Draw the circles detected
for
(
size_t
i
=
0
;
i
<
circles
.
size
();
i
++
)
{
Point
center
(
cvRound
(
circles
[
i
][
0
]),
cvRound
(
circles
[
i
][
1
]));
int
radius
=
cvRound
(
circles
[
i
][
2
]);
// circle center
circle
(
src
,
center
,
3
,
Scalar
(
0
,
255
,
0
),
-
1
,
8
,
0
);
// circle outline
circle
(
src
,
center
,
radius
,
Scalar
(
0
,
0
,
255
),
3
,
8
,
0
);
}
/// Show your results
namedWindow
(
"Hough Circle Transform Demo"
,
CV_WINDOW_AUTOSIZE
);
imshow
(
"Hough Circle Transform Demo"
,
src
);
waitKey
(
0
);
return
0
;
}
samples/cpp/tutorial_code/ImgTrans/HoughLines_Demo.cpp
0 → 100644
View file @
8f01f2cc
/**
* @file HoughLines_Demo.cpp
* @brief Demo code for Hough Transform
* @author OpenCV team
*/
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using
namespace
cv
;
using
namespace
std
;
/// Global variables
/** General variables */
Mat
src
,
edges
;
Mat
src_gray
;
Mat
standard_hough
,
probabilistic_hough
;
int
min_threshold
=
50
;
int
max_trackbar
=
150
;
char
*
standard_name
=
"Standard Hough Lines Demo"
;
char
*
probabilistic_name
=
"Probabilistic Hough Lines Demo"
;
int
s_trackbar
=
max_trackbar
;
int
p_trackbar
=
max_trackbar
;
/// Function Headers
void
help
();
void
Standard_Hough
(
int
,
void
*
);
void
Probabilistic_Hough
(
int
,
void
*
);
/**
* @function main
*/
int
main
(
int
argc
,
char
**
argv
)
{
/// Read the image
src
=
imread
(
argv
[
1
],
1
);
if
(
src
.
empty
()
)
{
help
();
return
-
1
;
}
/// Pass the image to gray
cvtColor
(
src
,
src_gray
,
CV_RGB2GRAY
);
/// Apply Canny edge detector
Canny
(
src_gray
,
edges
,
50
,
200
,
3
);
/// Create Trackbars for Thresholds
char
thresh_label
[
50
];
sprintf
(
thresh_label
,
"Thres: %d + input"
,
min_threshold
);
namedWindow
(
standard_name
,
CV_WINDOW_AUTOSIZE
);
createTrackbar
(
thresh_label
,
standard_name
,
&
s_trackbar
,
max_trackbar
,
Standard_Hough
);
namedWindow
(
probabilistic_name
,
CV_WINDOW_AUTOSIZE
);
createTrackbar
(
thresh_label
,
probabilistic_name
,
&
p_trackbar
,
max_trackbar
,
Probabilistic_Hough
);
/// Initialize
Standard_Hough
(
0
,
0
);
Probabilistic_Hough
(
0
,
0
);
waitKey
(
0
);
return
0
;
}
/**
* @function help
* @brief Indications of how to run this program and why is it for
*/
void
help
()
{
printf
(
"
\t
Hough Transform to detect lines
\n
"
);
printf
(
"
\t
---------------------------------
\n
"
);
printf
(
" Usage: ./HoughLines_Demo <image_name>
\n
"
);
}
/**
* @function Standard_Hough
*/
void
Standard_Hough
(
int
,
void
*
)
{
vector
<
Vec2f
>
s_lines
;
cvtColor
(
edges
,
standard_hough
,
CV_GRAY2BGR
);
/// 1. Use Standard Hough Transform
HoughLines
(
edges
,
s_lines
,
1
,
CV_PI
/
180
,
min_threshold
+
s_trackbar
,
0
,
0
);
/// Show the result
for
(
int
i
=
0
;
i
<
s_lines
.
size
();
i
++
)
{
float
r
=
s_lines
[
i
][
0
],
t
=
s_lines
[
i
][
1
];
double
cos_t
=
cos
(
t
),
sin_t
=
sin
(
t
);
double
x0
=
r
*
cos_t
,
y0
=
r
*
sin_t
;
double
alpha
=
1000
;
Point
pt1
(
cvRound
(
x0
+
alpha
*
(
-
sin_t
)),
cvRound
(
y0
+
alpha
*
cos_t
)
);
Point
pt2
(
cvRound
(
x0
-
alpha
*
(
-
sin_t
)),
cvRound
(
y0
-
alpha
*
cos_t
)
);
line
(
standard_hough
,
pt1
,
pt2
,
Scalar
(
255
,
0
,
0
),
3
,
CV_AA
);
}
imshow
(
standard_name
,
standard_hough
);
}
/**
* @function Probabilistic_Hough
*/
void
Probabilistic_Hough
(
int
,
void
*
)
{
vector
<
Vec4i
>
p_lines
;
cvtColor
(
edges
,
probabilistic_hough
,
CV_GRAY2BGR
);
/// 2. Use Probabilistic Hough Transform
HoughLinesP
(
edges
,
p_lines
,
1
,
CV_PI
/
180
,
min_threshold
+
p_trackbar
,
30
,
10
);
/// Show the result
for
(
size_t
i
=
0
;
i
<
p_lines
.
size
();
i
++
)
{
Vec4i
l
=
p_lines
[
i
];
line
(
probabilistic_hough
,
Point
(
l
[
0
],
l
[
1
]),
Point
(
l
[
2
],
l
[
3
]),
Scalar
(
255
,
0
,
0
),
3
,
CV_AA
);
}
imshow
(
probabilistic_name
,
probabilistic_hough
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment