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
3a0d3ebd
Commit
3a0d3ebd
authored
Jun 26, 2011
by
Ana Huaman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Laplace, Canny and Sobel samples in tutorial cpp code
parent
0dbbb89e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
196 additions
and
0 deletions
+196
-0
CannyDetector_Demo.cpp
samples/cpp/tutorial_code/ImgTrans/CannyDetector_Demo.cpp
+73
-0
Laplace_Demo.cpp
samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp
+56
-0
Sobel_Demo.cpp
samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp
+67
-0
No files found.
samples/cpp/tutorial_code/ImgTrans/CannyDetector_Demo.cpp
0 → 100644
View file @
3a0d3ebd
/**
* @file CannyDetector_Demo.cpp
* @brief Sample code showing how to detect edges using the Canny Detector
* @author OpenCV team
*/
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>
using
namespace
cv
;
/// Global variables
Mat
src
,
src_gray
;
Mat
dst
,
detected_edges
;
int
edgeThresh
=
1
;
int
lowThreshold
;
int
const
max_lowThreshold
=
100
;
int
ratio
=
3
;
int
kernel_size
=
3
;
char
*
window_name
=
"Edge Map"
;
/**
* @function CannyThreshold
* @brief Trackbar callback - Canny thresholds input with a ratio 1:3
*/
void
CannyThreshold
(
int
,
void
*
)
{
/// Reduce noise with a kernel 3x3
blur
(
src_gray
,
dst
,
Size
(
3
,
3
)
);
/// Canny detector
Canny
(
src_gray
,
detected_edges
,
lowThreshold
,
lowThreshold
*
ratio
,
kernel_size
);
/// Using Canny's output as a mask, we display our result
dst
=
Scalar
::
all
(
0
);
src
.
copyTo
(
dst
,
detected_edges
);
imshow
(
window_name
,
dst
);
}
/**
* @function main
*/
int
main
(
int
argc
,
char
**
argv
)
{
/// Load an image
src
=
imread
(
argv
[
1
]
);
if
(
!
src
.
data
)
{
return
-
1
;
}
/// Convert the image to grayscale
cvtColor
(
src
,
src_gray
,
CV_BGR2GRAY
);
/// Create a window
namedWindow
(
window_name
,
CV_WINDOW_AUTOSIZE
);
/// Create a Trackbar for user to enter threshold
createTrackbar
(
"Min Threshold:"
,
window_name
,
&
lowThreshold
,
max_lowThreshold
,
CannyThreshold
);
/// Show the image
CannyThreshold
(
0
,
0
);
/// Wait until user exit program by pressing a key
waitKey
(
0
);
return
0
;
}
samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp
0 → 100644
View file @
3a0d3ebd
/**
* @file Laplace_Demo.cpp
* @brief Sample code showing how to detect edges using the Laplace operator
* @author OpenCV team
*/
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>
using
namespace
cv
;
/**
* @function main
*/
int
main
(
int
argc
,
char
**
argv
)
{
Mat
src
,
src_gray
,
dst
;
int
kernel_size
=
3
;
int
scale
=
1
;
int
delta
=
0
;
int
ddepth
=
CV_16S
;
char
*
window_name
=
"Laplace Demo"
;
int
c
;
/// Load an image
src
=
imread
(
argv
[
1
]
);
if
(
!
src
.
data
)
{
return
-
1
;
}
/// Remove noise by blurring with a Gaussian filter
GaussianBlur
(
src
,
src
,
Size
(
3
,
3
),
0
,
0
,
BORDER_DEFAULT
);
/// Convert the image to grayscale
cvtColor
(
src
,
src_gray
,
CV_RGB2GRAY
);
/// Create window
namedWindow
(
window_name
,
CV_WINDOW_AUTOSIZE
);
/// Apply Laplace function
Mat
abs_dst
;
Laplacian
(
src_gray
,
dst
,
ddepth
,
kernel_size
,
scale
,
delta
,
BORDER_DEFAULT
);
convertScaleAbs
(
dst
,
abs_dst
);
/// Show what you got
imshow
(
window_name
,
abs_dst
);
waitKey
(
0
);
return
0
;
}
samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp
0 → 100644
View file @
3a0d3ebd
/**
* @file Sobel_Demo.cpp
* @brief Sample code using Sobel and/orScharr OpenCV functions to make a simple Edge Detector
* @author OpenCV team
*/
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>
using
namespace
cv
;
/**
* @function main
*/
int
main
(
int
argc
,
char
**
argv
)
{
Mat
src
,
src_gray
;
Mat
grad
;
char
*
window_name
=
"Sobel Demo - Simple Edge Detector"
;
int
scale
=
1
;
int
delta
=
0
;
int
ddepth
=
CV_16S
;
int
c
;
/// Load an image
src
=
imread
(
argv
[
1
]
);
if
(
!
src
.
data
)
{
return
-
1
;
}
GaussianBlur
(
src
,
src
,
Size
(
3
,
3
),
0
,
0
,
BORDER_DEFAULT
);
/// Convert it to gray
cvtColor
(
src
,
src_gray
,
CV_RGB2GRAY
);
/// Create window
namedWindow
(
window_name
,
CV_WINDOW_AUTOSIZE
);
/// Generate grad_x and grad_y
Mat
grad_x
,
grad_y
;
Mat
abs_grad_x
,
abs_grad_y
;
/// Gradient X
//Scharr( src_gray, grad_x, ddepth, 1, 0, scale, delta, BORDER_DEFAULT );
Sobel
(
src_gray
,
grad_x
,
ddepth
,
1
,
0
,
3
,
scale
,
delta
,
BORDER_DEFAULT
);
convertScaleAbs
(
grad_x
,
abs_grad_x
);
/// Gradient Y
//Scharr( src_gray, grad_y, ddepth, 0, 1, scale, delta, BORDER_DEFAULT );
Sobel
(
src_gray
,
grad_y
,
ddepth
,
0
,
1
,
3
,
scale
,
delta
,
BORDER_DEFAULT
);
convertScaleAbs
(
grad_y
,
abs_grad_y
);
/// Total Gradient (approximate)
addWeighted
(
abs_grad_x
,
0.5
,
abs_grad_y
,
0.5
,
0
,
grad
);
imshow
(
window_name
,
grad
);
waitKey
(
0
);
return
0
;
}
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