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
22e59e93
Commit
22e59e93
authored
Jun 21, 2011
by
Ana Huaman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Threshold.cpp in samples/cpp/tutorial_code/ImgProc
parent
9ce4e875
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
0 deletions
+84
-0
Threshold.cpp
samples/cpp/tutorial_code/ImgProc/Threshold.cpp
+84
-0
No files found.
samples/cpp/tutorial_code/ImgProc/Threshold.cpp
0 → 100644
View file @
22e59e93
/**
* @file Threshold.cpp
* @brief Sample code that shows how to use the diverse threshold options offered by OpenCV
* @author OpenCV team
*/
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>
using
namespace
cv
;
/// Global variables
int
threshold_value
=
0
;
int
threshold_type
=
3
;;
int
const
max_value
=
255
;
int
const
max_type
=
4
;
int
const
max_BINARY_value
=
255
;
Mat
src
,
src_gray
,
dst
;
char
*
window_name
=
"Threshold Demo"
;
char
*
trackbar_type
=
"Type:
\n
0: Binary
\n
1: Binary Inverted
\n
2: Truncate
\n
3: To Zero
\n
4: To Zero Inverted"
;
char
*
trackbar_value
=
"Value"
;
/// Function headers
void
Threshold_Demo
(
int
,
void
*
);
/**
* @function main
*/
int
main
(
int
argc
,
char
**
argv
)
{
/// Load an image
src
=
imread
(
argv
[
1
],
1
);
/// Convert the image to Gray
cvtColor
(
src
,
src_gray
,
CV_RGB2GRAY
);
/// Create a window to display results
namedWindow
(
window_name
,
CV_WINDOW_AUTOSIZE
);
/// Create Trackbar to choose type of Threshold
createTrackbar
(
trackbar_type
,
window_name
,
&
threshold_type
,
max_type
,
Threshold_Demo
);
createTrackbar
(
trackbar_value
,
window_name
,
&
threshold_value
,
max_value
,
Threshold_Demo
);
/// Call the function to initialize
Threshold_Demo
(
0
,
0
);
/// Wait until user finishes program
while
(
true
)
{
int
c
;
c
=
waitKey
(
20
);
if
(
(
char
)
c
==
27
)
{
break
;
}
}
}
/**
* @function Threshold_Demo
*/
void
Threshold_Demo
(
int
,
void
*
)
{
/* 0: Binary
1: Binary Inverted
2: Threshold Truncated
3: Threshold to Zero
4: Threshold to Zero Inverted
*/
threshold
(
src_gray
,
dst
,
threshold_value
,
max_BINARY_value
,
threshold_type
);
imshow
(
window_name
,
dst
);
}
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