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
a2185075
Commit
a2185075
authored
Nov 13, 2012
by
Andrey Kamaev
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #148 from taka-no-me/tutorial_codes
parents
8ba9289a
dad56e20
Hide whitespace changes
Inline
Side-by-side
Showing
60 changed files
with
437 additions
and
364 deletions
+437
-364
window.cpp
modules/highgui/src/window.cpp
+50
-0
CMakeLists.txt
samples/c/CMakeLists.txt
+2
-2
CMakeLists.txt
samples/cpp/CMakeLists.txt
+23
-6
main.cpp
samples/cpp/Qt_sample/main.cpp
+34
-18
AddingImagesTrackbar.cpp
samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp
+4
-4
BasicLinearTransformsTrackbar.cpp
...p/tutorial_code/HighGUI/BasicLinearTransformsTrackbar.cpp
+3
-5
video-input-psnr-ssim.cpp
...e/HighGUI/video-input-psnr-ssim/video-input-psnr-ssim.cpp
+49
-48
video-write.cpp
...les/cpp/tutorial_code/HighGUI/video-write/video-write.cpp
+32
-35
EqualizeHist_Demo.cpp
...p/tutorial_code/Histograms_Matching/EqualizeHist_Demo.cpp
+3
-3
MatchTemplate_Demo.cpp
.../tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp
+4
-4
calcBackProject_Demo1.cpp
...torial_code/Histograms_Matching/calcBackProject_Demo1.cpp
+2
-2
calcBackProject_Demo2.cpp
...torial_code/Histograms_Matching/calcBackProject_Demo2.cpp
+2
-2
calcHist_Demo.cpp
...s/cpp/tutorial_code/Histograms_Matching/calcHist_Demo.cpp
+1
-1
AddingImages.cpp
samples/cpp/tutorial_code/ImgProc/AddingImages.cpp
+4
-5
BasicLinearTransforms.cpp
samples/cpp/tutorial_code/ImgProc/BasicLinearTransforms.cpp
+2
-3
Morphology_1.cpp
samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp
+3
-4
Morphology_2.cpp
samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp
+2
-2
Pyramids.cpp
samples/cpp/tutorial_code/ImgProc/Pyramids.cpp
+3
-3
Smoothing.cpp
samples/cpp/tutorial_code/ImgProc/Smoothing.cpp
+3
-3
Threshold.cpp
samples/cpp/tutorial_code/ImgProc/Threshold.cpp
+5
-5
CannyDetector_Demo.cpp
samples/cpp/tutorial_code/ImgTrans/CannyDetector_Demo.cpp
+3
-3
Geometric_Transforms_Demo.cpp
.../cpp/tutorial_code/ImgTrans/Geometric_Transforms_Demo.cpp
+9
-9
HoughCircle_Demo.cpp
samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp
+1
-1
HoughLines_Demo.cpp
samples/cpp/tutorial_code/ImgTrans/HoughLines_Demo.cpp
+4
-4
Laplace_Demo.cpp
samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp
+2
-4
Remap_Demo.cpp
samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp
+11
-11
Sobel_Demo.cpp
samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp
+2
-4
copyMakeBorder_demo.cpp
samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp
+5
-4
filter2D_demo.cpp
samples/cpp/tutorial_code/ImgTrans/filter2D_demo.cpp
+3
-3
findContours_demo.cpp
.../cpp/tutorial_code/ShapeDescriptors/findContours_demo.cpp
+4
-4
generalContours_demo1.cpp
.../tutorial_code/ShapeDescriptors/generalContours_demo1.cpp
+5
-5
generalContours_demo2.cpp
.../tutorial_code/ShapeDescriptors/generalContours_demo2.cpp
+5
-5
hull_demo.cpp
samples/cpp/tutorial_code/ShapeDescriptors/hull_demo.cpp
+6
-6
moments_demo.cpp
samples/cpp/tutorial_code/ShapeDescriptors/moments_demo.cpp
+10
-10
pointPolygonTest_demo.cpp
.../tutorial_code/ShapeDescriptors/pointPolygonTest_demo.cpp
+9
-9
cornerDetector_Demo.cpp
.../cpp/tutorial_code/TrackingMotion/cornerDetector_Demo.cpp
+4
-4
cornerHarris_Demo.cpp
...es/cpp/tutorial_code/TrackingMotion/cornerHarris_Demo.cpp
+3
-3
cornerSubPix_Demo.cpp
...es/cpp/tutorial_code/TrackingMotion/cornerSubPix_Demo.cpp
+4
-4
goodFeaturesToTrack_Demo.cpp
...tutorial_code/TrackingMotion/goodFeaturesToTrack_Demo.cpp
+3
-3
camera_calibration.cpp
...al_code/calib3d/camera_calibration/camera_calibration.cpp
+29
-27
SBM_Sample.cpp
samples/cpp/tutorial_code/calib3d/stereoBM/SBM_Sample.cpp
+1
-1
retina_tutorial.cpp
samples/cpp/tutorial_code/contrib/retina_tutorial.cpp
+1
-1
Drawing_1.cpp
samples/cpp/tutorial_code/core/Matrix/Drawing_1.cpp
+26
-26
Drawing_2.cpp
samples/cpp/tutorial_code/core/Matrix/Drawing_2.cpp
+2
-3
discrete_fourier_transform.cpp
...discrete_fourier_transform/discrete_fourier_transform.cpp
+1
-1
file_input_output.cpp
...utorial_code/core/file_input_output/file_input_output.cpp
+4
-4
how_to_scan_images.cpp
...orial_code/core/how_to_scan_images/how_to_scan_images.cpp
+2
-2
interoperability_with_OpenCV_1.cpp
...rability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp
+1
-1
mat_mask_operations.cpp
...ial_code/core/mat_mask_operations/mat_mask_operations.cpp
+1
-1
mat_the_basic_image_container.cpp
...e_basic_image_container/mat_the_basic_image_container.cpp
+3
-3
SURF_FlannMatcher.cpp
samples/cpp/tutorial_code/features2D/SURF_FlannMatcher.cpp
+1
-1
SURF_Homography.cpp
samples/cpp/tutorial_code/features2D/SURF_Homography.cpp
+7
-6
SURF_descriptor.cpp
samples/cpp/tutorial_code/features2D/SURF_descriptor.cpp
+2
-2
SURF_detector.cpp
samples/cpp/tutorial_code/features2D/SURF_detector.cpp
+1
-1
gpu-basics-similarity.cpp
..._code/gpu/gpu-basics-similarity/gpu-basics-similarity.cpp
+9
-11
Test.cpp
...l_code/introduction/windows_visual_studio_Opencv/Test.cpp
+4
-4
non_linear_svms.cpp
.../cpp/tutorial_code/ml/non_linear_svms/non_linear_svms.cpp
+1
-1
objectDetection.cpp
...les/cpp/tutorial_code/objectDetection/objectDetection.cpp
+8
-8
objectDetection2.cpp
...es/cpp/tutorial_code/objectDetection/objectDetection2.cpp
+8
-8
CMakeLists.txt
samples/gpu/CMakeLists.txt
+1
-1
No files found.
modules/highgui/src/window.cpp
View file @
a2185075
...
@@ -571,6 +571,56 @@ int cv::createButton(const string& button_name, ButtonCallback on_change, void*
...
@@ -571,6 +571,56 @@ int cv::createButton(const string& button_name, ButtonCallback on_change, void*
return
cvCreateButton
(
button_name
.
c_str
(),
on_change
,
userdata
,
button_type
,
initial_button_state
);
return
cvCreateButton
(
button_name
.
c_str
(),
on_change
,
userdata
,
button_type
,
initial_button_state
);
}
}
#else
CvFont
cv
::
fontQt
(
const
string
&
,
int
,
Scalar
,
int
,
int
,
int
)
{
CV_Error
(
CV_StsNotImplemented
,
"The library is compiled without QT support"
);
return
CvFont
();
}
void
cv
::
addText
(
const
Mat
&
,
const
string
&
,
Point
,
CvFont
)
{
CV_Error
(
CV_StsNotImplemented
,
"The library is compiled without QT support"
);
}
void
cv
::
displayStatusBar
(
const
string
&
,
const
string
&
,
int
)
{
CV_Error
(
CV_StsNotImplemented
,
"The library is compiled without QT support"
);
}
void
cv
::
displayOverlay
(
const
string
&
,
const
string
&
,
int
)
{
CV_Error
(
CV_StsNotImplemented
,
"The library is compiled without QT support"
);
}
int
cv
::
startLoop
(
int
(
*
)(
int
argc
,
char
*
argv
[]),
int
,
char
**
)
{
CV_Error
(
CV_StsNotImplemented
,
"The library is compiled without QT support"
);
return
0
;
}
void
cv
::
stopLoop
()
{
CV_Error
(
CV_StsNotImplemented
,
"The library is compiled without QT support"
);
}
void
cv
::
saveWindowParameters
(
const
string
&
)
{
CV_Error
(
CV_StsNotImplemented
,
"The library is compiled without QT support"
);
}
void
cv
::
loadWindowParameters
(
const
string
&
)
{
CV_Error
(
CV_StsNotImplemented
,
"The library is compiled without QT support"
);
}
int
cv
::
createButton
(
const
string
&
,
ButtonCallback
,
void
*
,
int
,
bool
)
{
CV_Error
(
CV_StsNotImplemented
,
"The library is compiled without QT support"
);
return
0
;
}
#endif
#endif
#if defined WIN32 || defined _WIN32 // see window_w32.cpp
#if defined WIN32 || defined _WIN32 // see window_w32.cpp
...
...
samples/c/CMakeLists.txt
View file @
a2185075
...
@@ -27,7 +27,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
...
@@ -27,7 +27,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
target_link_libraries
(
${
the_target
}
${
OPENCV_LINKER_LIBS
}
${
OPENCV_C_SAMPLES_REQUIRED_DEPS
}
)
target_link_libraries
(
${
the_target
}
${
OPENCV_LINKER_LIBS
}
${
OPENCV_C_SAMPLES_REQUIRED_DEPS
}
)
set_target_properties
(
${
the_target
}
PROPERTIES
set_target_properties
(
${
the_target
}
PROPERTIES
OUTPUT_NAME
"
${
name
}
"
OUTPUT_NAME
"
c-example-
${
name
}
"
PROJECT_LABEL
"(EXAMPLE)
${
name
}
"
)
PROJECT_LABEL
"(EXAMPLE)
${
name
}
"
)
if
(
ENABLE_SOLUTION_FOLDERS
)
if
(
ENABLE_SOLUTION_FOLDERS
)
...
@@ -47,7 +47,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
...
@@ -47,7 +47,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
foreach
(
sample_filename
${
cpp_samples
}
)
foreach
(
sample_filename
${
cpp_samples
}
)
get_filename_component
(
sample
${
sample_filename
}
NAME_WE
)
get_filename_component
(
sample
${
sample_filename
}
NAME_WE
)
OPENCV_DEFINE_C_EXAMPLE
(
${
sample
}
${
sample_filename
}
)
OPENCV_DEFINE_C_EXAMPLE
(
${
sample
}
${
sample_filename
}
)
endforeach
()
endforeach
()
endif
()
endif
()
...
...
samples/cpp/CMakeLists.txt
View file @
a2185075
...
@@ -28,7 +28,16 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
...
@@ -28,7 +28,16 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
# Define executable targets
# Define executable targets
# ---------------------------------------------
# ---------------------------------------------
MACRO
(
OPENCV_DEFINE_CPP_EXAMPLE name srcs
)
MACRO
(
OPENCV_DEFINE_CPP_EXAMPLE name srcs
)
set
(
the_target
"example_
${
name
}
"
)
if
(
"
${
srcs
}
"
MATCHES
"tutorial_code"
)
set
(
sample_kind tutorial
)
set
(
sample_KIND TUTORIAL
)
else
()
set
(
sample_kind example
)
set
(
sample_KIND EXAMPLE
)
endif
()
set
(
the_target
"
${
sample_kind
}
_
${
name
}
"
)
add_executable
(
${
the_target
}
${
srcs
}
)
add_executable
(
${
the_target
}
${
srcs
}
)
target_link_libraries
(
${
the_target
}
${
OPENCV_LINKER_LIBS
}
${
OPENCV_CPP_SAMPLES_REQUIRED_DEPS
}
)
target_link_libraries
(
${
the_target
}
${
OPENCV_LINKER_LIBS
}
${
OPENCV_CPP_SAMPLES_REQUIRED_DEPS
}
)
...
@@ -37,11 +46,11 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
...
@@ -37,11 +46,11 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
endif
()
endif
()
set_target_properties
(
${
the_target
}
PROPERTIES
set_target_properties
(
${
the_target
}
PROPERTIES
OUTPUT_NAME
"
${
name
}
"
OUTPUT_NAME
"
cpp-
${
sample_kind
}
-
${
name
}
"
PROJECT_LABEL
"(
EXAMPLE
)
${
name
}
"
)
PROJECT_LABEL
"(
${
sample_KIND
}
)
${
name
}
"
)
if
(
ENABLE_SOLUTION_FOLDERS
)
if
(
ENABLE_SOLUTION_FOLDERS
)
set_target_properties
(
${
the_target
}
PROPERTIES FOLDER
"
sample
s//cpp"
)
set_target_properties
(
${
the_target
}
PROPERTIES FOLDER
"
${
sample_kind
}
s//cpp"
)
endif
()
endif
()
if
(
WIN32
)
if
(
WIN32
)
...
@@ -49,11 +58,19 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
...
@@ -49,11 +58,19 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
set_target_properties
(
${
the_target
}
PROPERTIES LINK_FLAGS
"/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG"
)
set_target_properties
(
${
the_target
}
PROPERTIES LINK_FLAGS
"/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG"
)
endif
()
endif
()
install
(
TARGETS
${
the_target
}
install
(
TARGETS
${
the_target
}
RUNTIME DESTINATION
"
sample
s/cpp"
COMPONENT main
)
RUNTIME DESTINATION
"
${
sample_kind
}
s/cpp"
COMPONENT main
)
endif
()
endif
()
ENDMACRO
()
ENDMACRO
()
file
(
GLOB cpp_samples RELATIVE
${
CMAKE_CURRENT_SOURCE_DIR
}
*.cpp
)
file
(
GLOB_RECURSE cpp_samples RELATIVE
${
CMAKE_CURRENT_SOURCE_DIR
}
*.cpp
)
if
(
NOT HAVE_OPENGL
)
ocv_list_filterout
(
cpp_samples Qt_sample
)
endif
()
if
(
NOT HAVE_opencv_gpu
)
ocv_list_filterout
(
cpp_samples
"/gpu/"
)
endif
()
foreach
(
sample_filename
${
cpp_samples
}
)
foreach
(
sample_filename
${
cpp_samples
}
)
get_filename_component
(
sample
${
sample_filename
}
NAME_WE
)
get_filename_component
(
sample
${
sample_filename
}
NAME_WE
)
...
...
samples/cpp/Qt_sample/main.cpp
View file @
a2185075
...
@@ -4,14 +4,29 @@
...
@@ -4,14 +4,29 @@
#include <iostream>
#include <iostream>
#include <vector>
#include <vector>
#include <opencv/highgui.h>
#include <opencv/highgui.h>
#include <GL/gl.h>
#if defined WIN32 || defined _WIN32 || defined WINCE
#include <windows.h>
#undef small
#undef min
#undef max
#undef abs
#endif
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#include <opencv/cxcore.h>
#include <opencv/cxcore.h>
#include <opencv/cv.h>
#include <opencv/cv.h>
using
namespace
std
;
using
namespace
std
;
using
namespace
cv
;
using
namespace
cv
;
void
help
()
static
void
help
()
{
{
cout
<<
"
\n
This demo demonstrates the use of the Qt enhanced version of the highgui GUI interface
\n
"
cout
<<
"
\n
This demo demonstrates the use of the Qt enhanced version of the highgui GUI interface
\n
"
" and dang if it doesn't throw in the use of of the POSIT 3D tracking algorithm too
\n
"
" and dang if it doesn't throw in the use of of the POSIT 3D tracking algorithm too
\n
"
...
@@ -29,7 +44,7 @@ void help()
...
@@ -29,7 +44,7 @@ void help()
#define FOCAL_LENGTH 600
#define FOCAL_LENGTH 600
#define CUBE_SIZE 10
#define CUBE_SIZE 10
void
renderCube
(
float
size
)
static
void
renderCube
(
float
size
)
{
{
glBegin
(
GL_QUADS
);
glBegin
(
GL_QUADS
);
// Front Face
// Front Face
...
@@ -72,7 +87,7 @@ void renderCube(float size)
...
@@ -72,7 +87,7 @@ void renderCube(float size)
}
}
void
on_opengl
(
void
*
param
)
static
void
on_opengl
(
void
*
param
)
{
{
//Draw the object with the estimated pose
//Draw the object with the estimated pose
glLoadIdentity
();
glLoadIdentity
();
...
@@ -87,7 +102,7 @@ void on_opengl(void* param)
...
@@ -87,7 +102,7 @@ void on_opengl(void* param)
glDisable
(
GL_LIGHTING
);
glDisable
(
GL_LIGHTING
);
}
}
void
initPOSIT
(
std
::
vector
<
CvPoint3D32f
>
*
modelPoints
)
static
void
initPOSIT
(
std
::
vector
<
CvPoint3D32f
>
*
modelPoints
)
{
{
//Create the model pointss
//Create the model pointss
modelPoints
->
push_back
(
cvPoint3D32f
(
0.0
f
,
0.0
f
,
0.0
f
));
//The first must be (0,0,0)
modelPoints
->
push_back
(
cvPoint3D32f
(
0.0
f
,
0.0
f
,
0.0
f
));
//The first must be (0,0,0)
...
@@ -96,7 +111,7 @@ void initPOSIT(std::vector<CvPoint3D32f> *modelPoints)
...
@@ -96,7 +111,7 @@ void initPOSIT(std::vector<CvPoint3D32f> *modelPoints)
modelPoints
->
push_back
(
cvPoint3D32f
(
0.0
f
,
CUBE_SIZE
,
0.0
f
));
modelPoints
->
push_back
(
cvPoint3D32f
(
0.0
f
,
CUBE_SIZE
,
0.0
f
));
}
}
void
foundCorners
(
vector
<
CvPoint2D32f
>
*
srcImagePoints
,
IplImage
*
source
,
IplImage
*
grayImage
)
static
void
foundCorners
(
vector
<
CvPoint2D32f
>
*
srcImagePoints
,
IplImage
*
source
,
IplImage
*
grayImage
)
{
{
cvCvtColor
(
source
,
grayImage
,
CV_RGB2GRAY
);
cvCvtColor
(
source
,
grayImage
,
CV_RGB2GRAY
);
cvSmooth
(
grayImage
,
grayImage
,
CV_GAUSSIAN
,
11
);
cvSmooth
(
grayImage
,
grayImage
,
CV_GAUSSIAN
,
11
);
...
@@ -116,12 +131,12 @@ void foundCorners(vector<CvPoint2D32f> *srcImagePoints,IplImage* source, IplImag
...
@@ -116,12 +131,12 @@ void foundCorners(vector<CvPoint2D32f> *srcImagePoints,IplImage* source, IplImag
if
(
contours
.
size
()
==
srcImagePoints_temp
.
size
())
if
(
contours
.
size
()
==
srcImagePoints_temp
.
size
())
{
{
for
(
in
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
{
{
p
.
x
=
p
.
y
=
0
;
p
.
x
=
p
.
y
=
0
;
for
(
in
t
j
=
0
;
j
<
contours
[
i
].
size
();
j
++
)
for
(
size_
t
j
=
0
;
j
<
contours
[
i
].
size
();
j
++
)
p
+=
contours
[
i
][
j
];
p
+=
contours
[
i
][
j
];
srcImagePoints_temp
.
at
(
i
)
=
cvPoint2D32f
(
float
(
p
.
x
)
/
contours
[
i
].
size
(),
float
(
p
.
y
)
/
contours
[
i
].
size
());
srcImagePoints_temp
.
at
(
i
)
=
cvPoint2D32f
(
float
(
p
.
x
)
/
contours
[
i
].
size
(),
float
(
p
.
y
)
/
contours
[
i
].
size
());
...
@@ -134,8 +149,8 @@ void foundCorners(vector<CvPoint2D32f> *srcImagePoints,IplImage* source, IplImag
...
@@ -134,8 +149,8 @@ void foundCorners(vector<CvPoint2D32f> *srcImagePoints,IplImage* source, IplImag
//< y = 3
//< y = 3
//get point 0;
//get point 0;
in
t
index
=
0
;
size_
t
index
=
0
;
for
(
in
t
i
=
1
;
i
<
srcImagePoints_temp
.
size
();
i
++
)
for
(
size_
t
i
=
1
;
i
<
srcImagePoints_temp
.
size
();
i
++
)
{
{
if
(
srcImagePoints_temp
.
at
(
i
).
y
>
srcImagePoints_temp
.
at
(
index
).
y
)
if
(
srcImagePoints_temp
.
at
(
i
).
y
>
srcImagePoints_temp
.
at
(
index
).
y
)
index
=
i
;
index
=
i
;
...
@@ -144,7 +159,7 @@ void foundCorners(vector<CvPoint2D32f> *srcImagePoints,IplImage* source, IplImag
...
@@ -144,7 +159,7 @@ void foundCorners(vector<CvPoint2D32f> *srcImagePoints,IplImage* source, IplImag
//get point 1;
//get point 1;
index
=
0
;
index
=
0
;
for
(
in
t
i
=
1
;
i
<
srcImagePoints_temp
.
size
();
i
++
)
for
(
size_
t
i
=
1
;
i
<
srcImagePoints_temp
.
size
();
i
++
)
{
{
if
(
srcImagePoints_temp
.
at
(
i
).
x
>
srcImagePoints_temp
.
at
(
index
).
x
)
if
(
srcImagePoints_temp
.
at
(
i
).
x
>
srcImagePoints_temp
.
at
(
index
).
x
)
index
=
i
;
index
=
i
;
...
@@ -153,7 +168,7 @@ void foundCorners(vector<CvPoint2D32f> *srcImagePoints,IplImage* source, IplImag
...
@@ -153,7 +168,7 @@ void foundCorners(vector<CvPoint2D32f> *srcImagePoints,IplImage* source, IplImag
//get point 2;
//get point 2;
index
=
0
;
index
=
0
;
for
(
in
t
i
=
1
;
i
<
srcImagePoints_temp
.
size
();
i
++
)
for
(
size_
t
i
=
1
;
i
<
srcImagePoints_temp
.
size
();
i
++
)
{
{
if
(
srcImagePoints_temp
.
at
(
i
).
x
<
srcImagePoints_temp
.
at
(
index
).
x
)
if
(
srcImagePoints_temp
.
at
(
i
).
x
<
srcImagePoints_temp
.
at
(
index
).
x
)
index
=
i
;
index
=
i
;
...
@@ -162,7 +177,7 @@ void foundCorners(vector<CvPoint2D32f> *srcImagePoints,IplImage* source, IplImag
...
@@ -162,7 +177,7 @@ void foundCorners(vector<CvPoint2D32f> *srcImagePoints,IplImage* source, IplImag
//get point 3;
//get point 3;
index
=
0
;
index
=
0
;
for
(
in
t
i
=
1
;
i
<
srcImagePoints_temp
.
size
();
i
++
)
for
(
size_
t
i
=
1
;
i
<
srcImagePoints_temp
.
size
();
i
++
)
{
{
if
(
srcImagePoints_temp
.
at
(
i
).
y
<
srcImagePoints_temp
.
at
(
index
).
y
)
if
(
srcImagePoints_temp
.
at
(
i
).
y
<
srcImagePoints_temp
.
at
(
index
).
y
)
index
=
i
;
index
=
i
;
...
@@ -171,7 +186,7 @@ void foundCorners(vector<CvPoint2D32f> *srcImagePoints,IplImage* source, IplImag
...
@@ -171,7 +186,7 @@ void foundCorners(vector<CvPoint2D32f> *srcImagePoints,IplImage* source, IplImag
Mat
Msource
=
source
;
Mat
Msource
=
source
;
stringstream
ss
;
stringstream
ss
;
for
(
in
t
i
=
0
;
i
<
srcImagePoints_temp
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
srcImagePoints_temp
.
size
();
i
++
)
{
{
ss
<<
i
;
ss
<<
i
;
circle
(
Msource
,
srcImagePoints
->
at
(
i
),
5
,
CV_RGB
(
255
,
0
,
0
));
circle
(
Msource
,
srcImagePoints
->
at
(
i
),
5
,
CV_RGB
(
255
,
0
,
0
));
...
@@ -185,7 +200,7 @@ void foundCorners(vector<CvPoint2D32f> *srcImagePoints,IplImage* source, IplImag
...
@@ -185,7 +200,7 @@ void foundCorners(vector<CvPoint2D32f> *srcImagePoints,IplImage* source, IplImag
}
}
void
createOpenGLMatrixFrom
(
float
*
posePOSIT
,
const
CvMatr32f
&
rotationMatrix
,
const
CvVect32f
&
translationVector
)
static
void
createOpenGLMatrixFrom
(
float
*
posePOSIT
,
const
CvMatr32f
&
rotationMatrix
,
const
CvVect32f
&
translationVector
)
{
{
...
@@ -206,8 +221,9 @@ void createOpenGLMatrixFrom(float *posePOSIT,const CvMatr32f &rotationMatrix, co
...
@@ -206,8 +221,9 @@ void createOpenGLMatrixFrom(float *posePOSIT,const CvMatr32f &rotationMatrix, co
posePOSIT
[
15
]
=
1.0
;
posePOSIT
[
15
]
=
1.0
;
}
}
int
main
(
int
argc
,
char
*
argv
[]
)
int
main
(
void
)
{
{
help
();
CvCapture
*
video
=
cvCaptureFromFile
(
"cube4.avi"
);
CvCapture
*
video
=
cvCaptureFromFile
(
"cube4.avi"
);
CV_Assert
(
video
);
CV_Assert
(
video
);
...
@@ -220,7 +236,7 @@ int main(int argc, char *argv[])
...
@@ -220,7 +236,7 @@ int main(int argc, char *argv[])
//For debug
//For debug
//cvNamedWindow("tempGray",CV_WINDOW_AUTOSIZE);
//cvNamedWindow("tempGray",CV_WINDOW_AUTOSIZE);
float
OpenGLMatrix
[]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
float
OpenGLMatrix
[]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
cv
CreateOpenGL
Callback
(
"POSIT"
,
on_opengl
,
OpenGLMatrix
);
cv
SetOpenGlDraw
Callback
(
"POSIT"
,
on_opengl
,
OpenGLMatrix
);
vector
<
CvPoint3D32f
>
modelPoints
;
vector
<
CvPoint3D32f
>
modelPoints
;
initPOSIT
(
&
modelPoints
);
initPOSIT
(
&
modelPoints
);
...
...
samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp
View file @
a2185075
...
@@ -4,8 +4,8 @@
...
@@ -4,8 +4,8 @@
* @author OpenCV team
* @author OpenCV team
*/
*/
#include
<cv.h>
#include
"opencv2/highgui/highgui.hpp"
#include <
highgui
.h>
#include <
stdio
.h>
using
namespace
cv
;
using
namespace
cv
;
...
@@ -24,7 +24,7 @@ Mat dst;
...
@@ -24,7 +24,7 @@ Mat dst;
* @function on_trackbar
* @function on_trackbar
* @brief Callback for trackbar
* @brief Callback for trackbar
*/
*/
void
on_trackbar
(
int
,
void
*
)
static
void
on_trackbar
(
int
,
void
*
)
{
{
alpha
=
(
double
)
alpha_slider
/
alpha_slider_max
;
alpha
=
(
double
)
alpha_slider
/
alpha_slider_max
;
...
@@ -40,7 +40,7 @@ void on_trackbar( int, void* )
...
@@ -40,7 +40,7 @@ void on_trackbar( int, void* )
* @function main
* @function main
* @brief Main function
* @brief Main function
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
void
)
{
{
/// Read image ( same size, same type )
/// Read image ( same size, same type )
src1
=
imread
(
"../images/LinuxLogo.jpg"
);
src1
=
imread
(
"../images/LinuxLogo.jpg"
);
...
...
samples/cpp/tutorial_code/HighGUI/BasicLinearTransformsTrackbar.cpp
View file @
a2185075
...
@@ -5,8 +5,7 @@
...
@@ -5,8 +5,7 @@
* @author OpenCV team
* @author OpenCV team
*/
*/
#include <cv.h>
#include "opencv2/highgui/highgui.hpp"
#include <highgui.h>
using
namespace
cv
;
using
namespace
cv
;
...
@@ -18,13 +17,12 @@ int beta; /**< Simple brightness control*/
...
@@ -18,13 +17,12 @@ int beta; /**< Simple brightness control*/
/** Matrices to store images */
/** Matrices to store images */
Mat
image
;
Mat
image
;
Mat
new_image
;
/**
/**
* @function on_trackbar
* @function on_trackbar
* @brief Called whenever any of alpha or beta changes
* @brief Called whenever any of alpha or beta changes
*/
*/
void
on_trackbar
(
int
,
void
*
)
static
void
on_trackbar
(
int
,
void
*
)
{
{
Mat
new_image
=
Mat
::
zeros
(
image
.
size
(),
image
.
type
()
);
Mat
new_image
=
Mat
::
zeros
(
image
.
size
(),
image
.
type
()
);
...
@@ -44,7 +42,7 @@ void on_trackbar( int, void* )
...
@@ -44,7 +42,7 @@ void on_trackbar( int, void* )
* @function main
* @function main
* @brief Main function
* @brief Main function
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Read image given by user
/// Read image given by user
image
=
imread
(
argv
[
1
]
);
image
=
imread
(
argv
[
1
]
);
...
...
samples/cpp/tutorial_code/HighGUI/video-input-psnr-ssim/video-input-psnr-ssim.cpp
View file @
a2185075
#include <iostream>
// for standard I/O
#include <iostream>
// for standard I/O
#include <string> // for strings
#include <string> // for strings
#include <iomanip> // for controlling float print precision
#include <iomanip> // for controlling float print precision
#include <sstream> // string to number conversion
#include <sstream> // string to number conversion
#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
#include <opencv2/highgui/highgui.hpp> // OpenCV window I/O
#include <opencv2/highgui/highgui.hpp> // OpenCV window I/O
using
namespace
std
;
using
namespace
std
;
...
@@ -13,55 +13,57 @@ using namespace cv;
...
@@ -13,55 +13,57 @@ using namespace cv;
double
getPSNR
(
const
Mat
&
I1
,
const
Mat
&
I2
);
double
getPSNR
(
const
Mat
&
I1
,
const
Mat
&
I2
);
Scalar
getMSSIM
(
const
Mat
&
I1
,
const
Mat
&
I2
);
Scalar
getMSSIM
(
const
Mat
&
I1
,
const
Mat
&
I2
);
void
help
()
static
void
help
()
{
{
cout
cout
<<
"
\n
--------------------------------------------------------------------------"
<<
endl
<<
"
----
--------------------------------------------------------------------------"
<<
endl
<<
"This program shows how to read a video file with OpenCV. In addition, it
tests the
"
<<
"This program shows how to read a video file with OpenCV. In addition, it "
<<
"
similarity of two input videos first with PSNR, and for the frames below a PSNR "
<<
endl
<<
"
tests the similarity of two input videos first with PSNR, and for the frames "
<<
"
trigger value, also with MSSIM."
<<
endl
<<
"
below a PSNR trigger value, also with MSSIM."
<<
endl
<<
"Usage:"
<<
endl
<<
"Usage:"
<<
endl
<<
"./video-source referenceVideo useCaseTestVideo PSNR_Trigger_Value Wait_Between_Frames "
<<
endl
<<
"./video-source referenceVideo useCaseTestVideo PSNR_Trigger_Value Wait_Between_Frames "
<<
endl
<<
"--------------------------------------------------------------------------"
<<
endl
<<
"--------------------------------------------------------------------------"
<<
endl
<<
endl
;
<<
endl
;
}
}
int
main
(
int
argc
,
char
*
argv
[],
char
*
window_name
)
int
main
(
int
argc
,
char
*
argv
[])
{
{
help
();
help
();
if
(
argc
!=
5
)
if
(
argc
!=
5
)
{
{
cout
<<
"Not enough parameters"
<<
endl
;
cout
<<
"Not enough parameters"
<<
endl
;
return
-
1
;
return
-
1
;
}
}
stringstream
conv
;
stringstream
conv
;
const
string
sourceReference
=
argv
[
1
],
sourceCompareWith
=
argv
[
2
];
const
string
sourceReference
=
argv
[
1
],
sourceCompareWith
=
argv
[
2
];
int
psnrTriggerValue
,
delay
;
int
psnrTriggerValue
,
delay
;
conv
<<
argv
[
3
]
<<
endl
<<
argv
[
4
];
// put in the strings
conv
<<
argv
[
3
]
<<
endl
<<
argv
[
4
];
// put in the strings
conv
>>
psnrTriggerValue
>>
delay
;
// take out the numbers
conv
>>
psnrTriggerValue
>>
delay
;
// take out the numbers
char
c
;
char
c
;
int
frameNum
=
-
1
;
// Frame counter
int
frameNum
=
-
1
;
// Frame counter
VideoCapture
captRefrnc
(
sourceReference
),
VideoCapture
captRefrnc
(
sourceReference
),
captUndTst
(
sourceCompareWith
);
captUndTst
(
sourceCompareWith
);
if
(
!
captRefrnc
.
isOpened
())
if
(
!
captRefrnc
.
isOpened
())
{
{
cout
<<
"Could not open reference "
<<
sourceReference
<<
endl
;
cout
<<
"Could not open reference "
<<
sourceReference
<<
endl
;
return
-
1
;
return
-
1
;
}
}
if
(
!
captUndTst
.
isOpened
())
if
(
!
captUndTst
.
isOpened
())
{
{
cout
<<
"Could not open case test "
<<
sourceCompareWith
<<
endl
;
cout
<<
"Could not open case test "
<<
sourceCompareWith
<<
endl
;
return
-
1
;
return
-
1
;
}
}
Size
refS
=
Size
((
int
)
captRefrnc
.
get
(
CV_CAP_PROP_FRAME_WIDTH
),
Size
refS
=
Size
((
int
)
captRefrnc
.
get
(
CV_CAP_PROP_FRAME_WIDTH
),
(
int
)
captRefrnc
.
get
(
CV_CAP_PROP_FRAME_HEIGHT
)),
(
int
)
captRefrnc
.
get
(
CV_CAP_PROP_FRAME_HEIGHT
)),
uTSi
=
Size
((
int
)
captUndTst
.
get
(
CV_CAP_PROP_FRAME_WIDTH
),
uTSi
=
Size
((
int
)
captUndTst
.
get
(
CV_CAP_PROP_FRAME_WIDTH
),
(
int
)
captUndTst
.
get
(
CV_CAP_PROP_FRAME_HEIGHT
));
(
int
)
captUndTst
.
get
(
CV_CAP_PROP_FRAME_HEIGHT
));
if
(
refS
!=
uTSi
)
if
(
refS
!=
uTSi
)
{
{
...
@@ -73,43 +75,43 @@ int main(int argc, char *argv[], char *window_name)
...
@@ -73,43 +75,43 @@ int main(int argc, char *argv[], char *window_name)
const
char
*
WIN_RF
=
"Reference"
;
const
char
*
WIN_RF
=
"Reference"
;
// Windows
// Windows
namedWindow
(
WIN_RF
,
CV_WINDOW_AUTOSIZE
);
namedWindow
(
WIN_RF
,
CV_WINDOW_AUTOSIZE
);
namedWindow
(
WIN_UT
,
CV_WINDOW_AUTOSIZE
);
namedWindow
(
WIN_UT
,
CV_WINDOW_AUTOSIZE
);
cvMoveWindow
(
WIN_RF
,
400
,
0
);
//750, 2 (bernat =0)
cvMoveWindow
(
WIN_RF
,
400
,
0
);
//750, 2 (bernat =0)
cvMoveWindow
(
WIN_UT
,
refS
.
width
,
0
);
//1500, 2
cvMoveWindow
(
WIN_UT
,
refS
.
width
,
0
);
//1500, 2
cout
<<
"Reference frame resolution: Width="
<<
refS
.
width
<<
" Height="
<<
refS
.
height
cout
<<
"Reference frame resolution: Width="
<<
refS
.
width
<<
" Height="
<<
refS
.
height
<<
" of nr#: "
<<
captRefrnc
.
get
(
CV_CAP_PROP_FRAME_COUNT
)
<<
endl
;
<<
" of nr#: "
<<
captRefrnc
.
get
(
CV_CAP_PROP_FRAME_COUNT
)
<<
endl
;
cout
<<
"PSNR trigger value "
<<
cout
<<
"PSNR trigger value "
<<
setiosflags
(
ios
::
fixed
)
<<
setprecision
(
3
)
setiosflags
(
ios
::
fixed
)
<<
setprecision
(
3
)
<<
psnrTriggerValue
<<
endl
;
<<
psnrTriggerValue
<<
endl
;
Mat
frameReference
,
frameUnderTest
;
Mat
frameReference
,
frameUnderTest
;
double
psnrV
;
double
psnrV
;
Scalar
mssimV
;
Scalar
mssimV
;
while
(
true
)
//Show the image captured in the window and repeat
for
(;;
)
//Show the image captured in the window and repeat
{
{
captRefrnc
>>
frameReference
;
captRefrnc
>>
frameReference
;
captUndTst
>>
frameUnderTest
;
captUndTst
>>
frameUnderTest
;
if
(
frameReference
.
empty
()
||
frameUnderTest
.
empty
())
if
(
frameReference
.
empty
()
||
frameUnderTest
.
empty
())
{
{
cout
<<
" < < < Game over! > > > "
;
cout
<<
" < < < Game over! > > > "
;
break
;
break
;
}
}
++
frameNum
;
++
frameNum
;
cout
<<
"Frame:"
<<
frameNum
<<
"# "
;
cout
<<
"Frame: "
<<
frameNum
<<
"# "
;
///////////////////////////////// PSNR ////////////////////////////////////////////////////
///////////////////////////////// PSNR ////////////////////////////////////////////////////
psnrV
=
getPSNR
(
frameReference
,
frameUnderTest
);
//get PSNR
psnrV
=
getPSNR
(
frameReference
,
frameUnderTest
);
cout
<<
setiosflags
(
ios
::
fixed
)
<<
setprecision
(
3
)
<<
psnrV
<<
"dB"
;
cout
<<
setiosflags
(
ios
::
fixed
)
<<
setprecision
(
3
)
<<
psnrV
<<
"dB"
;
//////////////////////////////////// MSSIM /////////////////////////////////////////////////
//////////////////////////////////// MSSIM /////////////////////////////////////////////////
if
(
psnrV
<
psnrTriggerValue
&&
psnrV
)
if
(
psnrV
<
psnrTriggerValue
&&
psnrV
)
{
{
mssimV
=
getMSSIM
(
frameReference
,
frameUnderTest
);
mssimV
=
getMSSIM
(
frameReference
,
frameUnderTest
);
cout
<<
" MSSIM: "
cout
<<
" MSSIM: "
<<
" R "
<<
setiosflags
(
ios
::
fixed
)
<<
setprecision
(
2
)
<<
mssimV
.
val
[
2
]
*
100
<<
"%"
<<
" R "
<<
setiosflags
(
ios
::
fixed
)
<<
setprecision
(
2
)
<<
mssimV
.
val
[
2
]
*
100
<<
"%"
...
@@ -120,10 +122,10 @@ int main(int argc, char *argv[], char *window_name)
...
@@ -120,10 +122,10 @@ int main(int argc, char *argv[], char *window_name)
cout
<<
endl
;
cout
<<
endl
;
////////////////////////////////// Show Image /////////////////////////////////////////////
////////////////////////////////// Show Image /////////////////////////////////////////////
imshow
(
WIN_RF
,
frameReference
);
imshow
(
WIN_RF
,
frameReference
);
imshow
(
WIN_UT
,
frameUnderTest
);
imshow
(
WIN_UT
,
frameUnderTest
);
c
=
cvWaitKey
(
delay
);
c
=
(
char
)
cvWaitKey
(
delay
);
if
(
c
==
27
)
break
;
if
(
c
==
27
)
break
;
}
}
...
@@ -137,7 +139,7 @@ double getPSNR(const Mat& I1, const Mat& I2)
...
@@ -137,7 +139,7 @@ double getPSNR(const Mat& I1, const Mat& I2)
s1
.
convertTo
(
s1
,
CV_32F
);
// cannot make a square on 8 bits
s1
.
convertTo
(
s1
,
CV_32F
);
// cannot make a square on 8 bits
s1
=
s1
.
mul
(
s1
);
// |I1 - I2|^2
s1
=
s1
.
mul
(
s1
);
// |I1 - I2|^2
Scalar
s
=
sum
(
s1
);
// sum elements per channel
Scalar
s
=
sum
(
s1
);
// sum elements per channel
double
sse
=
s
.
val
[
0
]
+
s
.
val
[
1
]
+
s
.
val
[
2
];
// sum channels
double
sse
=
s
.
val
[
0
]
+
s
.
val
[
1
]
+
s
.
val
[
2
];
// sum channels
...
@@ -145,8 +147,8 @@ double getPSNR(const Mat& I1, const Mat& I2)
...
@@ -145,8 +147,8 @@ double getPSNR(const Mat& I1, const Mat& I2)
return
0
;
return
0
;
else
else
{
{
double
mse
=
sse
/
(
double
)(
I1
.
channels
()
*
I1
.
total
());
double
mse
=
sse
/
(
double
)(
I1
.
channels
()
*
I1
.
total
());
double
psnr
=
10.0
*
log10
((
255
*
255
)
/
mse
);
double
psnr
=
10.0
*
log10
((
255
*
255
)
/
mse
);
return
psnr
;
return
psnr
;
}
}
}
}
...
@@ -155,10 +157,10 @@ Scalar getMSSIM( const Mat& i1, const Mat& i2)
...
@@ -155,10 +157,10 @@ Scalar getMSSIM( const Mat& i1, const Mat& i2)
{
{
const
double
C1
=
6.5025
,
C2
=
58.5225
;
const
double
C1
=
6.5025
,
C2
=
58.5225
;
/***************************** INITS **********************************/
/***************************** INITS **********************************/
int
d
=
CV_32F
;
int
d
=
CV_32F
;
Mat
I1
,
I2
;
Mat
I1
,
I2
;
i1
.
convertTo
(
I1
,
d
);
// cannot calculate on one byte large values
i1
.
convertTo
(
I1
,
d
);
// cannot calculate on one byte large values
i2
.
convertTo
(
I2
,
d
);
i2
.
convertTo
(
I2
,
d
);
Mat
I2_2
=
I2
.
mul
(
I2
);
// I2^2
Mat
I2_2
=
I2
.
mul
(
I2
);
// I2^2
...
@@ -167,7 +169,7 @@ Scalar getMSSIM( const Mat& i1, const Mat& i2)
...
@@ -167,7 +169,7 @@ Scalar getMSSIM( const Mat& i1, const Mat& i2)
/*************************** END INITS **********************************/
/*************************** END INITS **********************************/
Mat
mu1
,
mu2
;
// PRELIMINARY COMPUTING
Mat
mu1
,
mu2
;
// PRELIMINARY COMPUTING
GaussianBlur
(
I1
,
mu1
,
Size
(
11
,
11
),
1.5
);
GaussianBlur
(
I1
,
mu1
,
Size
(
11
,
11
),
1.5
);
GaussianBlur
(
I2
,
mu2
,
Size
(
11
,
11
),
1.5
);
GaussianBlur
(
I2
,
mu2
,
Size
(
11
,
11
),
1.5
);
...
@@ -191,15 +193,15 @@ Scalar getMSSIM( const Mat& i1, const Mat& i2)
...
@@ -191,15 +193,15 @@ Scalar getMSSIM( const Mat& i1, const Mat& i2)
t1
=
2
*
mu1_mu2
+
C1
;
t1
=
2
*
mu1_mu2
+
C1
;
t2
=
2
*
sigma12
+
C2
;
t2
=
2
*
sigma12
+
C2
;
t3
=
t1
.
mul
(
t2
);
// t3 = ((2*mu1_mu2 + C1).*(2*sigma12 + C2))
t3
=
t1
.
mul
(
t2
);
// t3 = ((2*mu1_mu2 + C1).*(2*sigma12 + C2))
t1
=
mu1_2
+
mu2_2
+
C1
;
t1
=
mu1_2
+
mu2_2
+
C1
;
t2
=
sigma1_2
+
sigma2_2
+
C2
;
t2
=
sigma1_2
+
sigma2_2
+
C2
;
t1
=
t1
.
mul
(
t2
);
// t1 =((mu1_2 + mu2_2 + C1).*(sigma1_2 + sigma2_2 + C2))
t1
=
t1
.
mul
(
t2
);
// t1 =((mu1_2 + mu2_2 + C1).*(sigma1_2 + sigma2_2 + C2))
Mat
ssim_map
;
Mat
ssim_map
;
divide
(
t3
,
t1
,
ssim_map
);
// ssim_map = t3./t1;
divide
(
t3
,
t1
,
ssim_map
);
// ssim_map = t3./t1;
Scalar
mssim
=
mean
(
ssim_map
);
// mssim = average of ssim map
Scalar
mssim
=
mean
(
ssim_map
);
// mssim = average of ssim map
return
mssim
;
return
mssim
;
}
}
\ No newline at end of file
samples/cpp/tutorial_code/HighGUI/video-write/video-write.cpp
View file @
a2185075
...
@@ -7,51 +7,53 @@
...
@@ -7,51 +7,53 @@
using
namespace
std
;
using
namespace
std
;
using
namespace
cv
;
using
namespace
cv
;
void
help
()
static
void
help
()
{
{
cout
cout
<<
"
\n
--------------------------------------------------------------------------"
<<
endl
<<
"
----
--------------------------------------------------------------------------"
<<
endl
<<
"This program shows how to write video files.
You can extract the R or G or B color channel "
<<
"This program shows how to write video files.
"
<<
endl
<<
"
of the input video.write "
<<
endl
<<
"
You can extract the R or G or B color channel of the input video."
<<
endl
<<
"Usage:"
<<
endl
<<
"Usage:"
<<
endl
<<
"./video-write inputvideoName [ R | G | B] [Y | N]"
<<
endl
<<
"./video-write inputvideoName [ R | G | B] [Y | N]"
<<
endl
<<
"--------------------------------------------------------------------------
"
<<
endl
<<
"--------------------------------------------------------------------------
----"
<<
endl
<<
endl
;
<<
endl
;
}
}
int
main
(
int
argc
,
char
*
argv
[],
char
*
window_name
)
int
main
(
int
argc
,
char
*
argv
[])
{
{
help
();
help
();
if
(
argc
!=
4
)
if
(
argc
!=
4
)
{
{
cout
<<
"Not enough parameters"
<<
endl
;
cout
<<
"Not enough parameters"
<<
endl
;
return
-
1
;
return
-
1
;
}
}
const
string
source
=
argv
[
1
];
// the source file name
const
string
source
=
argv
[
1
];
// the source file name
const
bool
askOutputType
=
argv
[
3
][
0
]
==
'Y'
;
// If false it will use the inputs codec type
const
bool
askOutputType
=
argv
[
3
][
0
]
==
'Y'
;
// If false it will use the inputs codec type
VideoCapture
inputVideo
(
source
);
// Open input
VideoCapture
inputVideo
(
source
);
// Open input
if
(
!
inputVideo
.
isOpened
())
if
(
!
inputVideo
.
isOpened
())
{
{
cout
<<
"Could not open the input video
.
"
<<
source
<<
endl
;
cout
<<
"Could not open the input video
:
"
<<
source
<<
endl
;
return
-
1
;
return
-
1
;
}
}
string
::
size_type
pAt
=
source
.
find_last_of
(
'.'
);
// Find extension point
string
::
size_type
pAt
=
source
.
find_last_of
(
'.'
);
// Find extension point
const
string
NAME
=
source
.
substr
(
0
,
pAt
)
+
argv
[
2
][
0
]
+
".avi"
;
// Form the new name with container
const
string
NAME
=
source
.
substr
(
0
,
pAt
)
+
argv
[
2
][
0
]
+
".avi"
;
// Form the new name with container
int
ex
=
static_cast
<
int
>
(
inputVideo
.
get
(
CV_CAP_PROP_FOURCC
));
// Get Codec Type- Int form
int
ex
=
static_cast
<
int
>
(
inputVideo
.
get
(
CV_CAP_PROP_FOURCC
));
// Get Codec Type- Int form
// Transform from int to char via Bitwise operators
// Transform from int to char via Bitwise operators
char
EXT
[]
=
{
ex
&
0XFF
,
(
ex
&
0XFF00
)
>>
8
,(
ex
&
0XFF0000
)
>>
16
,(
ex
&
0XFF000000
)
>>
24
,
0
};
char
EXT
[]
=
{
(
char
)(
ex
&
0XFF
)
,
(
char
)((
ex
&
0XFF00
)
>>
8
),(
char
)((
ex
&
0XFF0000
)
>>
16
),(
char
)((
ex
&
0XFF000000
)
>>
24
)
,
0
};
Size
S
=
Size
((
int
)
inputVideo
.
get
(
CV_CAP_PROP_FRAME_WIDTH
),
//Acquire input size
Size
S
=
Size
((
int
)
inputVideo
.
get
(
CV_CAP_PROP_FRAME_WIDTH
),
//
Acquire input size
(
int
)
inputVideo
.
get
(
CV_CAP_PROP_FRAME_HEIGHT
));
(
int
)
inputVideo
.
get
(
CV_CAP_PROP_FRAME_HEIGHT
));
VideoWriter
outputVideo
;
// Open the output
VideoWriter
outputVideo
;
// Open the output
if
(
askOutputType
)
if
(
askOutputType
)
outputVideo
.
open
(
NAME
,
ex
=-
1
,
inputVideo
.
get
(
CV_CAP_PROP_FPS
),
S
,
true
);
outputVideo
.
open
(
NAME
,
ex
=-
1
,
inputVideo
.
get
(
CV_CAP_PROP_FPS
),
S
,
true
);
else
else
outputVideo
.
open
(
NAME
,
ex
,
inputVideo
.
get
(
CV_CAP_PROP_FPS
),
S
,
true
);
outputVideo
.
open
(
NAME
,
ex
,
inputVideo
.
get
(
CV_CAP_PROP_FPS
),
S
,
true
);
if
(
!
outputVideo
.
isOpened
())
if
(
!
outputVideo
.
isOpened
())
{
{
...
@@ -59,33 +61,29 @@ int main(int argc, char *argv[], char *window_name)
...
@@ -59,33 +61,29 @@ int main(int argc, char *argv[], char *window_name)
return
-
1
;
return
-
1
;
}
}
union
{
int
v
;
char
c
[
5
];}
uEx
;
uEx
.
v
=
ex
;
// From Int to char via union
uEx
.
c
[
4
]
=
'\0'
;
cout
<<
"Input frame resolution: Width="
<<
S
.
width
<<
" Height="
<<
S
.
height
cout
<<
"Input frame resolution: Width="
<<
S
.
width
<<
" Height="
<<
S
.
height
<<
" of nr#: "
<<
inputVideo
.
get
(
CV_CAP_PROP_FRAME_COUNT
)
<<
endl
;
<<
" of nr#: "
<<
inputVideo
.
get
(
CV_CAP_PROP_FRAME_COUNT
)
<<
endl
;
cout
<<
"Input codec type: "
<<
EXT
<<
endl
;
cout
<<
"Input codec type: "
<<
EXT
<<
endl
;
int
channel
=
2
;
// Select the channel to save
int
channel
=
2
;
// Select the channel to save
switch
(
argv
[
2
][
0
])
switch
(
argv
[
2
][
0
])
{
{
case
'R'
:
{
channel
=
2
;
break
;}
case
'R'
:
channel
=
2
;
break
;
case
'G'
:
{
channel
=
1
;
break
;}
case
'G'
:
channel
=
1
;
break
;
case
'B'
:
{
channel
=
0
;
break
;}
case
'B'
:
channel
=
0
;
break
;
}
}
Mat
src
,
res
;
Mat
src
,
res
;
vector
<
Mat
>
spl
;
vector
<
Mat
>
spl
;
while
(
true
)
//Show the image captured in the window and repeat
for
(;;
)
//Show the image captured in the window and repeat
{
{
inputVideo
>>
src
;
// read
inputVideo
>>
src
;
// read
if
(
src
.
empty
())
break
;
// check if at end
if
(
src
.
empty
())
break
;
// check if at end
split
(
src
,
spl
);
// process - extract only the correct channel
split
(
src
,
spl
);
// process - extract only the correct channel
for
(
int
i
=
0
;
i
<
3
;
++
i
)
for
(
int
i
=
0
;
i
<
3
;
++
i
)
if
(
i
!=
channel
)
if
(
i
!=
channel
)
spl
[
i
]
=
Mat
::
zeros
(
S
,
spl
[
0
].
type
());
spl
[
i
]
=
Mat
::
zeros
(
S
,
spl
[
0
].
type
());
merge
(
spl
,
res
);
merge
(
spl
,
res
);
//outputVideo.write(res); //save or
//outputVideo.write(res); //save or
...
@@ -94,4 +92,4 @@ int main(int argc, char *argv[], char *window_name)
...
@@ -94,4 +92,4 @@ int main(int argc, char *argv[], char *window_name)
cout
<<
"Finished writing"
<<
endl
;
cout
<<
"Finished writing"
<<
endl
;
return
0
;
return
0
;
}
}
\ No newline at end of file
samples/cpp/tutorial_code/Histograms_Matching/EqualizeHist_Demo.cpp
View file @
a2185075
...
@@ -15,12 +15,12 @@ using namespace std;
...
@@ -15,12 +15,12 @@ using namespace std;
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
Mat
src
,
dst
;
Mat
src
,
dst
;
char
*
source_window
=
"Source image"
;
c
onst
c
har
*
source_window
=
"Source image"
;
char
*
equalized_window
=
"Equalized Image"
;
c
onst
c
har
*
equalized_window
=
"Equalized Image"
;
/// Load image
/// Load image
src
=
imread
(
argv
[
1
],
1
);
src
=
imread
(
argv
[
1
],
1
);
...
...
samples/cpp/tutorial_code/Histograms_Matching/MatchTemplate_Demo.cpp
View file @
a2185075
...
@@ -14,8 +14,8 @@ using namespace cv;
...
@@ -14,8 +14,8 @@ using namespace cv;
/// Global Variables
/// Global Variables
Mat
img
;
Mat
templ
;
Mat
result
;
Mat
img
;
Mat
templ
;
Mat
result
;
char
*
image_window
=
"Source Image"
;
c
onst
c
har
*
image_window
=
"Source Image"
;
char
*
result_window
=
"Result window"
;
c
onst
c
har
*
result_window
=
"Result window"
;
int
match_method
;
int
match_method
;
int
max_Trackbar
=
5
;
int
max_Trackbar
=
5
;
...
@@ -26,7 +26,7 @@ void MatchingMethod( int, void* );
...
@@ -26,7 +26,7 @@ void MatchingMethod( int, void* );
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Load image and template
/// Load image and template
img
=
imread
(
argv
[
1
],
1
);
img
=
imread
(
argv
[
1
],
1
);
...
@@ -37,7 +37,7 @@ int main( int argc, char** argv )
...
@@ -37,7 +37,7 @@ int main( int argc, char** argv )
namedWindow
(
result_window
,
CV_WINDOW_AUTOSIZE
);
namedWindow
(
result_window
,
CV_WINDOW_AUTOSIZE
);
/// Create Trackbar
/// Create Trackbar
char
*
trackbar_label
=
"Method:
\n
0: SQDIFF
\n
1: SQDIFF NORMED
\n
2: TM CCORR
\n
3: TM CCORR NORMED
\n
4: TM COEFF
\n
5: TM COEFF NORMED"
;
c
onst
c
har
*
trackbar_label
=
"Method:
\n
0: SQDIFF
\n
1: SQDIFF NORMED
\n
2: TM CCORR
\n
3: TM CCORR NORMED
\n
4: TM COEFF
\n
5: TM COEFF NORMED"
;
createTrackbar
(
trackbar_label
,
image_window
,
&
match_method
,
max_Trackbar
,
MatchingMethod
);
createTrackbar
(
trackbar_label
,
image_window
,
&
match_method
,
max_Trackbar
,
MatchingMethod
);
MatchingMethod
(
0
,
0
);
MatchingMethod
(
0
,
0
);
...
...
samples/cpp/tutorial_code/Histograms_Matching/calcBackProject_Demo1.cpp
View file @
a2185075
...
@@ -23,7 +23,7 @@ void Hist_and_Backproj(int, void* );
...
@@ -23,7 +23,7 @@ void Hist_and_Backproj(int, void* );
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Read the image
/// Read the image
src
=
imread
(
argv
[
1
],
1
);
src
=
imread
(
argv
[
1
],
1
);
...
@@ -36,7 +36,7 @@ int main( int argc, char** argv )
...
@@ -36,7 +36,7 @@ int main( int argc, char** argv )
mixChannels
(
&
hsv
,
1
,
&
hue
,
1
,
ch
,
1
);
mixChannels
(
&
hsv
,
1
,
&
hue
,
1
,
ch
,
1
);
/// Create Trackbar to enter the number of bins
/// Create Trackbar to enter the number of bins
char
*
window_image
=
"Source image"
;
c
onst
c
har
*
window_image
=
"Source image"
;
namedWindow
(
window_image
,
CV_WINDOW_AUTOSIZE
);
namedWindow
(
window_image
,
CV_WINDOW_AUTOSIZE
);
createTrackbar
(
"* Hue bins: "
,
window_image
,
&
bins
,
180
,
Hist_and_Backproj
);
createTrackbar
(
"* Hue bins: "
,
window_image
,
&
bins
,
180
,
Hist_and_Backproj
);
Hist_and_Backproj
(
0
,
0
);
Hist_and_Backproj
(
0
,
0
);
...
...
samples/cpp/tutorial_code/Histograms_Matching/calcBackProject_Demo2.cpp
View file @
a2185075
...
@@ -17,7 +17,7 @@ Mat src; Mat hsv;
...
@@ -17,7 +17,7 @@ Mat src; Mat hsv;
Mat
mask
;
Mat
mask
;
int
lo
=
20
;
int
up
=
20
;
int
lo
=
20
;
int
up
=
20
;
char
*
window_image
=
"Source image"
;
c
onst
c
har
*
window_image
=
"Source image"
;
/// Function Headers
/// Function Headers
void
Hist_and_Backproj
(
);
void
Hist_and_Backproj
(
);
...
@@ -26,7 +26,7 @@ void pickPoint (int event, int x, int y, int, void* );
...
@@ -26,7 +26,7 @@ void pickPoint (int event, int x, int y, int, void* );
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Read the image
/// Read the image
src
=
imread
(
argv
[
1
],
1
);
src
=
imread
(
argv
[
1
],
1
);
...
...
samples/cpp/tutorial_code/Histograms_Matching/calcHist_Demo.cpp
View file @
a2185075
...
@@ -15,7 +15,7 @@ using namespace cv;
...
@@ -15,7 +15,7 @@ using namespace cv;
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
Mat
src
,
dst
;
Mat
src
,
dst
;
...
...
samples/cpp/tutorial_code/ImgProc/AddingImages.cpp
View file @
a2185075
...
@@ -4,8 +4,7 @@
...
@@ -4,8 +4,7 @@
* @author OpenCV team
* @author OpenCV team
*/
*/
#include <cv.h>
#include "opencv2/highgui/highgui.hpp"
#include <highgui.h>
#include <iostream>
#include <iostream>
using
namespace
cv
;
using
namespace
cv
;
...
@@ -14,7 +13,7 @@ using namespace cv;
...
@@ -14,7 +13,7 @@ using namespace cv;
* @function main
* @function main
* @brief Main function
* @brief Main function
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
void
)
{
{
double
alpha
=
0.5
;
double
beta
;
double
input
;
double
alpha
=
0.5
;
double
beta
;
double
input
;
...
@@ -35,8 +34,8 @@ int main( int argc, char** argv )
...
@@ -35,8 +34,8 @@ int main( int argc, char** argv )
src1
=
imread
(
"../images/LinuxLogo.jpg"
);
src1
=
imread
(
"../images/LinuxLogo.jpg"
);
src2
=
imread
(
"../images/WindowsLogo.jpg"
);
src2
=
imread
(
"../images/WindowsLogo.jpg"
);
if
(
!
src1
.
data
)
{
printf
(
"Error loading src1
\n
"
)
;
return
-
1
;
}
if
(
!
src1
.
data
)
{
std
::
cout
<<
"Error loading src1"
<<
std
::
endl
;
return
-
1
;
}
if
(
!
src2
.
data
)
{
printf
(
"Error loading src2
\n
"
)
;
return
-
1
;
}
if
(
!
src2
.
data
)
{
std
::
cout
<<
"Error loading src2"
<<
std
::
endl
;
return
-
1
;
}
/// Create Windows
/// Create Windows
namedWindow
(
"Linear Blend"
,
1
);
namedWindow
(
"Linear Blend"
,
1
);
...
...
samples/cpp/tutorial_code/ImgProc/BasicLinearTransforms.cpp
View file @
a2185075
...
@@ -4,8 +4,7 @@
...
@@ -4,8 +4,7 @@
* @author OpenCV team
* @author OpenCV team
*/
*/
#include <cv.h>
#include "opencv2/highgui/highgui.hpp"
#include <highgui.h>
#include <iostream>
#include <iostream>
using
namespace
cv
;
using
namespace
cv
;
...
@@ -17,7 +16,7 @@ int beta; /**< Simple brightness control */
...
@@ -17,7 +16,7 @@ int beta; /**< Simple brightness control */
* @function main
* @function main
* @brief Main function
* @brief Main function
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Read image given by user
/// Read image given by user
Mat
image
=
imread
(
argv
[
1
]
);
Mat
image
=
imread
(
argv
[
1
]
);
...
...
samples/cpp/tutorial_code/ImgProc/Morphology_1.cpp
View file @
a2185075
...
@@ -6,7 +6,6 @@
...
@@ -6,7 +6,6 @@
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "highgui.h"
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
...
@@ -29,7 +28,7 @@ void Dilation( int, void* );
...
@@ -29,7 +28,7 @@ void Dilation( int, void* );
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Load an image
/// Load an image
src
=
imread
(
argv
[
1
]
);
src
=
imread
(
argv
[
1
]
);
...
@@ -73,7 +72,7 @@ int main( int argc, char** argv )
...
@@ -73,7 +72,7 @@ int main( int argc, char** argv )
*/
*/
void
Erosion
(
int
,
void
*
)
void
Erosion
(
int
,
void
*
)
{
{
int
erosion_type
;
int
erosion_type
=
0
;
if
(
erosion_elem
==
0
){
erosion_type
=
MORPH_RECT
;
}
if
(
erosion_elem
==
0
){
erosion_type
=
MORPH_RECT
;
}
else
if
(
erosion_elem
==
1
){
erosion_type
=
MORPH_CROSS
;
}
else
if
(
erosion_elem
==
1
){
erosion_type
=
MORPH_CROSS
;
}
else
if
(
erosion_elem
==
2
)
{
erosion_type
=
MORPH_ELLIPSE
;
}
else
if
(
erosion_elem
==
2
)
{
erosion_type
=
MORPH_ELLIPSE
;
}
...
@@ -91,7 +90,7 @@ void Erosion( int, void* )
...
@@ -91,7 +90,7 @@ void Erosion( int, void* )
*/
*/
void
Dilation
(
int
,
void
*
)
void
Dilation
(
int
,
void
*
)
{
{
int
dilation_type
;
int
dilation_type
=
0
;
if
(
dilation_elem
==
0
){
dilation_type
=
MORPH_RECT
;
}
if
(
dilation_elem
==
0
){
dilation_type
=
MORPH_RECT
;
}
else
if
(
dilation_elem
==
1
){
dilation_type
=
MORPH_CROSS
;
}
else
if
(
dilation_elem
==
1
){
dilation_type
=
MORPH_CROSS
;
}
else
if
(
dilation_elem
==
2
)
{
dilation_type
=
MORPH_ELLIPSE
;
}
else
if
(
dilation_elem
==
2
)
{
dilation_type
=
MORPH_ELLIPSE
;
}
...
...
samples/cpp/tutorial_code/ImgProc/Morphology_2.cpp
View file @
a2185075
...
@@ -21,7 +21,7 @@ int const max_operator = 4;
...
@@ -21,7 +21,7 @@ int const max_operator = 4;
int
const
max_elem
=
2
;
int
const
max_elem
=
2
;
int
const
max_kernel_size
=
21
;
int
const
max_kernel_size
=
21
;
char
*
window_name
=
"Morphology Transformations Demo"
;
c
onst
c
har
*
window_name
=
"Morphology Transformations Demo"
;
/** Function Headers */
/** Function Headers */
...
@@ -30,7 +30,7 @@ void Morphology_Operations( int, void* );
...
@@ -30,7 +30,7 @@ void Morphology_Operations( int, void* );
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Load an image
/// Load an image
src
=
imread
(
argv
[
1
]
);
src
=
imread
(
argv
[
1
]
);
...
...
samples/cpp/tutorial_code/ImgProc/Pyramids.cpp
View file @
a2185075
...
@@ -15,13 +15,13 @@ using namespace cv;
...
@@ -15,13 +15,13 @@ using namespace cv;
/// Global variables
/// Global variables
Mat
src
,
dst
,
tmp
;
Mat
src
,
dst
,
tmp
;
char
*
window_name
=
"Pyramids Demo"
;
c
onst
c
har
*
window_name
=
"Pyramids Demo"
;
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
void
)
{
{
/// General instructions
/// General instructions
printf
(
"
\n
Zoom In-Out demo
\n
"
);
printf
(
"
\n
Zoom In-Out demo
\n
"
);
...
@@ -44,7 +44,7 @@ int main( int argc, char** argv )
...
@@ -44,7 +44,7 @@ int main( int argc, char** argv )
imshow
(
window_name
,
dst
);
imshow
(
window_name
,
dst
);
/// Loop
/// Loop
while
(
true
)
for
(;;
)
{
{
int
c
;
int
c
;
c
=
waitKey
(
10
);
c
=
waitKey
(
10
);
...
...
samples/cpp/tutorial_code/ImgProc/Smoothing.cpp
View file @
a2185075
...
@@ -22,14 +22,14 @@ Mat src; Mat dst;
...
@@ -22,14 +22,14 @@ Mat src; Mat dst;
char
window_name
[]
=
"Smoothing Demo"
;
char
window_name
[]
=
"Smoothing Demo"
;
/// Function headers
/// Function headers
int
display_caption
(
char
*
caption
);
int
display_caption
(
c
onst
c
har
*
caption
);
int
display_dst
(
int
delay
);
int
display_dst
(
int
delay
);
/**
/**
* function main
* function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
void
)
{
{
namedWindow
(
window_name
,
CV_WINDOW_AUTOSIZE
);
namedWindow
(
window_name
,
CV_WINDOW_AUTOSIZE
);
...
@@ -84,7 +84,7 @@ int main( int argc, char** argv )
...
@@ -84,7 +84,7 @@ int main( int argc, char** argv )
/**
/**
* @function display_caption
* @function display_caption
*/
*/
int
display_caption
(
char
*
caption
)
int
display_caption
(
c
onst
c
har
*
caption
)
{
{
dst
=
Mat
::
zeros
(
src
.
size
(),
src
.
type
()
);
dst
=
Mat
::
zeros
(
src
.
size
(),
src
.
type
()
);
putText
(
dst
,
caption
,
putText
(
dst
,
caption
,
...
...
samples/cpp/tutorial_code/ImgProc/Threshold.cpp
View file @
a2185075
...
@@ -20,10 +20,10 @@ int const max_type = 4;
...
@@ -20,10 +20,10 @@ int const max_type = 4;
int
const
max_BINARY_value
=
255
;
int
const
max_BINARY_value
=
255
;
Mat
src
,
src_gray
,
dst
;
Mat
src
,
src_gray
,
dst
;
char
*
window_name
=
"Threshold Demo"
;
c
onst
c
har
*
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"
;
c
onst
c
har
*
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"
;
c
onst
c
har
*
trackbar_value
=
"Value"
;
/// Function headers
/// Function headers
void
Threshold_Demo
(
int
,
void
*
);
void
Threshold_Demo
(
int
,
void
*
);
...
@@ -31,7 +31,7 @@ void Threshold_Demo( int, void* );
...
@@ -31,7 +31,7 @@ void Threshold_Demo( int, void* );
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Load an image
/// Load an image
src
=
imread
(
argv
[
1
],
1
);
src
=
imread
(
argv
[
1
],
1
);
...
@@ -55,7 +55,7 @@ int main( int argc, char** argv )
...
@@ -55,7 +55,7 @@ int main( int argc, char** argv )
Threshold_Demo
(
0
,
0
);
Threshold_Demo
(
0
,
0
);
/// Wait until user finishes program
/// Wait until user finishes program
while
(
true
)
for
(;;
)
{
{
int
c
;
int
c
;
c
=
waitKey
(
20
);
c
=
waitKey
(
20
);
...
...
samples/cpp/tutorial_code/ImgTrans/CannyDetector_Demo.cpp
View file @
a2185075
...
@@ -21,13 +21,13 @@ int lowThreshold;
...
@@ -21,13 +21,13 @@ int lowThreshold;
int
const
max_lowThreshold
=
100
;
int
const
max_lowThreshold
=
100
;
int
ratio
=
3
;
int
ratio
=
3
;
int
kernel_size
=
3
;
int
kernel_size
=
3
;
char
*
window_name
=
"Edge Map"
;
c
onst
c
har
*
window_name
=
"Edge Map"
;
/**
/**
* @function CannyThreshold
* @function CannyThreshold
* @brief Trackbar callback - Canny thresholds input with a ratio 1:3
* @brief Trackbar callback - Canny thresholds input with a ratio 1:3
*/
*/
void
CannyThreshold
(
int
,
void
*
)
static
void
CannyThreshold
(
int
,
void
*
)
{
{
/// Reduce noise with a kernel 3x3
/// Reduce noise with a kernel 3x3
blur
(
src_gray
,
detected_edges
,
Size
(
3
,
3
)
);
blur
(
src_gray
,
detected_edges
,
Size
(
3
,
3
)
);
...
@@ -46,7 +46,7 @@ void CannyThreshold(int, void*)
...
@@ -46,7 +46,7 @@ void CannyThreshold(int, void*)
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Load an image
/// Load an image
src
=
imread
(
argv
[
1
]
);
src
=
imread
(
argv
[
1
]
);
...
...
samples/cpp/tutorial_code/ImgTrans/Geometric_Transforms_Demo.cpp
View file @
a2185075
...
@@ -13,14 +13,14 @@ using namespace cv;
...
@@ -13,14 +13,14 @@ using namespace cv;
using
namespace
std
;
using
namespace
std
;
/// Global variables
/// Global variables
char
*
source_window
=
"Source image"
;
c
onst
c
har
*
source_window
=
"Source image"
;
char
*
warp_window
=
"Warp"
;
c
onst
c
har
*
warp_window
=
"Warp"
;
char
*
warp_rotate_window
=
"Warp + Rotate"
;
c
onst
c
har
*
warp_rotate_window
=
"Warp + Rotate"
;
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
Point2f
srcTri
[
3
];
Point2f
srcTri
[
3
];
Point2f
dstTri
[
3
];
Point2f
dstTri
[
3
];
...
@@ -37,12 +37,12 @@ int main( int argc, char** argv )
...
@@ -37,12 +37,12 @@ int main( int argc, char** argv )
/// Set your 3 points to calculate the Affine Transform
/// Set your 3 points to calculate the Affine Transform
srcTri
[
0
]
=
Point2f
(
0
,
0
);
srcTri
[
0
]
=
Point2f
(
0
,
0
);
srcTri
[
1
]
=
Point2f
(
src
.
cols
-
1
,
0
);
srcTri
[
1
]
=
Point2f
(
src
.
cols
-
1
.
f
,
0
);
srcTri
[
2
]
=
Point2f
(
0
,
src
.
rows
-
1
);
srcTri
[
2
]
=
Point2f
(
0
,
src
.
rows
-
1
.
f
);
dstTri
[
0
]
=
Point2f
(
src
.
cols
*
0.0
,
src
.
rows
*
0.33
);
dstTri
[
0
]
=
Point2f
(
src
.
cols
*
0.0
f
,
src
.
rows
*
0.33
f
);
dstTri
[
1
]
=
Point2f
(
src
.
cols
*
0.85
,
src
.
rows
*
0.25
);
dstTri
[
1
]
=
Point2f
(
src
.
cols
*
0.85
f
,
src
.
rows
*
0.25
f
);
dstTri
[
2
]
=
Point2f
(
src
.
cols
*
0.15
,
src
.
rows
*
0.7
);
dstTri
[
2
]
=
Point2f
(
src
.
cols
*
0.15
f
,
src
.
rows
*
0.7
f
);
/// Get the Affine Transform
/// Get the Affine Transform
warp_mat
=
getAffineTransform
(
srcTri
,
dstTri
);
warp_mat
=
getAffineTransform
(
srcTri
,
dstTri
);
...
...
samples/cpp/tutorial_code/ImgTrans/HoughCircle_Demo.cpp
View file @
a2185075
...
@@ -14,7 +14,7 @@ using namespace cv;
...
@@ -14,7 +14,7 @@ using namespace cv;
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
Mat
src
,
src_gray
;
Mat
src
,
src_gray
;
...
...
samples/cpp/tutorial_code/ImgTrans/HoughLines_Demo.cpp
View file @
a2185075
...
@@ -21,8 +21,8 @@ Mat standard_hough, probabilistic_hough;
...
@@ -21,8 +21,8 @@ Mat standard_hough, probabilistic_hough;
int
min_threshold
=
50
;
int
min_threshold
=
50
;
int
max_trackbar
=
150
;
int
max_trackbar
=
150
;
char
*
standard_name
=
"Standard Hough Lines Demo"
;
c
onst
c
har
*
standard_name
=
"Standard Hough Lines Demo"
;
char
*
probabilistic_name
=
"Probabilistic Hough Lines Demo"
;
c
onst
c
har
*
probabilistic_name
=
"Probabilistic Hough Lines Demo"
;
int
s_trackbar
=
max_trackbar
;
int
s_trackbar
=
max_trackbar
;
int
p_trackbar
=
max_trackbar
;
int
p_trackbar
=
max_trackbar
;
...
@@ -35,7 +35,7 @@ void Probabilistic_Hough( int, void* );
...
@@ -35,7 +35,7 @@ void Probabilistic_Hough( int, void* );
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Read the image
/// Read the image
src
=
imread
(
argv
[
1
],
1
);
src
=
imread
(
argv
[
1
],
1
);
...
@@ -91,7 +91,7 @@ void Standard_Hough( int, void* )
...
@@ -91,7 +91,7 @@ void Standard_Hough( int, void* )
HoughLines
(
edges
,
s_lines
,
1
,
CV_PI
/
180
,
min_threshold
+
s_trackbar
,
0
,
0
);
HoughLines
(
edges
,
s_lines
,
1
,
CV_PI
/
180
,
min_threshold
+
s_trackbar
,
0
,
0
);
/// Show the result
/// Show the result
for
(
in
t
i
=
0
;
i
<
s_lines
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
s_lines
.
size
();
i
++
)
{
{
float
r
=
s_lines
[
i
][
0
],
t
=
s_lines
[
i
][
1
];
float
r
=
s_lines
[
i
][
0
],
t
=
s_lines
[
i
][
1
];
double
cos_t
=
cos
(
t
),
sin_t
=
sin
(
t
);
double
cos_t
=
cos
(
t
),
sin_t
=
sin
(
t
);
...
...
samples/cpp/tutorial_code/ImgTrans/Laplace_Demo.cpp
View file @
a2185075
...
@@ -14,7 +14,7 @@ using namespace cv;
...
@@ -14,7 +14,7 @@ using namespace cv;
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
Mat
src
,
src_gray
,
dst
;
Mat
src
,
src_gray
,
dst
;
...
@@ -22,9 +22,7 @@ int main( int argc, char** argv )
...
@@ -22,9 +22,7 @@ int main( int argc, char** argv )
int
scale
=
1
;
int
scale
=
1
;
int
delta
=
0
;
int
delta
=
0
;
int
ddepth
=
CV_16S
;
int
ddepth
=
CV_16S
;
char
*
window_name
=
"Laplace Demo"
;
const
char
*
window_name
=
"Laplace Demo"
;
int
c
;
/// Load an image
/// Load an image
src
=
imread
(
argv
[
1
]
);
src
=
imread
(
argv
[
1
]
);
...
...
samples/cpp/tutorial_code/ImgTrans/Remap_Demo.cpp
View file @
a2185075
...
@@ -14,7 +14,7 @@ using namespace cv;
...
@@ -14,7 +14,7 @@ using namespace cv;
/// Global variables
/// Global variables
Mat
src
,
dst
;
Mat
src
,
dst
;
Mat
map_x
,
map_y
;
Mat
map_x
,
map_y
;
char
*
remap_window
=
"Remap demo"
;
c
onst
c
har
*
remap_window
=
"Remap demo"
;
int
ind
=
0
;
int
ind
=
0
;
/// Function Headers
/// Function Headers
...
@@ -23,7 +23,7 @@ void update_map( void );
...
@@ -23,7 +23,7 @@ void update_map( void );
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Load the image
/// Load the image
src
=
imread
(
argv
[
1
],
1
);
src
=
imread
(
argv
[
1
],
1
);
...
@@ -37,7 +37,7 @@ int main( int argc, char** argv )
...
@@ -37,7 +37,7 @@ int main( int argc, char** argv )
namedWindow
(
remap_window
,
CV_WINDOW_AUTOSIZE
);
namedWindow
(
remap_window
,
CV_WINDOW_AUTOSIZE
);
/// Loop
/// Loop
while
(
true
)
for
(;;
)
{
{
/// Each 1 sec. Press ESC to exit the program
/// Each 1 sec. Press ESC to exit the program
int
c
=
waitKey
(
1000
);
int
c
=
waitKey
(
1000
);
...
@@ -71,8 +71,8 @@ void update_map( void )
...
@@ -71,8 +71,8 @@ void update_map( void )
case
0
:
case
0
:
if
(
i
>
src
.
cols
*
0.25
&&
i
<
src
.
cols
*
0.75
&&
j
>
src
.
rows
*
0.25
&&
j
<
src
.
rows
*
0.75
)
if
(
i
>
src
.
cols
*
0.25
&&
i
<
src
.
cols
*
0.75
&&
j
>
src
.
rows
*
0.25
&&
j
<
src
.
rows
*
0.75
)
{
{
map_x
.
at
<
float
>
(
j
,
i
)
=
2
*
(
i
-
src
.
cols
*
0.25
)
+
0.5
;
map_x
.
at
<
float
>
(
j
,
i
)
=
2
*
(
i
-
src
.
cols
*
0.25
f
)
+
0.5
f
;
map_y
.
at
<
float
>
(
j
,
i
)
=
2
*
(
j
-
src
.
rows
*
0.25
)
+
0.5
;
map_y
.
at
<
float
>
(
j
,
i
)
=
2
*
(
j
-
src
.
rows
*
0.25
f
)
+
0.5
f
;
}
}
else
else
{
map_x
.
at
<
float
>
(
j
,
i
)
=
0
;
{
map_x
.
at
<
float
>
(
j
,
i
)
=
0
;
...
@@ -80,16 +80,16 @@ void update_map( void )
...
@@ -80,16 +80,16 @@ void update_map( void )
}
}
break
;
break
;
case
1
:
case
1
:
map_x
.
at
<
float
>
(
j
,
i
)
=
i
;
map_x
.
at
<
float
>
(
j
,
i
)
=
(
float
)
i
;
map_y
.
at
<
float
>
(
j
,
i
)
=
src
.
rows
-
j
;
map_y
.
at
<
float
>
(
j
,
i
)
=
(
float
)(
src
.
rows
-
j
)
;
break
;
break
;
case
2
:
case
2
:
map_x
.
at
<
float
>
(
j
,
i
)
=
src
.
cols
-
i
;
map_x
.
at
<
float
>
(
j
,
i
)
=
(
float
)(
src
.
cols
-
i
)
;
map_y
.
at
<
float
>
(
j
,
i
)
=
j
;
map_y
.
at
<
float
>
(
j
,
i
)
=
(
float
)
j
;
break
;
break
;
case
3
:
case
3
:
map_x
.
at
<
float
>
(
j
,
i
)
=
src
.
cols
-
i
;
map_x
.
at
<
float
>
(
j
,
i
)
=
(
float
)(
src
.
cols
-
i
)
;
map_y
.
at
<
float
>
(
j
,
i
)
=
src
.
rows
-
j
;
map_y
.
at
<
float
>
(
j
,
i
)
=
(
float
)(
src
.
rows
-
j
)
;
break
;
break
;
}
// end of switch
}
// end of switch
}
}
...
...
samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp
View file @
a2185075
...
@@ -14,18 +14,16 @@ using namespace cv;
...
@@ -14,18 +14,16 @@ using namespace cv;
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
Mat
src
,
src_gray
;
Mat
src
,
src_gray
;
Mat
grad
;
Mat
grad
;
char
*
window_name
=
"Sobel Demo - Simple Edge Detector"
;
c
onst
c
har
*
window_name
=
"Sobel Demo - Simple Edge Detector"
;
int
scale
=
1
;
int
scale
=
1
;
int
delta
=
0
;
int
delta
=
0
;
int
ddepth
=
CV_16S
;
int
ddepth
=
CV_16S
;
int
c
;
/// Load an image
/// Load an image
src
=
imread
(
argv
[
1
]
);
src
=
imread
(
argv
[
1
]
);
...
...
samples/cpp/tutorial_code/ImgTrans/copyMakeBorder_demo.cpp
View file @
a2185075
...
@@ -16,13 +16,13 @@ Mat src, dst;
...
@@ -16,13 +16,13 @@ Mat src, dst;
int
top
,
bottom
,
left
,
right
;
int
top
,
bottom
,
left
,
right
;
int
borderType
;
int
borderType
;
Scalar
value
;
Scalar
value
;
char
*
window_name
=
"copyMakeBorder Demo"
;
c
onst
c
har
*
window_name
=
"copyMakeBorder Demo"
;
RNG
rng
(
12345
);
RNG
rng
(
12345
);
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
int
c
;
int
c
;
...
@@ -31,8 +31,9 @@ int main( int argc, char** argv )
...
@@ -31,8 +31,9 @@ int main( int argc, char** argv )
src
=
imread
(
argv
[
1
]
);
src
=
imread
(
argv
[
1
]
);
if
(
!
src
.
data
)
if
(
!
src
.
data
)
{
return
-
1
;
{
printf
(
" No data entered, please enter the path to an image file
\n
"
);
printf
(
" No data entered, please enter the path to an image file
\n
"
);
return
-
1
;
}
}
/// Brief how-to for this program
/// Brief how-to for this program
...
@@ -52,7 +53,7 @@ int main( int argc, char** argv )
...
@@ -52,7 +53,7 @@ int main( int argc, char** argv )
imshow
(
window_name
,
dst
);
imshow
(
window_name
,
dst
);
while
(
true
)
for
(;;
)
{
{
c
=
waitKey
(
500
);
c
=
waitKey
(
500
);
...
...
samples/cpp/tutorial_code/ImgTrans/filter2D_demo.cpp
View file @
a2185075
...
@@ -14,7 +14,7 @@ using namespace cv;
...
@@ -14,7 +14,7 @@ using namespace cv;
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Declare variables
/// Declare variables
Mat
src
,
dst
;
Mat
src
,
dst
;
...
@@ -24,7 +24,7 @@ int main ( int argc, char** argv )
...
@@ -24,7 +24,7 @@ int main ( int argc, char** argv )
double
delta
;
double
delta
;
int
ddepth
;
int
ddepth
;
int
kernel_size
;
int
kernel_size
;
char
*
window_name
=
"filter2D Demo"
;
c
onst
c
har
*
window_name
=
"filter2D Demo"
;
int
c
;
int
c
;
...
@@ -44,7 +44,7 @@ int main ( int argc, char** argv )
...
@@ -44,7 +44,7 @@ int main ( int argc, char** argv )
/// Loop - Will filter the image with different kernel sizes each 0.5 seconds
/// Loop - Will filter the image with different kernel sizes each 0.5 seconds
int
ind
=
0
;
int
ind
=
0
;
while
(
true
)
for
(;;
)
{
{
c
=
waitKey
(
500
);
c
=
waitKey
(
500
);
/// Press 'ESC' to exit the program
/// Press 'ESC' to exit the program
...
...
samples/cpp/tutorial_code/ShapeDescriptors/findContours_demo.cpp
View file @
a2185075
...
@@ -24,7 +24,7 @@ void thresh_callback(int, void* );
...
@@ -24,7 +24,7 @@ void thresh_callback(int, void* );
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Load source image and convert it to gray
/// Load source image and convert it to gray
src
=
imread
(
argv
[
1
],
1
);
src
=
imread
(
argv
[
1
],
1
);
...
@@ -34,7 +34,7 @@ int main( int argc, char** argv )
...
@@ -34,7 +34,7 @@ int main( int argc, char** argv )
blur
(
src_gray
,
src_gray
,
Size
(
3
,
3
)
);
blur
(
src_gray
,
src_gray
,
Size
(
3
,
3
)
);
/// Create Window
/// Create Window
char
*
source_window
=
"Source"
;
c
onst
c
har
*
source_window
=
"Source"
;
namedWindow
(
source_window
,
CV_WINDOW_AUTOSIZE
);
namedWindow
(
source_window
,
CV_WINDOW_AUTOSIZE
);
imshow
(
source_window
,
src
);
imshow
(
source_window
,
src
);
...
@@ -61,10 +61,10 @@ void thresh_callback(int, void* )
...
@@ -61,10 +61,10 @@ void thresh_callback(int, void* )
/// Draw contours
/// Draw contours
Mat
drawing
=
Mat
::
zeros
(
canny_output
.
size
(),
CV_8UC3
);
Mat
drawing
=
Mat
::
zeros
(
canny_output
.
size
(),
CV_8UC3
);
for
(
in
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
{
{
Scalar
color
=
Scalar
(
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
)
);
Scalar
color
=
Scalar
(
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
)
);
drawContours
(
drawing
,
contours
,
i
,
color
,
2
,
8
,
hierarchy
,
0
,
Point
()
);
drawContours
(
drawing
,
contours
,
(
int
)
i
,
color
,
2
,
8
,
hierarchy
,
0
,
Point
()
);
}
}
/// Show in a window
/// Show in a window
...
...
samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo1.cpp
View file @
a2185075
...
@@ -24,7 +24,7 @@ void thresh_callback(int, void* );
...
@@ -24,7 +24,7 @@ void thresh_callback(int, void* );
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Load source image and convert it to gray
/// Load source image and convert it to gray
src
=
imread
(
argv
[
1
],
1
);
src
=
imread
(
argv
[
1
],
1
);
...
@@ -34,7 +34,7 @@ int main( int argc, char** argv )
...
@@ -34,7 +34,7 @@ int main( int argc, char** argv )
blur
(
src_gray
,
src_gray
,
Size
(
3
,
3
)
);
blur
(
src_gray
,
src_gray
,
Size
(
3
,
3
)
);
/// Create Window
/// Create Window
char
*
source_window
=
"Source"
;
c
onst
c
har
*
source_window
=
"Source"
;
namedWindow
(
source_window
,
CV_WINDOW_AUTOSIZE
);
namedWindow
(
source_window
,
CV_WINDOW_AUTOSIZE
);
imshow
(
source_window
,
src
);
imshow
(
source_window
,
src
);
...
@@ -65,7 +65,7 @@ void thresh_callback(int, void* )
...
@@ -65,7 +65,7 @@ void thresh_callback(int, void* )
vector
<
Point2f
>
center
(
contours
.
size
()
);
vector
<
Point2f
>
center
(
contours
.
size
()
);
vector
<
float
>
radius
(
contours
.
size
()
);
vector
<
float
>
radius
(
contours
.
size
()
);
for
(
in
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
{
approxPolyDP
(
Mat
(
contours
[
i
]),
contours_poly
[
i
],
3
,
true
);
{
approxPolyDP
(
Mat
(
contours
[
i
]),
contours_poly
[
i
],
3
,
true
);
boundRect
[
i
]
=
boundingRect
(
Mat
(
contours_poly
[
i
])
);
boundRect
[
i
]
=
boundingRect
(
Mat
(
contours_poly
[
i
])
);
minEnclosingCircle
(
contours_poly
[
i
],
center
[
i
],
radius
[
i
]
);
minEnclosingCircle
(
contours_poly
[
i
],
center
[
i
],
radius
[
i
]
);
...
@@ -74,10 +74,10 @@ void thresh_callback(int, void* )
...
@@ -74,10 +74,10 @@ void thresh_callback(int, void* )
/// Draw polygonal contour + bonding rects + circles
/// Draw polygonal contour + bonding rects + circles
Mat
drawing
=
Mat
::
zeros
(
threshold_output
.
size
(),
CV_8UC3
);
Mat
drawing
=
Mat
::
zeros
(
threshold_output
.
size
(),
CV_8UC3
);
for
(
in
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
{
{
Scalar
color
=
Scalar
(
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
)
);
Scalar
color
=
Scalar
(
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
)
);
drawContours
(
drawing
,
contours_poly
,
i
,
color
,
1
,
8
,
vector
<
Vec4i
>
(),
0
,
Point
()
);
drawContours
(
drawing
,
contours_poly
,
(
int
)
i
,
color
,
1
,
8
,
vector
<
Vec4i
>
(),
0
,
Point
()
);
rectangle
(
drawing
,
boundRect
[
i
].
tl
(),
boundRect
[
i
].
br
(),
color
,
2
,
8
,
0
);
rectangle
(
drawing
,
boundRect
[
i
].
tl
(),
boundRect
[
i
].
br
(),
color
,
2
,
8
,
0
);
circle
(
drawing
,
center
[
i
],
(
int
)
radius
[
i
],
color
,
2
,
8
,
0
);
circle
(
drawing
,
center
[
i
],
(
int
)
radius
[
i
],
color
,
2
,
8
,
0
);
}
}
...
...
samples/cpp/tutorial_code/ShapeDescriptors/generalContours_demo2.cpp
View file @
a2185075
...
@@ -24,7 +24,7 @@ void thresh_callback(int, void* );
...
@@ -24,7 +24,7 @@ void thresh_callback(int, void* );
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Load source image and convert it to gray
/// Load source image and convert it to gray
src
=
imread
(
argv
[
1
],
1
);
src
=
imread
(
argv
[
1
],
1
);
...
@@ -34,7 +34,7 @@ int main( int argc, char** argv )
...
@@ -34,7 +34,7 @@ int main( int argc, char** argv )
blur
(
src_gray
,
src_gray
,
Size
(
3
,
3
)
);
blur
(
src_gray
,
src_gray
,
Size
(
3
,
3
)
);
/// Create Window
/// Create Window
char
*
source_window
=
"Source"
;
c
onst
c
har
*
source_window
=
"Source"
;
namedWindow
(
source_window
,
CV_WINDOW_AUTOSIZE
);
namedWindow
(
source_window
,
CV_WINDOW_AUTOSIZE
);
imshow
(
source_window
,
src
);
imshow
(
source_window
,
src
);
...
@@ -63,7 +63,7 @@ void thresh_callback(int, void* )
...
@@ -63,7 +63,7 @@ void thresh_callback(int, void* )
vector
<
RotatedRect
>
minRect
(
contours
.
size
()
);
vector
<
RotatedRect
>
minRect
(
contours
.
size
()
);
vector
<
RotatedRect
>
minEllipse
(
contours
.
size
()
);
vector
<
RotatedRect
>
minEllipse
(
contours
.
size
()
);
for
(
in
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
{
minRect
[
i
]
=
minAreaRect
(
Mat
(
contours
[
i
])
);
{
minRect
[
i
]
=
minAreaRect
(
Mat
(
contours
[
i
])
);
if
(
contours
[
i
].
size
()
>
5
)
if
(
contours
[
i
].
size
()
>
5
)
{
minEllipse
[
i
]
=
fitEllipse
(
Mat
(
contours
[
i
])
);
}
{
minEllipse
[
i
]
=
fitEllipse
(
Mat
(
contours
[
i
])
);
}
...
@@ -71,11 +71,11 @@ void thresh_callback(int, void* )
...
@@ -71,11 +71,11 @@ void thresh_callback(int, void* )
/// Draw contours + rotated rects + ellipses
/// Draw contours + rotated rects + ellipses
Mat
drawing
=
Mat
::
zeros
(
threshold_output
.
size
(),
CV_8UC3
);
Mat
drawing
=
Mat
::
zeros
(
threshold_output
.
size
(),
CV_8UC3
);
for
(
in
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
{
{
Scalar
color
=
Scalar
(
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
)
);
Scalar
color
=
Scalar
(
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
)
);
// contour
// contour
drawContours
(
drawing
,
contours
,
i
,
color
,
1
,
8
,
vector
<
Vec4i
>
(),
0
,
Point
()
);
drawContours
(
drawing
,
contours
,
(
int
)
i
,
color
,
1
,
8
,
vector
<
Vec4i
>
(),
0
,
Point
()
);
// ellipse
// ellipse
ellipse
(
drawing
,
minEllipse
[
i
],
color
,
2
,
8
);
ellipse
(
drawing
,
minEllipse
[
i
],
color
,
2
,
8
);
// rotated rectangle
// rotated rectangle
...
...
samples/cpp/tutorial_code/ShapeDescriptors/hull_demo.cpp
View file @
a2185075
...
@@ -24,7 +24,7 @@ void thresh_callback(int, void* );
...
@@ -24,7 +24,7 @@ void thresh_callback(int, void* );
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Load source image and convert it to gray
/// Load source image and convert it to gray
src
=
imread
(
argv
[
1
],
1
);
src
=
imread
(
argv
[
1
],
1
);
...
@@ -34,7 +34,7 @@ int main( int argc, char** argv )
...
@@ -34,7 +34,7 @@ int main( int argc, char** argv )
blur
(
src_gray
,
src_gray
,
Size
(
3
,
3
)
);
blur
(
src_gray
,
src_gray
,
Size
(
3
,
3
)
);
/// Create Window
/// Create Window
char
*
source_window
=
"Source"
;
c
onst
c
har
*
source_window
=
"Source"
;
namedWindow
(
source_window
,
CV_WINDOW_AUTOSIZE
);
namedWindow
(
source_window
,
CV_WINDOW_AUTOSIZE
);
imshow
(
source_window
,
src
);
imshow
(
source_window
,
src
);
...
@@ -63,16 +63,16 @@ void thresh_callback(int, void* )
...
@@ -63,16 +63,16 @@ void thresh_callback(int, void* )
/// Find the convex hull object for each contour
/// Find the convex hull object for each contour
vector
<
vector
<
Point
>
>
hull
(
contours
.
size
()
);
vector
<
vector
<
Point
>
>
hull
(
contours
.
size
()
);
for
(
in
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
{
convexHull
(
Mat
(
contours
[
i
]),
hull
[
i
],
false
);
}
{
convexHull
(
Mat
(
contours
[
i
]),
hull
[
i
],
false
);
}
/// Draw contours + hull results
/// Draw contours + hull results
Mat
drawing
=
Mat
::
zeros
(
threshold_output
.
size
(),
CV_8UC3
);
Mat
drawing
=
Mat
::
zeros
(
threshold_output
.
size
(),
CV_8UC3
);
for
(
in
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
{
{
Scalar
color
=
Scalar
(
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
)
);
Scalar
color
=
Scalar
(
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
)
);
drawContours
(
drawing
,
contours
,
i
,
color
,
1
,
8
,
vector
<
Vec4i
>
(),
0
,
Point
()
);
drawContours
(
drawing
,
contours
,
(
int
)
i
,
color
,
1
,
8
,
vector
<
Vec4i
>
(),
0
,
Point
()
);
drawContours
(
drawing
,
hull
,
i
,
color
,
1
,
8
,
vector
<
Vec4i
>
(),
0
,
Point
()
);
drawContours
(
drawing
,
hull
,
(
int
)
i
,
color
,
1
,
8
,
vector
<
Vec4i
>
(),
0
,
Point
()
);
}
}
/// Show in a window
/// Show in a window
...
...
samples/cpp/tutorial_code/ShapeDescriptors/moments_demo.cpp
View file @
a2185075
...
@@ -24,7 +24,7 @@ void thresh_callback(int, void* );
...
@@ -24,7 +24,7 @@ void thresh_callback(int, void* );
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Load source image and convert it to gray
/// Load source image and convert it to gray
src
=
imread
(
argv
[
1
],
1
);
src
=
imread
(
argv
[
1
],
1
);
...
@@ -34,7 +34,7 @@ int main( int argc, char** argv )
...
@@ -34,7 +34,7 @@ int main( int argc, char** argv )
blur
(
src_gray
,
src_gray
,
Size
(
3
,
3
)
);
blur
(
src_gray
,
src_gray
,
Size
(
3
,
3
)
);
/// Create Window
/// Create Window
char
*
source_window
=
"Source"
;
c
onst
c
har
*
source_window
=
"Source"
;
namedWindow
(
source_window
,
CV_WINDOW_AUTOSIZE
);
namedWindow
(
source_window
,
CV_WINDOW_AUTOSIZE
);
imshow
(
source_window
,
src
);
imshow
(
source_window
,
src
);
...
@@ -61,20 +61,20 @@ void thresh_callback(int, void* )
...
@@ -61,20 +61,20 @@ void thresh_callback(int, void* )
/// Get the moments
/// Get the moments
vector
<
Moments
>
mu
(
contours
.
size
()
);
vector
<
Moments
>
mu
(
contours
.
size
()
);
for
(
in
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
{
mu
[
i
]
=
moments
(
contours
[
i
],
false
);
}
{
mu
[
i
]
=
moments
(
contours
[
i
],
false
);
}
/// Get the mass centers:
/// Get the mass centers:
vector
<
Point2f
>
mc
(
contours
.
size
()
);
vector
<
Point2f
>
mc
(
contours
.
size
()
);
for
(
in
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
{
mc
[
i
]
=
Point2f
(
mu
[
i
].
m10
/
mu
[
i
].
m00
,
mu
[
i
].
m01
/
mu
[
i
].
m00
);
}
{
mc
[
i
]
=
Point2f
(
static_cast
<
float
>
(
mu
[
i
].
m10
/
mu
[
i
].
m00
)
,
static_cast
<
float
>
(
mu
[
i
].
m01
/
mu
[
i
].
m00
)
);
}
/// Draw contours
/// Draw contours
Mat
drawing
=
Mat
::
zeros
(
canny_output
.
size
(),
CV_8UC3
);
Mat
drawing
=
Mat
::
zeros
(
canny_output
.
size
(),
CV_8UC3
);
for
(
in
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
{
{
Scalar
color
=
Scalar
(
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
)
);
Scalar
color
=
Scalar
(
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
)
);
drawContours
(
drawing
,
contours
,
i
,
color
,
2
,
8
,
hierarchy
,
0
,
Point
()
);
drawContours
(
drawing
,
contours
,
(
int
)
i
,
color
,
2
,
8
,
hierarchy
,
0
,
Point
()
);
circle
(
drawing
,
mc
[
i
],
4
,
color
,
-
1
,
8
,
0
);
circle
(
drawing
,
mc
[
i
],
4
,
color
,
-
1
,
8
,
0
);
}
}
...
@@ -84,11 +84,11 @@ void thresh_callback(int, void* )
...
@@ -84,11 +84,11 @@ void thresh_callback(int, void* )
/// Calculate the area with the moments 00 and compare with the result of the OpenCV function
/// Calculate the area with the moments 00 and compare with the result of the OpenCV function
printf
(
"
\t
Info: Area and Contour Length
\n
"
);
printf
(
"
\t
Info: Area and Contour Length
\n
"
);
for
(
in
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
contours
.
size
();
i
++
)
{
{
printf
(
" * Contour[%d] - Area (M_00) = %.2f - Area OpenCV: %.2f - Length: %.2f
\n
"
,
i
,
mu
[
i
].
m00
,
contourArea
(
contours
[
i
]),
arcLength
(
contours
[
i
],
true
)
);
printf
(
" * Contour[%d] - Area (M_00) = %.2f - Area OpenCV: %.2f - Length: %.2f
\n
"
,
(
int
)
i
,
mu
[
i
].
m00
,
contourArea
(
contours
[
i
]),
arcLength
(
contours
[
i
],
true
)
);
Scalar
color
=
Scalar
(
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
)
);
Scalar
color
=
Scalar
(
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
)
);
drawContours
(
drawing
,
contours
,
i
,
color
,
2
,
8
,
hierarchy
,
0
,
Point
()
);
drawContours
(
drawing
,
contours
,
(
int
)
i
,
color
,
2
,
8
,
hierarchy
,
0
,
Point
()
);
circle
(
drawing
,
mc
[
i
],
4
,
color
,
-
1
,
8
,
0
);
circle
(
drawing
,
mc
[
i
],
4
,
color
,
-
1
,
8
,
0
);
}
}
}
}
...
...
samples/cpp/tutorial_code/ShapeDescriptors/pointPolygonTest_demo.cpp
View file @
a2185075
...
@@ -16,7 +16,7 @@ using namespace std;
...
@@ -16,7 +16,7 @@ using namespace std;
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
void
)
{
{
/// Create an image
/// Create an image
const
int
r
=
100
;
const
int
r
=
100
;
...
@@ -25,12 +25,12 @@ int main( int argc, char** argv )
...
@@ -25,12 +25,12 @@ int main( int argc, char** argv )
/// Create a sequence of points to make a contour:
/// Create a sequence of points to make a contour:
vector
<
Point2f
>
vert
(
6
);
vector
<
Point2f
>
vert
(
6
);
vert
[
0
]
=
Point
(
1.5
*
r
,
1.34
*
r
);
vert
[
0
]
=
Point
(
3
*
r
/
2
,
static_cast
<
int
>
(
1.34
*
r
)
);
vert
[
1
]
=
Point
(
1
*
r
,
2
*
r
);
vert
[
1
]
=
Point
(
1
*
r
,
2
*
r
);
vert
[
2
]
=
Point
(
1.5
*
r
,
2.866
*
r
);
vert
[
2
]
=
Point
(
3
*
r
/
2
,
static_cast
<
int
>
(
2.866
*
r
)
);
vert
[
3
]
=
Point
(
2.5
*
r
,
2.866
*
r
);
vert
[
3
]
=
Point
(
5
*
r
/
2
,
static_cast
<
int
>
(
2.866
*
r
)
);
vert
[
4
]
=
Point
(
3
*
r
,
2
*
r
);
vert
[
4
]
=
Point
(
3
*
r
,
2
*
r
);
vert
[
5
]
=
Point
(
2.5
*
r
,
1.34
*
r
);
vert
[
5
]
=
Point
(
5
*
r
/
2
,
static_cast
<
int
>
(
1.34
*
r
)
);
/// Draw it in src
/// Draw it in src
for
(
int
j
=
0
;
j
<
6
;
j
++
)
for
(
int
j
=
0
;
j
<
6
;
j
++
)
...
@@ -47,7 +47,7 @@ int main( int argc, char** argv )
...
@@ -47,7 +47,7 @@ int main( int argc, char** argv )
for
(
int
j
=
0
;
j
<
src
.
rows
;
j
++
)
for
(
int
j
=
0
;
j
<
src
.
rows
;
j
++
)
{
for
(
int
i
=
0
;
i
<
src
.
cols
;
i
++
)
{
for
(
int
i
=
0
;
i
<
src
.
cols
;
i
++
)
{
raw_dist
.
at
<
float
>
(
j
,
i
)
=
pointPolygonTest
(
contours
[
0
],
Point2f
(
i
,
j
),
true
);
}
{
raw_dist
.
at
<
float
>
(
j
,
i
)
=
(
float
)
pointPolygonTest
(
contours
[
0
],
Point2f
((
float
)
i
,(
float
)
j
),
true
);
}
}
}
double
minVal
;
double
maxVal
;
double
minVal
;
double
maxVal
;
...
@@ -61,16 +61,16 @@ int main( int argc, char** argv )
...
@@ -61,16 +61,16 @@ int main( int argc, char** argv )
{
for
(
int
i
=
0
;
i
<
src
.
cols
;
i
++
)
{
for
(
int
i
=
0
;
i
<
src
.
cols
;
i
++
)
{
{
if
(
raw_dist
.
at
<
float
>
(
j
,
i
)
<
0
)
if
(
raw_dist
.
at
<
float
>
(
j
,
i
)
<
0
)
{
drawing
.
at
<
Vec3b
>
(
j
,
i
)[
0
]
=
255
-
(
int
)
abs
(
raw_dist
.
at
<
float
>
(
j
,
i
))
*
255
/
minVal
;
}
{
drawing
.
at
<
Vec3b
>
(
j
,
i
)[
0
]
=
(
uchar
)(
255
-
abs
(
raw_dist
.
at
<
float
>
(
j
,
i
))
*
255
/
minVal
)
;
}
else
if
(
raw_dist
.
at
<
float
>
(
j
,
i
)
>
0
)
else
if
(
raw_dist
.
at
<
float
>
(
j
,
i
)
>
0
)
{
drawing
.
at
<
Vec3b
>
(
j
,
i
)[
2
]
=
255
-
(
int
)
raw_dist
.
at
<
float
>
(
j
,
i
)
*
255
/
maxVal
;
}
{
drawing
.
at
<
Vec3b
>
(
j
,
i
)[
2
]
=
(
uchar
)(
255
-
raw_dist
.
at
<
float
>
(
j
,
i
)
*
255
/
maxVal
)
;
}
else
else
{
drawing
.
at
<
Vec3b
>
(
j
,
i
)[
0
]
=
255
;
drawing
.
at
<
Vec3b
>
(
j
,
i
)[
1
]
=
255
;
drawing
.
at
<
Vec3b
>
(
j
,
i
)[
2
]
=
255
;
}
{
drawing
.
at
<
Vec3b
>
(
j
,
i
)[
0
]
=
255
;
drawing
.
at
<
Vec3b
>
(
j
,
i
)[
1
]
=
255
;
drawing
.
at
<
Vec3b
>
(
j
,
i
)[
2
]
=
255
;
}
}
}
}
}
/// Create Window and show your results
/// Create Window and show your results
char
*
source_window
=
"Source"
;
c
onst
c
har
*
source_window
=
"Source"
;
namedWindow
(
source_window
,
CV_WINDOW_AUTOSIZE
);
namedWindow
(
source_window
,
CV_WINDOW_AUTOSIZE
);
imshow
(
source_window
,
src
);
imshow
(
source_window
,
src
);
namedWindow
(
"Distance"
,
CV_WINDOW_AUTOSIZE
);
namedWindow
(
"Distance"
,
CV_WINDOW_AUTOSIZE
);
...
...
samples/cpp/tutorial_code/TrackingMotion/cornerDetector_Demo.cpp
View file @
a2185075
...
@@ -26,8 +26,8 @@ double myShiTomasi_minVal; double myShiTomasi_maxVal;
...
@@ -26,8 +26,8 @@ double myShiTomasi_minVal; double myShiTomasi_maxVal;
RNG
rng
(
12345
);
RNG
rng
(
12345
);
char
*
myHarris_window
=
"My Harris corner detector"
;
c
onst
c
har
*
myHarris_window
=
"My Harris corner detector"
;
char
*
myShiTomasi_window
=
"My Shi Tomasi corner detector"
;
c
onst
c
har
*
myShiTomasi_window
=
"My Shi Tomasi corner detector"
;
/// Function headers
/// Function headers
void
myShiTomasi_function
(
int
,
void
*
);
void
myShiTomasi_function
(
int
,
void
*
);
...
@@ -36,7 +36,7 @@ void myHarris_function( int, void* );
...
@@ -36,7 +36,7 @@ void myHarris_function( int, void* );
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Load source image and convert it to gray
/// Load source image and convert it to gray
src
=
imread
(
argv
[
1
],
1
);
src
=
imread
(
argv
[
1
],
1
);
...
@@ -57,7 +57,7 @@ int main( int argc, char** argv )
...
@@ -57,7 +57,7 @@ int main( int argc, char** argv )
{
{
float
lambda_1
=
myHarris_dst
.
at
<
Vec6f
>
(
j
,
i
)[
0
];
float
lambda_1
=
myHarris_dst
.
at
<
Vec6f
>
(
j
,
i
)[
0
];
float
lambda_2
=
myHarris_dst
.
at
<
Vec6f
>
(
j
,
i
)[
1
];
float
lambda_2
=
myHarris_dst
.
at
<
Vec6f
>
(
j
,
i
)[
1
];
Mc
.
at
<
float
>
(
j
,
i
)
=
lambda_1
*
lambda_2
-
0.04
*
pow
(
(
lambda_1
+
lambda_2
),
2
);
Mc
.
at
<
float
>
(
j
,
i
)
=
lambda_1
*
lambda_2
-
0.04
f
*
pow
(
(
lambda_1
+
lambda_2
),
2
);
}
}
}
}
...
...
samples/cpp/tutorial_code/TrackingMotion/cornerHarris_Demo.cpp
View file @
a2185075
...
@@ -18,8 +18,8 @@ Mat src, src_gray;
...
@@ -18,8 +18,8 @@ Mat src, src_gray;
int
thresh
=
200
;
int
thresh
=
200
;
int
max_thresh
=
255
;
int
max_thresh
=
255
;
char
*
source_window
=
"Source image"
;
c
onst
c
har
*
source_window
=
"Source image"
;
char
*
corners_window
=
"Corners detected"
;
c
onst
c
har
*
corners_window
=
"Corners detected"
;
/// Function header
/// Function header
void
cornerHarris_demo
(
int
,
void
*
);
void
cornerHarris_demo
(
int
,
void
*
);
...
@@ -27,7 +27,7 @@ void cornerHarris_demo( int, void* );
...
@@ -27,7 +27,7 @@ void cornerHarris_demo( int, void* );
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Load source image and convert it to gray
/// Load source image and convert it to gray
src
=
imread
(
argv
[
1
],
1
);
src
=
imread
(
argv
[
1
],
1
);
...
...
samples/cpp/tutorial_code/TrackingMotion/cornerSubPix_Demo.cpp
View file @
a2185075
...
@@ -20,7 +20,7 @@ int maxCorners = 10;
...
@@ -20,7 +20,7 @@ int maxCorners = 10;
int
maxTrackbar
=
25
;
int
maxTrackbar
=
25
;
RNG
rng
(
12345
);
RNG
rng
(
12345
);
char
*
source_window
=
"Image"
;
c
onst
c
har
*
source_window
=
"Image"
;
/// Function header
/// Function header
void
goodFeaturesToTrack_Demo
(
int
,
void
*
);
void
goodFeaturesToTrack_Demo
(
int
,
void
*
);
...
@@ -28,7 +28,7 @@ void goodFeaturesToTrack_Demo( int, void* );
...
@@ -28,7 +28,7 @@ void goodFeaturesToTrack_Demo( int, void* );
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Load source image and convert it to gray
/// Load source image and convert it to gray
src
=
imread
(
argv
[
1
],
1
);
src
=
imread
(
argv
[
1
],
1
);
...
@@ -83,7 +83,7 @@ void goodFeaturesToTrack_Demo( int, void* )
...
@@ -83,7 +83,7 @@ void goodFeaturesToTrack_Demo( int, void* )
/// Draw corners detected
/// Draw corners detected
cout
<<
"** Number of corners detected: "
<<
corners
.
size
()
<<
endl
;
cout
<<
"** Number of corners detected: "
<<
corners
.
size
()
<<
endl
;
int
r
=
4
;
int
r
=
4
;
for
(
in
t
i
=
0
;
i
<
corners
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
corners
.
size
();
i
++
)
{
circle
(
copy
,
corners
[
i
],
r
,
Scalar
(
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
)),
-
1
,
8
,
0
);
}
{
circle
(
copy
,
corners
[
i
],
r
,
Scalar
(
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
)),
-
1
,
8
,
0
);
}
/// Show what you got
/// Show what you got
...
@@ -99,7 +99,7 @@ void goodFeaturesToTrack_Demo( int, void* )
...
@@ -99,7 +99,7 @@ void goodFeaturesToTrack_Demo( int, void* )
cornerSubPix
(
src_gray
,
corners
,
winSize
,
zeroZone
,
criteria
);
cornerSubPix
(
src_gray
,
corners
,
winSize
,
zeroZone
,
criteria
);
/// Write them down
/// Write them down
for
(
in
t
i
=
0
;
i
<
corners
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
corners
.
size
();
i
++
)
{
cout
<<
" -- Refined Corner ["
<<
i
<<
"] ("
<<
corners
[
i
].
x
<<
","
<<
corners
[
i
].
y
<<
")"
<<
endl
;
}
{
cout
<<
" -- Refined Corner ["
<<
i
<<
"] ("
<<
corners
[
i
].
x
<<
","
<<
corners
[
i
].
y
<<
")"
<<
endl
;
}
}
}
samples/cpp/tutorial_code/TrackingMotion/goodFeaturesToTrack_Demo.cpp
View file @
a2185075
...
@@ -20,7 +20,7 @@ int maxCorners = 23;
...
@@ -20,7 +20,7 @@ int maxCorners = 23;
int
maxTrackbar
=
100
;
int
maxTrackbar
=
100
;
RNG
rng
(
12345
);
RNG
rng
(
12345
);
char
*
source_window
=
"Image"
;
c
onst
c
har
*
source_window
=
"Image"
;
/// Function header
/// Function header
void
goodFeaturesToTrack_Demo
(
int
,
void
*
);
void
goodFeaturesToTrack_Demo
(
int
,
void
*
);
...
@@ -28,7 +28,7 @@ void goodFeaturesToTrack_Demo( int, void* );
...
@@ -28,7 +28,7 @@ void goodFeaturesToTrack_Demo( int, void* );
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
,
char
**
argv
)
{
{
/// Load source image and convert it to gray
/// Load source image and convert it to gray
src
=
imread
(
argv
[
1
],
1
);
src
=
imread
(
argv
[
1
],
1
);
...
@@ -83,7 +83,7 @@ void goodFeaturesToTrack_Demo( int, void* )
...
@@ -83,7 +83,7 @@ void goodFeaturesToTrack_Demo( int, void* )
/// Draw corners detected
/// Draw corners detected
cout
<<
"** Number of corners detected: "
<<
corners
.
size
()
<<
endl
;
cout
<<
"** Number of corners detected: "
<<
corners
.
size
()
<<
endl
;
int
r
=
4
;
int
r
=
4
;
for
(
in
t
i
=
0
;
i
<
corners
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
corners
.
size
();
i
++
)
{
circle
(
copy
,
corners
[
i
],
r
,
Scalar
(
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
)),
-
1
,
8
,
0
);
}
{
circle
(
copy
,
corners
[
i
],
r
,
Scalar
(
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
),
rng
.
uniform
(
0
,
255
)),
-
1
,
8
,
0
);
}
/// Show what you got
/// Show what you got
...
...
samples/cpp/tutorial_code/calib3d/camera_calibration/camera_calibration.cpp
View file @
a2185075
#include <iostream>
#include <iostream>
#include <sstream>
#include <sstream>
#include <time.h>
#include <time.h>
#include <stdio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/imgproc/imgproc.hpp>
...
@@ -10,7 +11,7 @@
...
@@ -10,7 +11,7 @@
using
namespace
cv
;
using
namespace
cv
;
using
namespace
std
;
using
namespace
std
;
void
help
()
static
void
help
()
{
{
cout
<<
"This is a camera calibration sample."
<<
endl
cout
<<
"This is a camera calibration sample."
<<
endl
<<
"Usage: calibration configurationFile"
<<
endl
<<
"Usage: calibration configurationFile"
<<
endl
...
@@ -99,7 +100,7 @@ public:
...
@@ -99,7 +100,7 @@ public:
if
(
readStringList
(
input
,
imageList
))
if
(
readStringList
(
input
,
imageList
))
{
{
inputType
=
IMAGE_LIST
;
inputType
=
IMAGE_LIST
;
nrFrames
=
(
nrFrames
<
imageList
.
size
())
?
nrFrames
:
imageList
.
size
();
nrFrames
=
(
nrFrames
<
(
int
)
imageList
.
size
())
?
nrFrames
:
(
int
)
imageList
.
size
();
}
}
else
else
inputType
=
VIDEO_FILE
;
inputType
=
VIDEO_FILE
;
...
@@ -196,11 +197,7 @@ private:
...
@@ -196,11 +197,7 @@ private:
};
};
void
write
(
FileStorage
&
fs
,
const
std
::
string
&
,
const
Settings
&
x
)
static
void
read
(
const
FileNode
&
node
,
Settings
&
x
,
const
Settings
&
default_value
=
Settings
())
{
x
.
write
(
fs
);
}
void
read
(
const
FileNode
&
node
,
Settings
&
x
,
const
Settings
&
default_value
=
Settings
())
{
{
if
(
node
.
empty
())
if
(
node
.
empty
())
x
=
default_value
;
x
=
default_value
;
...
@@ -282,6 +279,9 @@ int main(int argc, char* argv[])
...
@@ -282,6 +279,9 @@ int main(int argc, char* argv[])
case
Settings
:
:
ASYMMETRIC_CIRCLES_GRID
:
case
Settings
:
:
ASYMMETRIC_CIRCLES_GRID
:
found
=
findCirclesGrid
(
view
,
s
.
boardSize
,
pointBuf
,
CALIB_CB_ASYMMETRIC_GRID
);
found
=
findCirclesGrid
(
view
,
s
.
boardSize
,
pointBuf
,
CALIB_CB_ASYMMETRIC_GRID
);
break
;
break
;
default:
found
=
false
;
break
;
}
}
if
(
found
)
// If done with success,
if
(
found
)
// If done with success,
...
@@ -336,7 +336,7 @@ int main(int argc, char* argv[])
...
@@ -336,7 +336,7 @@ int main(int argc, char* argv[])
//------------------------------ Show image and check for input commands -------------------
//------------------------------ Show image and check for input commands -------------------
imshow
(
"Image View"
,
view
);
imshow
(
"Image View"
,
view
);
char
key
=
waitKey
(
s
.
inputCapture
.
isOpened
()
?
50
:
s
.
delay
);
char
key
=
(
char
)
waitKey
(
s
.
inputCapture
.
isOpened
()
?
50
:
s
.
delay
);
if
(
key
==
ESC_KEY
)
if
(
key
==
ESC_KEY
)
break
;
break
;
...
@@ -366,7 +366,7 @@ int main(int argc, char* argv[])
...
@@ -366,7 +366,7 @@ int main(int argc, char* argv[])
continue
;
continue
;
remap
(
view
,
rview
,
map1
,
map2
,
INTER_LINEAR
);
remap
(
view
,
rview
,
map1
,
map2
,
INTER_LINEAR
);
imshow
(
"Image View"
,
rview
);
imshow
(
"Image View"
,
rview
);
char
c
=
waitKey
();
char
c
=
(
char
)
waitKey
();
if
(
c
==
ESC_KEY
||
c
==
'q'
||
c
==
'Q'
)
if
(
c
==
ESC_KEY
||
c
==
'q'
||
c
==
'Q'
)
break
;
break
;
}
}
...
@@ -376,11 +376,11 @@ int main(int argc, char* argv[])
...
@@ -376,11 +376,11 @@ int main(int argc, char* argv[])
return
0
;
return
0
;
}
}
double
computeReprojectionErrors
(
const
vector
<
vector
<
Point3f
>
>&
objectPoints
,
static
double
computeReprojectionErrors
(
const
vector
<
vector
<
Point3f
>
>&
objectPoints
,
const
vector
<
vector
<
Point2f
>
>&
imagePoints
,
const
vector
<
vector
<
Point2f
>
>&
imagePoints
,
const
vector
<
Mat
>&
rvecs
,
const
vector
<
Mat
>&
tvecs
,
const
vector
<
Mat
>&
rvecs
,
const
vector
<
Mat
>&
tvecs
,
const
Mat
&
cameraMatrix
,
const
Mat
&
distCoeffs
,
const
Mat
&
cameraMatrix
,
const
Mat
&
distCoeffs
,
vector
<
float
>&
perViewErrors
)
vector
<
float
>&
perViewErrors
)
{
{
vector
<
Point2f
>
imagePoints2
;
vector
<
Point2f
>
imagePoints2
;
int
i
,
totalPoints
=
0
;
int
i
,
totalPoints
=
0
;
...
@@ -402,8 +402,8 @@ double computeReprojectionErrors( const vector<vector<Point3f> >& objectPoints,
...
@@ -402,8 +402,8 @@ double computeReprojectionErrors( const vector<vector<Point3f> >& objectPoints,
return
std
::
sqrt
(
totalErr
/
totalPoints
);
return
std
::
sqrt
(
totalErr
/
totalPoints
);
}
}
void
calcBoardCornerPositions
(
Size
boardSize
,
float
squareSize
,
vector
<
Point3f
>&
corners
,
static
void
calcBoardCornerPositions
(
Size
boardSize
,
float
squareSize
,
vector
<
Point3f
>&
corners
,
Settings
::
Pattern
patternType
/*= Settings::CHESSBOARD*/
)
Settings
::
Pattern
patternType
/*= Settings::CHESSBOARD*/
)
{
{
corners
.
clear
();
corners
.
clear
();
...
@@ -421,12 +421,14 @@ void calcBoardCornerPositions(Size boardSize, float squareSize, vector<Point3f>&
...
@@ -421,12 +421,14 @@ void calcBoardCornerPositions(Size boardSize, float squareSize, vector<Point3f>&
for
(
int
j
=
0
;
j
<
boardSize
.
width
;
j
++
)
for
(
int
j
=
0
;
j
<
boardSize
.
width
;
j
++
)
corners
.
push_back
(
Point3f
(
float
((
2
*
j
+
i
%
2
)
*
squareSize
),
float
(
i
*
squareSize
),
0
));
corners
.
push_back
(
Point3f
(
float
((
2
*
j
+
i
%
2
)
*
squareSize
),
float
(
i
*
squareSize
),
0
));
break
;
break
;
default:
break
;
}
}
}
}
bool
runCalibration
(
Settings
&
s
,
Size
&
imageSize
,
Mat
&
cameraMatrix
,
Mat
&
distCoeffs
,
static
bool
runCalibration
(
Settings
&
s
,
Size
&
imageSize
,
Mat
&
cameraMatrix
,
Mat
&
distCoeffs
,
vector
<
vector
<
Point2f
>
>
imagePoints
,
vector
<
Mat
>&
rvecs
,
vector
<
Mat
>&
tvecs
,
vector
<
vector
<
Point2f
>
>
imagePoints
,
vector
<
Mat
>&
rvecs
,
vector
<
Mat
>&
tvecs
,
vector
<
float
>&
reprojErrs
,
double
&
totalAvgErr
)
vector
<
float
>&
reprojErrs
,
double
&
totalAvgErr
)
{
{
cameraMatrix
=
Mat
::
eye
(
3
,
3
,
CV_64F
);
cameraMatrix
=
Mat
::
eye
(
3
,
3
,
CV_64F
);
...
@@ -455,16 +457,16 @@ bool runCalibration( Settings& s, Size& imageSize, Mat& cameraMatrix, Mat& distC
...
@@ -455,16 +457,16 @@ bool runCalibration( Settings& s, Size& imageSize, Mat& cameraMatrix, Mat& distC
}
}
// Print camera parameters to the output file
// Print camera parameters to the output file
void
saveCameraParams
(
Settings
&
s
,
Size
&
imageSize
,
Mat
&
cameraMatrix
,
Mat
&
distCoeffs
,
static
void
saveCameraParams
(
Settings
&
s
,
Size
&
imageSize
,
Mat
&
cameraMatrix
,
Mat
&
distCoeffs
,
const
vector
<
Mat
>&
rvecs
,
const
vector
<
Mat
>&
tvecs
,
const
vector
<
Mat
>&
rvecs
,
const
vector
<
Mat
>&
tvecs
,
const
vector
<
float
>&
reprojErrs
,
const
vector
<
vector
<
Point2f
>
>&
imagePoints
,
const
vector
<
float
>&
reprojErrs
,
const
vector
<
vector
<
Point2f
>
>&
imagePoints
,
double
totalAvgErr
)
double
totalAvgErr
)
{
{
FileStorage
fs
(
s
.
outputFileName
,
FileStorage
::
WRITE
);
FileStorage
fs
(
s
.
outputFileName
,
FileStorage
::
WRITE
);
time_t
t
;
time_t
t
m
;
time
(
&
t
);
time
(
&
t
m
);
struct
tm
*
t2
=
localtime
(
&
t
);
struct
tm
*
t2
=
localtime
(
&
t
m
);
char
buf
[
1024
];
char
buf
[
1024
];
strftime
(
buf
,
sizeof
(
buf
)
-
1
,
"%c"
,
t2
);
strftime
(
buf
,
sizeof
(
buf
)
-
1
,
"%c"
,
t2
);
...
@@ -522,7 +524,7 @@ void saveCameraParams( Settings& s, Size& imageSize, Mat& cameraMatrix, Mat& dis
...
@@ -522,7 +524,7 @@ void saveCameraParams( Settings& s, Size& imageSize, Mat& cameraMatrix, Mat& dis
if
(
!
imagePoints
.
empty
()
)
if
(
!
imagePoints
.
empty
()
)
{
{
Mat
imagePtMat
((
int
)
imagePoints
.
size
(),
imagePoints
[
0
].
size
(),
CV_32FC2
);
Mat
imagePtMat
((
int
)
imagePoints
.
size
(),
(
int
)
imagePoints
[
0
].
size
(),
CV_32FC2
);
for
(
int
i
=
0
;
i
<
(
int
)
imagePoints
.
size
();
i
++
)
for
(
int
i
=
0
;
i
<
(
int
)
imagePoints
.
size
();
i
++
)
{
{
Mat
r
=
imagePtMat
.
row
(
i
).
reshape
(
2
,
imagePtMat
.
cols
);
Mat
r
=
imagePtMat
.
row
(
i
).
reshape
(
2
,
imagePtMat
.
cols
);
...
...
samples/cpp/tutorial_code/calib3d/stereoBM/SBM_Sample.cpp
View file @
a2185075
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
using
namespace
cv
;
using
namespace
cv
;
char
*
windowDisparity
=
"Disparity"
;
c
onst
c
har
*
windowDisparity
=
"Disparity"
;
void
readme
();
void
readme
();
...
...
samples/cpp/tutorial_code/contrib/retina_tutorial.cpp
View file @
a2185075
...
@@ -118,7 +118,7 @@ int main(int argc, char* argv[]) {
...
@@ -118,7 +118,7 @@ int main(int argc, char* argv[]) {
cv
::
Mat
retinaOutput_magno
;
cv
::
Mat
retinaOutput_magno
;
// processing loop with no stop condition
// processing loop with no stop condition
while
(
true
)
for
(;;
)
{
{
// if using video stream, then, grabbing a new frame, else, input remains the same
// if using video stream, then, grabbing a new frame, else, input remains the same
if
(
videoCapture
.
isOpened
())
if
(
videoCapture
.
isOpened
())
...
...
samples/cpp/tutorial_code/core/Matrix/Drawing_1.cpp
View file @
a2185075
...
@@ -20,7 +20,7 @@ void MyLine( Mat img, Point start, Point end );
...
@@ -20,7 +20,7 @@ void MyLine( Mat img, Point start, Point end );
* @function main
* @function main
* @brief Main function
* @brief Main function
*/
*/
int
main
(
int
argc
,
char
**
argv
){
int
main
(
void
){
/// Windows names
/// Windows names
char
atom_window
[]
=
"Drawing 1: Atom"
;
char
atom_window
[]
=
"Drawing 1: Atom"
;
...
@@ -40,7 +40,7 @@ int main( int argc, char **argv ){
...
@@ -40,7 +40,7 @@ int main( int argc, char **argv ){
MyEllipse
(
atom_image
,
-
45
);
MyEllipse
(
atom_image
,
-
45
);
/// 1.b. Creating circles
/// 1.b. Creating circles
MyFilledCircle
(
atom_image
,
Point
(
w
/
2
.0
,
w
/
2.0
)
);
MyFilledCircle
(
atom_image
,
Point
(
w
/
2
,
w
/
2
)
);
/// 2. Draw a rook
/// 2. Draw a rook
/// ------------------
/// ------------------
...
@@ -50,7 +50,7 @@ int main( int argc, char **argv ){
...
@@ -50,7 +50,7 @@ int main( int argc, char **argv ){
/// 2.b. Creating rectangles
/// 2.b. Creating rectangles
rectangle
(
rook_image
,
rectangle
(
rook_image
,
Point
(
0
,
7
*
w
/
8
.0
),
Point
(
0
,
7
*
w
/
8
),
Point
(
w
,
w
),
Point
(
w
,
w
),
Scalar
(
0
,
255
,
255
),
Scalar
(
0
,
255
,
255
),
-
1
,
-
1
,
...
@@ -84,8 +84,8 @@ void MyEllipse( Mat img, double angle )
...
@@ -84,8 +84,8 @@ void MyEllipse( Mat img, double angle )
int
lineType
=
8
;
int
lineType
=
8
;
ellipse
(
img
,
ellipse
(
img
,
Point
(
w
/
2
.0
,
w
/
2.0
),
Point
(
w
/
2
,
w
/
2
),
Size
(
w
/
4
.0
,
w
/
16.0
),
Size
(
w
/
4
,
w
/
16
),
angle
,
angle
,
0
,
0
,
360
,
360
,
...
@@ -105,7 +105,7 @@ void MyFilledCircle( Mat img, Point center )
...
@@ -105,7 +105,7 @@ void MyFilledCircle( Mat img, Point center )
circle
(
img
,
circle
(
img
,
center
,
center
,
w
/
32
.0
,
w
/
32
,
Scalar
(
0
,
0
,
255
),
Scalar
(
0
,
0
,
255
),
thickness
,
thickness
,
lineType
);
lineType
);
...
@@ -121,26 +121,26 @@ void MyPolygon( Mat img )
...
@@ -121,26 +121,26 @@ void MyPolygon( Mat img )
/** Create some points */
/** Create some points */
Point
rook_points
[
1
][
20
];
Point
rook_points
[
1
][
20
];
rook_points
[
0
][
0
]
=
Point
(
w
/
4.0
,
7
*
w
/
8.0
);
rook_points
[
0
][
0
]
=
Point
(
w
/
4
,
7
*
w
/
8
);
rook_points
[
0
][
1
]
=
Point
(
3
*
w
/
4.0
,
7
*
w
/
8.0
);
rook_points
[
0
][
1
]
=
Point
(
3
*
w
/
4
,
7
*
w
/
8
);
rook_points
[
0
][
2
]
=
Point
(
3
*
w
/
4.0
,
13
*
w
/
16.0
);
rook_points
[
0
][
2
]
=
Point
(
3
*
w
/
4
,
13
*
w
/
16
);
rook_points
[
0
][
3
]
=
Point
(
11
*
w
/
16.0
,
13
*
w
/
16.0
);
rook_points
[
0
][
3
]
=
Point
(
11
*
w
/
16
,
13
*
w
/
16
);
rook_points
[
0
][
4
]
=
Point
(
19
*
w
/
32.0
,
3
*
w
/
8.0
);
rook_points
[
0
][
4
]
=
Point
(
19
*
w
/
32
,
3
*
w
/
8
);
rook_points
[
0
][
5
]
=
Point
(
3
*
w
/
4.0
,
3
*
w
/
8.0
);
rook_points
[
0
][
5
]
=
Point
(
3
*
w
/
4
,
3
*
w
/
8
);
rook_points
[
0
][
6
]
=
Point
(
3
*
w
/
4.0
,
w
/
8.0
);
rook_points
[
0
][
6
]
=
Point
(
3
*
w
/
4
,
w
/
8
);
rook_points
[
0
][
7
]
=
Point
(
26
*
w
/
40.0
,
w
/
8.0
);
rook_points
[
0
][
7
]
=
Point
(
26
*
w
/
40
,
w
/
8
);
rook_points
[
0
][
8
]
=
Point
(
26
*
w
/
40.0
,
w
/
4.0
);
rook_points
[
0
][
8
]
=
Point
(
26
*
w
/
40
,
w
/
4
);
rook_points
[
0
][
9
]
=
Point
(
22
*
w
/
40.0
,
w
/
4.0
);
rook_points
[
0
][
9
]
=
Point
(
22
*
w
/
40
,
w
/
4
);
rook_points
[
0
][
10
]
=
Point
(
22
*
w
/
40
.0
,
w
/
8.0
);
rook_points
[
0
][
10
]
=
Point
(
22
*
w
/
40
,
w
/
8
);
rook_points
[
0
][
11
]
=
Point
(
18
*
w
/
40
.0
,
w
/
8.0
);
rook_points
[
0
][
11
]
=
Point
(
18
*
w
/
40
,
w
/
8
);
rook_points
[
0
][
12
]
=
Point
(
18
*
w
/
40
.0
,
w
/
4.0
);
rook_points
[
0
][
12
]
=
Point
(
18
*
w
/
40
,
w
/
4
);
rook_points
[
0
][
13
]
=
Point
(
14
*
w
/
40
.0
,
w
/
4.0
);
rook_points
[
0
][
13
]
=
Point
(
14
*
w
/
40
,
w
/
4
);
rook_points
[
0
][
14
]
=
Point
(
14
*
w
/
40
.0
,
w
/
8.0
);
rook_points
[
0
][
14
]
=
Point
(
14
*
w
/
40
,
w
/
8
);
rook_points
[
0
][
15
]
=
Point
(
w
/
4.0
,
w
/
8.0
);
rook_points
[
0
][
15
]
=
Point
(
w
/
4
,
w
/
8
);
rook_points
[
0
][
16
]
=
Point
(
w
/
4.0
,
3
*
w
/
8.0
);
rook_points
[
0
][
16
]
=
Point
(
w
/
4
,
3
*
w
/
8
);
rook_points
[
0
][
17
]
=
Point
(
13
*
w
/
32
.0
,
3
*
w
/
8.0
);
rook_points
[
0
][
17
]
=
Point
(
13
*
w
/
32
,
3
*
w
/
8
);
rook_points
[
0
][
18
]
=
Point
(
5
*
w
/
16.0
,
13
*
w
/
16.0
);
rook_points
[
0
][
18
]
=
Point
(
5
*
w
/
16
,
13
*
w
/
16
);
rook_points
[
0
][
19
]
=
Point
(
w
/
4.0
,
13
*
w
/
16.0
)
;
rook_points
[
0
][
19
]
=
Point
(
w
/
4
,
13
*
w
/
16
)
;
const
Point
*
ppt
[
1
]
=
{
rook_points
[
0
]
};
const
Point
*
ppt
[
1
]
=
{
rook_points
[
0
]
};
int
npt
[]
=
{
20
};
int
npt
[]
=
{
20
};
...
...
samples/cpp/tutorial_code/core/Matrix/Drawing_2.cpp
View file @
a2185075
...
@@ -36,7 +36,7 @@ int Displaying_Big_End( Mat image, char* window_name, RNG rng );
...
@@ -36,7 +36,7 @@ int Displaying_Big_End( Mat image, char* window_name, RNG rng );
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
char
**
argv
)
int
main
(
void
)
{
{
int
c
;
int
c
;
...
@@ -106,7 +106,6 @@ static Scalar randomColor( RNG& rng )
...
@@ -106,7 +106,6 @@ static Scalar randomColor( RNG& rng )
*/
*/
int
Drawing_Random_Lines
(
Mat
image
,
char
*
window_name
,
RNG
rng
)
int
Drawing_Random_Lines
(
Mat
image
,
char
*
window_name
,
RNG
rng
)
{
{
int
lineType
=
8
;
Point
pt1
,
pt2
;
Point
pt1
,
pt2
;
for
(
int
i
=
0
;
i
<
NUMBER
;
i
++
)
for
(
int
i
=
0
;
i
<
NUMBER
;
i
++
)
...
@@ -303,7 +302,7 @@ int Displaying_Random_Text( Mat image, char* window_name, RNG rng )
...
@@ -303,7 +302,7 @@ int Displaying_Random_Text( Mat image, char* window_name, RNG rng )
/**
/**
* @function Displaying_Big_End
* @function Displaying_Big_End
*/
*/
int
Displaying_Big_End
(
Mat
image
,
char
*
window_name
,
RNG
rng
)
int
Displaying_Big_End
(
Mat
image
,
char
*
window_name
,
RNG
)
{
{
Size
textsize
=
getTextSize
(
"OpenCV forever!"
,
CV_FONT_HERSHEY_COMPLEX
,
3
,
5
,
0
);
Size
textsize
=
getTextSize
(
"OpenCV forever!"
,
CV_FONT_HERSHEY_COMPLEX
,
3
,
5
,
0
);
Point
org
((
window_width
-
textsize
.
width
)
/
2
,
(
window_height
-
textsize
.
height
)
/
2
);
Point
org
((
window_width
-
textsize
.
width
)
/
2
,
(
window_height
-
textsize
.
height
)
/
2
);
...
...
samples/cpp/tutorial_code/core/discrete_fourier_transform/discrete_fourier_transform.cpp
View file @
a2185075
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
using
namespace
cv
;
using
namespace
cv
;
using
namespace
std
;
using
namespace
std
;
void
help
(
char
*
progName
)
static
void
help
(
char
*
progName
)
{
{
cout
<<
endl
cout
<<
endl
<<
"This program demonstrated the use of the discrete Fourier transform (DFT). "
<<
endl
<<
"This program demonstrated the use of the discrete Fourier transform (DFT). "
<<
endl
...
...
samples/cpp/tutorial_code/core/file_input_output/file_input_output.cpp
View file @
a2185075
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
using
namespace
cv
;
using
namespace
cv
;
using
namespace
std
;
using
namespace
std
;
void
help
(
char
**
av
)
static
void
help
(
char
**
av
)
{
{
cout
<<
endl
cout
<<
endl
<<
av
[
0
]
<<
" shows the usage of the OpenCV serialization functionality."
<<
endl
<<
av
[
0
]
<<
" shows the usage of the OpenCV serialization functionality."
<<
endl
...
@@ -42,11 +42,11 @@ public: // Data Members
...
@@ -42,11 +42,11 @@ public: // Data Members
};
};
//These write and read functions must be defined for the serialization in FileStorage to work
//These write and read functions must be defined for the serialization in FileStorage to work
void
write
(
FileStorage
&
fs
,
const
std
::
string
&
,
const
MyData
&
x
)
static
void
write
(
FileStorage
&
fs
,
const
std
::
string
&
,
const
MyData
&
x
)
{
{
x
.
write
(
fs
);
x
.
write
(
fs
);
}
}
void
read
(
const
FileNode
&
node
,
MyData
&
x
,
const
MyData
&
default_value
=
MyData
()){
static
void
read
(
const
FileNode
&
node
,
MyData
&
x
,
const
MyData
&
default_value
=
MyData
()){
if
(
node
.
empty
())
if
(
node
.
empty
())
x
=
default_value
;
x
=
default_value
;
else
else
...
@@ -54,7 +54,7 @@ void read(const FileNode& node, MyData& x, const MyData& default_value = MyData(
...
@@ -54,7 +54,7 @@ void read(const FileNode& node, MyData& x, const MyData& default_value = MyData(
}
}
// This function will print our custom class to the console
// This function will print our custom class to the console
ostream
&
operator
<<
(
ostream
&
out
,
const
MyData
&
m
)
static
ostream
&
operator
<<
(
ostream
&
out
,
const
MyData
&
m
)
{
{
out
<<
"{ id = "
<<
m
.
id
<<
", "
;
out
<<
"{ id = "
<<
m
.
id
<<
", "
;
out
<<
"X = "
<<
m
.
X
<<
", "
;
out
<<
"X = "
<<
m
.
X
<<
", "
;
...
...
samples/cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp
View file @
a2185075
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
using
namespace
std
;
using
namespace
std
;
using
namespace
cv
;
using
namespace
cv
;
void
help
()
static
void
help
()
{
{
cout
cout
<<
"
\n
--------------------------------------------------------------------------"
<<
endl
<<
"
\n
--------------------------------------------------------------------------"
<<
endl
...
@@ -57,7 +57,7 @@ int main( int argc, char* argv[])
...
@@ -57,7 +57,7 @@ int main( int argc, char* argv[])
uchar
table
[
256
];
uchar
table
[
256
];
for
(
int
i
=
0
;
i
<
256
;
++
i
)
for
(
int
i
=
0
;
i
<
256
;
++
i
)
table
[
i
]
=
divideWith
*
(
i
/
divideWith
);
table
[
i
]
=
(
uchar
)(
divideWith
*
(
i
/
divideWith
)
);
const
int
times
=
100
;
const
int
times
=
100
;
double
t
;
double
t
;
...
...
samples/cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp
View file @
a2185075
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
using
namespace
cv
;
// The new C++ interface API is inside this namespace. Import it.
using
namespace
cv
;
// The new C++ interface API is inside this namespace. Import it.
using
namespace
std
;
using
namespace
std
;
void
help
(
char
*
progName
)
static
void
help
(
char
*
progName
)
{
{
cout
<<
endl
<<
progName
cout
<<
endl
<<
progName
<<
" shows how to use cv::Mat and IplImages together (converting back and forth)."
<<
endl
<<
" shows how to use cv::Mat and IplImages together (converting back and forth)."
<<
endl
...
...
samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp
View file @
a2185075
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
using
namespace
std
;
using
namespace
std
;
using
namespace
cv
;
using
namespace
cv
;
void
help
(
char
*
progName
)
static
void
help
(
char
*
progName
)
{
{
cout
<<
endl
cout
<<
endl
<<
"This program shows how to filter images with mask: the write it yourself and the"
<<
"This program shows how to filter images with mask: the write it yourself and the"
...
...
samples/cpp/tutorial_code/core/mat_the_basic_image_container/mat_the_basic_image_container.cpp
View file @
a2185075
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
using
namespace
std
;
using
namespace
std
;
using
namespace
cv
;
using
namespace
cv
;
void
help
()
static
void
help
()
{
{
cout
cout
<<
"
\n
--------------------------------------------------------------------------"
<<
endl
<<
"
\n
--------------------------------------------------------------------------"
<<
endl
...
@@ -77,8 +77,8 @@ int main(int,char**)
...
@@ -77,8 +77,8 @@ int main(int,char**)
cout
<<
"Vector of floats via Mat = "
<<
Mat
(
v
)
<<
endl
<<
endl
;
cout
<<
"Vector of floats via Mat = "
<<
Mat
(
v
)
<<
endl
<<
endl
;
vector
<
Point2f
>
vPoints
(
20
);
vector
<
Point2f
>
vPoints
(
20
);
for
(
size_t
E
=
0
;
E
<
vPoints
.
size
();
++
E
)
for
(
size_t
i
=
0
;
i
<
vPoints
.
size
();
++
i
)
vPoints
[
E
]
=
Point2f
((
float
)(
E
*
5
),
(
float
)(
E
%
7
));
vPoints
[
i
]
=
Point2f
((
float
)(
i
*
5
),
(
float
)(
i
%
7
));
cout
<<
"A vector of 2D Points = "
<<
vPoints
<<
endl
<<
endl
;
cout
<<
"A vector of 2D Points = "
<<
vPoints
<<
endl
<<
endl
;
return
0
;
return
0
;
...
...
samples/cpp/tutorial_code/features2D/SURF_FlannMatcher.cpp
View file @
a2185075
...
@@ -83,7 +83,7 @@ int main( int argc, char** argv )
...
@@ -83,7 +83,7 @@ int main( int argc, char** argv )
//-- Show detected matches
//-- Show detected matches
imshow
(
"Good Matches"
,
img_matches
);
imshow
(
"Good Matches"
,
img_matches
);
for
(
int
i
=
0
;
i
<
good_matches
.
size
();
i
++
)
for
(
int
i
=
0
;
i
<
(
int
)
good_matches
.
size
();
i
++
)
{
printf
(
"-- Good Match [%d] Keypoint 1: %d -- Keypoint 2: %d
\n
"
,
i
,
good_matches
[
i
].
queryIdx
,
good_matches
[
i
].
trainIdx
);
}
{
printf
(
"-- Good Match [%d] Keypoint 1: %d -- Keypoint 2: %d
\n
"
,
i
,
good_matches
[
i
].
queryIdx
,
good_matches
[
i
].
trainIdx
);
}
waitKey
(
0
);
waitKey
(
0
);
...
...
samples/cpp/tutorial_code/features2D/SURF_Homography.cpp
View file @
a2185075
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/nonfree/features2d.
c
pp"
#include "opencv2/nonfree/features2d.
h
pp"
using
namespace
cv
;
using
namespace
cv
;
...
@@ -84,7 +84,7 @@ int main( int argc, char** argv )
...
@@ -84,7 +84,7 @@ int main( int argc, char** argv )
std
::
vector
<
Point2f
>
obj
;
std
::
vector
<
Point2f
>
obj
;
std
::
vector
<
Point2f
>
scene
;
std
::
vector
<
Point2f
>
scene
;
for
(
in
t
i
=
0
;
i
<
good_matches
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
good_matches
.
size
();
i
++
)
{
{
//-- Get the keypoints from the good matches
//-- Get the keypoints from the good matches
obj
.
push_back
(
keypoints_object
[
good_matches
[
i
].
queryIdx
].
pt
);
obj
.
push_back
(
keypoints_object
[
good_matches
[
i
].
queryIdx
].
pt
);
...
@@ -103,10 +103,11 @@ int main( int argc, char** argv )
...
@@ -103,10 +103,11 @@ int main( int argc, char** argv )
//-- Draw lines between the corners (the mapped object in the scene - image_2 )
//-- Draw lines between the corners (the mapped object in the scene - image_2 )
line
(
img_matches
,
scene_corners
[
0
]
+
Point2f
(
img_object
.
cols
,
0
),
scene_corners
[
1
]
+
Point2f
(
img_object
.
cols
,
0
),
Scalar
(
0
,
255
,
0
),
4
);
Point2f
offset
(
(
float
)
img_object
.
cols
,
0
);
line
(
img_matches
,
scene_corners
[
1
]
+
Point2f
(
img_object
.
cols
,
0
),
scene_corners
[
2
]
+
Point2f
(
img_object
.
cols
,
0
),
Scalar
(
0
,
255
,
0
),
4
);
line
(
img_matches
,
scene_corners
[
0
]
+
offset
,
scene_corners
[
1
]
+
offset
,
Scalar
(
0
,
255
,
0
),
4
);
line
(
img_matches
,
scene_corners
[
2
]
+
Point2f
(
img_object
.
cols
,
0
),
scene_corners
[
3
]
+
Point2f
(
img_object
.
cols
,
0
),
Scalar
(
0
,
255
,
0
),
4
);
line
(
img_matches
,
scene_corners
[
1
]
+
offset
,
scene_corners
[
2
]
+
offset
,
Scalar
(
0
,
255
,
0
),
4
);
line
(
img_matches
,
scene_corners
[
3
]
+
Point2f
(
img_object
.
cols
,
0
),
scene_corners
[
0
]
+
Point2f
(
img_object
.
cols
,
0
),
Scalar
(
0
,
255
,
0
),
4
);
line
(
img_matches
,
scene_corners
[
2
]
+
offset
,
scene_corners
[
3
]
+
offset
,
Scalar
(
0
,
255
,
0
),
4
);
line
(
img_matches
,
scene_corners
[
3
]
+
offset
,
scene_corners
[
0
]
+
offset
,
Scalar
(
0
,
255
,
0
),
4
);
//-- Show detected matches
//-- Show detected matches
imshow
(
"Good Matches & Object detection"
,
img_matches
);
imshow
(
"Good Matches & Object detection"
,
img_matches
);
...
...
samples/cpp/tutorial_code/features2D/SURF_descriptor.cpp
View file @
a2185075
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
#include "opencv2/core/core.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/features2d.
c
pp"
#include "opencv2/nonfree/features2d.
h
pp"
using
namespace
cv
;
using
namespace
cv
;
...
@@ -49,7 +49,7 @@ int main( int argc, char** argv )
...
@@ -49,7 +49,7 @@ int main( int argc, char** argv )
extractor
.
compute
(
img_2
,
keypoints_2
,
descriptors_2
);
extractor
.
compute
(
img_2
,
keypoints_2
,
descriptors_2
);
//-- Step 3: Matching descriptor vectors with a brute force matcher
//-- Step 3: Matching descriptor vectors with a brute force matcher
B
ruteForceMatcher
<
L2
<
float
>
>
matcher
;
B
FMatcher
matcher
(
NORM_L2
)
;
std
::
vector
<
DMatch
>
matches
;
std
::
vector
<
DMatch
>
matches
;
matcher
.
match
(
descriptors_1
,
descriptors_2
,
matches
);
matcher
.
match
(
descriptors_1
,
descriptors_2
,
matches
);
...
...
samples/cpp/tutorial_code/features2D/SURF_detector.cpp
View file @
a2185075
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
#include "opencv2/core/core.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/features2d.
c
pp"
#include "opencv2/nonfree/features2d.
h
pp"
using
namespace
cv
;
using
namespace
cv
;
...
...
samples/cpp/tutorial_code/gpu/gpu-basics-similarity/gpu-basics-similarity.cpp
View file @
a2185075
...
@@ -42,7 +42,7 @@ struct BufferMSSIM // Optimized GPU versions
...
@@ -42,7 +42,7 @@ struct BufferMSSIM // Optimized GPU versions
};
};
Scalar
getMSSIM_GPU_optimized
(
const
Mat
&
i1
,
const
Mat
&
i2
,
BufferMSSIM
&
b
);
Scalar
getMSSIM_GPU_optimized
(
const
Mat
&
i1
,
const
Mat
&
i2
,
BufferMSSIM
&
b
);
void
help
()
static
void
help
()
{
{
cout
cout
<<
"
\n
--------------------------------------------------------------------------"
<<
endl
<<
"
\n
--------------------------------------------------------------------------"
<<
endl
...
@@ -54,7 +54,7 @@ void help()
...
@@ -54,7 +54,7 @@ void help()
<<
endl
;
<<
endl
;
}
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
,
char
*
argv
[])
{
{
help
();
help
();
Mat
I1
=
imread
(
argv
[
1
]);
// Read the two images
Mat
I1
=
imread
(
argv
[
1
]);
// Read the two images
...
@@ -72,7 +72,7 @@ int main(int argc, char *argv[])
...
@@ -72,7 +72,7 @@ int main(int argc, char *argv[])
int
TIMES
;
int
TIMES
;
stringstream
sstr
(
argv
[
3
]);
stringstream
sstr
(
argv
[
3
]);
sstr
>>
TIMES
;
sstr
>>
TIMES
;
double
time
,
result
;
double
time
,
result
=
0
;
//------------------------------- PSNR CPU ----------------------------------------------------
//------------------------------- PSNR CPU ----------------------------------------------------
time
=
(
double
)
getTickCount
();
time
=
(
double
)
getTickCount
();
...
@@ -84,7 +84,7 @@ int main(int argc, char *argv[])
...
@@ -84,7 +84,7 @@ int main(int argc, char *argv[])
time
/=
TIMES
;
time
/=
TIMES
;
cout
<<
"Time of PSNR CPU (averaged for "
<<
TIMES
<<
" runs): "
<<
time
<<
" milliseconds."
cout
<<
"Time of PSNR CPU (averaged for "
<<
TIMES
<<
" runs): "
<<
time
<<
" milliseconds."
<<
" With result of: "
<<
result
<<
endl
;
<<
" With result of: "
<<
result
<<
endl
;
//------------------------------- PSNR GPU ----------------------------------------------------
//------------------------------- PSNR GPU ----------------------------------------------------
time
=
(
double
)
getTickCount
();
time
=
(
double
)
getTickCount
();
...
@@ -291,17 +291,17 @@ Scalar getMSSIM_GPU( const Mat& i1, const Mat& i2)
...
@@ -291,17 +291,17 @@ Scalar getMSSIM_GPU( const Mat& i1, const Mat& i2)
{
{
const
float
C1
=
6.5025
f
,
C2
=
58.5225
f
;
const
float
C1
=
6.5025
f
,
C2
=
58.5225
f
;
/***************************** INITS **********************************/
/***************************** INITS **********************************/
gpu
::
GpuMat
gI1
,
gI2
,
gs1
,
t
1
,
t
2
;
gpu
::
GpuMat
gI1
,
gI2
,
gs1
,
t
mp1
,
tmp
2
;
gI1
.
upload
(
i1
);
gI1
.
upload
(
i1
);
gI2
.
upload
(
i2
);
gI2
.
upload
(
i2
);
gI1
.
convertTo
(
t1
,
CV_MAKE_TYPE
(
CV_32F
,
gI1
.
channels
()));
gI1
.
convertTo
(
t
mp
1
,
CV_MAKE_TYPE
(
CV_32F
,
gI1
.
channels
()));
gI2
.
convertTo
(
t2
,
CV_MAKE_TYPE
(
CV_32F
,
gI2
.
channels
()));
gI2
.
convertTo
(
t
mp
2
,
CV_MAKE_TYPE
(
CV_32F
,
gI2
.
channels
()));
vector
<
gpu
::
GpuMat
>
vI1
,
vI2
;
vector
<
gpu
::
GpuMat
>
vI1
,
vI2
;
gpu
::
split
(
t1
,
vI1
);
gpu
::
split
(
t
mp
1
,
vI1
);
gpu
::
split
(
t2
,
vI2
);
gpu
::
split
(
t
mp
2
,
vI2
);
Scalar
mssim
;
Scalar
mssim
;
for
(
int
i
=
0
;
i
<
gI1
.
channels
();
++
i
)
for
(
int
i
=
0
;
i
<
gI1
.
channels
();
++
i
)
...
@@ -356,8 +356,6 @@ Scalar getMSSIM_GPU( const Mat& i1, const Mat& i2)
...
@@ -356,8 +356,6 @@ Scalar getMSSIM_GPU( const Mat& i1, const Mat& i2)
Scalar
getMSSIM_GPU_optimized
(
const
Mat
&
i1
,
const
Mat
&
i2
,
BufferMSSIM
&
b
)
Scalar
getMSSIM_GPU_optimized
(
const
Mat
&
i1
,
const
Mat
&
i2
,
BufferMSSIM
&
b
)
{
{
int
cn
=
i1
.
channels
();
const
float
C1
=
6.5025
f
,
C2
=
58.5225
f
;
const
float
C1
=
6.5025
f
,
C2
=
58.5225
f
;
/***************************** INITS **********************************/
/***************************** INITS **********************************/
...
...
samples/cpp/tutorial_code/introduction/windows_visual_studio_Opencv/Test.cpp
View file @
a2185075
...
@@ -14,7 +14,7 @@ using namespace cv;
...
@@ -14,7 +14,7 @@ using namespace cv;
double
getPSNR
(
const
Mat
&
I1
,
const
Mat
&
I2
);
double
getPSNR
(
const
Mat
&
I1
,
const
Mat
&
I2
);
Scalar
getMSSIM
(
const
Mat
&
I1
,
const
Mat
&
I2
);
Scalar
getMSSIM
(
const
Mat
&
I1
,
const
Mat
&
I2
);
void
help
()
static
void
help
()
{
{
cout
cout
<<
"
\n
--------------------------------------------------------------------------"
<<
endl
<<
"
\n
--------------------------------------------------------------------------"
<<
endl
...
@@ -26,7 +26,7 @@ void help()
...
@@ -26,7 +26,7 @@ void help()
<<
"--------------------------------------------------------------------------"
<<
endl
<<
"--------------------------------------------------------------------------"
<<
endl
<<
endl
;
<<
endl
;
}
}
int
main
(
int
argc
,
char
*
argv
[]
,
char
*
window_name
)
int
main
(
int
argc
,
char
*
argv
[])
{
{
help
();
help
();
if
(
argc
!=
5
)
if
(
argc
!=
5
)
...
@@ -89,7 +89,7 @@ int main(int argc, char *argv[], char *window_name)
...
@@ -89,7 +89,7 @@ int main(int argc, char *argv[], char *window_name)
double
psnrV
;
double
psnrV
;
Scalar
mssimV
;
Scalar
mssimV
;
while
(
true
)
//Show the image captured in the window and repeat
for
(;;
)
//Show the image captured in the window and repeat
{
{
captRefrnc
>>
frameReference
;
captRefrnc
>>
frameReference
;
captUndTst
>>
frameUnderTest
;
captUndTst
>>
frameUnderTest
;
...
@@ -124,7 +124,7 @@ int main(int argc, char *argv[], char *window_name)
...
@@ -124,7 +124,7 @@ int main(int argc, char *argv[], char *window_name)
imshow
(
WIN_RF
,
frameReference
);
imshow
(
WIN_RF
,
frameReference
);
imshow
(
WIN_UT
,
frameUnderTest
);
imshow
(
WIN_UT
,
frameUnderTest
);
c
=
cvWaitKey
(
delay
);
c
=
(
char
)
cvWaitKey
(
delay
);
if
(
c
==
27
)
break
;
if
(
c
==
27
)
break
;
}
}
...
...
samples/cpp/tutorial_code/ml/non_linear_svms/non_linear_svms.cpp
View file @
a2185075
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
using
namespace
cv
;
using
namespace
cv
;
using
namespace
std
;
using
namespace
std
;
void
help
()
static
void
help
()
{
{
cout
<<
"
\n
--------------------------------------------------------------------------"
<<
endl
cout
<<
"
\n
--------------------------------------------------------------------------"
<<
endl
<<
"This program shows Support Vector Machines for Non-Linearly Separable Data. "
<<
endl
<<
"This program shows Support Vector Machines for Non-Linearly Separable Data. "
<<
endl
...
...
samples/cpp/tutorial_code/objectDetection/objectDetection.cpp
View file @
a2185075
...
@@ -28,7 +28,7 @@ RNG rng(12345);
...
@@ -28,7 +28,7 @@ RNG rng(12345);
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
const
char
**
argv
)
int
main
(
void
)
{
{
CvCapture
*
capture
;
CvCapture
*
capture
;
Mat
frame
;
Mat
frame
;
...
@@ -41,7 +41,7 @@ int main( int argc, const char** argv )
...
@@ -41,7 +41,7 @@ int main( int argc, const char** argv )
capture
=
cvCaptureFromCAM
(
-
1
);
capture
=
cvCaptureFromCAM
(
-
1
);
if
(
capture
)
if
(
capture
)
{
{
while
(
true
)
for
(;;
)
{
{
frame
=
cvQueryFrame
(
capture
);
frame
=
cvQueryFrame
(
capture
);
...
@@ -72,10 +72,10 @@ void detectAndDisplay( Mat frame )
...
@@ -72,10 +72,10 @@ void detectAndDisplay( Mat frame )
//-- Detect faces
//-- Detect faces
face_cascade
.
detectMultiScale
(
frame_gray
,
faces
,
1.1
,
2
,
0
|
CV_HAAR_SCALE_IMAGE
,
Size
(
30
,
30
)
);
face_cascade
.
detectMultiScale
(
frame_gray
,
faces
,
1.1
,
2
,
0
|
CV_HAAR_SCALE_IMAGE
,
Size
(
30
,
30
)
);
for
(
in
t
i
=
0
;
i
<
faces
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
faces
.
size
();
i
++
)
{
{
Point
center
(
faces
[
i
].
x
+
faces
[
i
].
width
*
0.5
,
faces
[
i
].
y
+
faces
[
i
].
height
*
0.5
);
Point
center
(
faces
[
i
].
x
+
faces
[
i
].
width
/
2
,
faces
[
i
].
y
+
faces
[
i
].
height
/
2
);
ellipse
(
frame
,
center
,
Size
(
faces
[
i
].
width
*
0.5
,
faces
[
i
].
height
*
0.5
),
0
,
0
,
360
,
Scalar
(
255
,
0
,
255
),
2
,
8
,
0
);
ellipse
(
frame
,
center
,
Size
(
faces
[
i
].
width
/
2
,
faces
[
i
].
height
/
2
),
0
,
0
,
360
,
Scalar
(
255
,
0
,
255
),
2
,
8
,
0
);
Mat
faceROI
=
frame_gray
(
faces
[
i
]
);
Mat
faceROI
=
frame_gray
(
faces
[
i
]
);
std
::
vector
<
Rect
>
eyes
;
std
::
vector
<
Rect
>
eyes
;
...
@@ -83,11 +83,11 @@ void detectAndDisplay( Mat frame )
...
@@ -83,11 +83,11 @@ void detectAndDisplay( Mat frame )
//-- In each face, detect eyes
//-- In each face, detect eyes
eyes_cascade
.
detectMultiScale
(
faceROI
,
eyes
,
1.1
,
2
,
0
|
CV_HAAR_SCALE_IMAGE
,
Size
(
30
,
30
)
);
eyes_cascade
.
detectMultiScale
(
faceROI
,
eyes
,
1.1
,
2
,
0
|
CV_HAAR_SCALE_IMAGE
,
Size
(
30
,
30
)
);
for
(
in
t
j
=
0
;
j
<
eyes
.
size
();
j
++
)
for
(
size_
t
j
=
0
;
j
<
eyes
.
size
();
j
++
)
{
{
Point
center
(
faces
[
i
].
x
+
eyes
[
j
].
x
+
eyes
[
j
].
width
*
0.5
,
faces
[
i
].
y
+
eyes
[
j
].
y
+
eyes
[
j
].
height
*
0.5
);
Point
eye_center
(
faces
[
i
].
x
+
eyes
[
j
].
x
+
eyes
[
j
].
width
/
2
,
faces
[
i
].
y
+
eyes
[
j
].
y
+
eyes
[
j
].
height
/
2
);
int
radius
=
cvRound
(
(
eyes
[
j
].
width
+
eyes
[
j
].
height
)
*
0.25
);
int
radius
=
cvRound
(
(
eyes
[
j
].
width
+
eyes
[
j
].
height
)
*
0.25
);
circle
(
frame
,
center
,
radius
,
Scalar
(
255
,
0
,
0
),
3
,
8
,
0
);
circle
(
frame
,
eye_
center
,
radius
,
Scalar
(
255
,
0
,
0
),
3
,
8
,
0
);
}
}
}
}
//-- Show what you got
//-- Show what you got
...
...
samples/cpp/tutorial_code/objectDetection/objectDetection2.cpp
View file @
a2185075
...
@@ -28,7 +28,7 @@ RNG rng(12345);
...
@@ -28,7 +28,7 @@ RNG rng(12345);
/**
/**
* @function main
* @function main
*/
*/
int
main
(
int
argc
,
const
char
**
argv
)
int
main
(
void
)
{
{
CvCapture
*
capture
;
CvCapture
*
capture
;
Mat
frame
;
Mat
frame
;
...
@@ -41,7 +41,7 @@ int main( int argc, const char** argv )
...
@@ -41,7 +41,7 @@ int main( int argc, const char** argv )
capture
=
cvCaptureFromCAM
(
-
1
);
capture
=
cvCaptureFromCAM
(
-
1
);
if
(
capture
)
if
(
capture
)
{
{
while
(
true
)
for
(;;
)
{
{
frame
=
cvQueryFrame
(
capture
);
frame
=
cvQueryFrame
(
capture
);
...
@@ -73,7 +73,7 @@ void detectAndDisplay( Mat frame )
...
@@ -73,7 +73,7 @@ void detectAndDisplay( Mat frame )
//-- Detect faces
//-- Detect faces
face_cascade
.
detectMultiScale
(
frame_gray
,
faces
,
1.1
,
2
,
0
,
Size
(
80
,
80
)
);
face_cascade
.
detectMultiScale
(
frame_gray
,
faces
,
1.1
,
2
,
0
,
Size
(
80
,
80
)
);
for
(
in
t
i
=
0
;
i
<
faces
.
size
();
i
++
)
for
(
size_
t
i
=
0
;
i
<
faces
.
size
();
i
++
)
{
{
Mat
faceROI
=
frame_gray
(
faces
[
i
]
);
Mat
faceROI
=
frame_gray
(
faces
[
i
]
);
std
::
vector
<
Rect
>
eyes
;
std
::
vector
<
Rect
>
eyes
;
...
@@ -83,14 +83,14 @@ void detectAndDisplay( Mat frame )
...
@@ -83,14 +83,14 @@ void detectAndDisplay( Mat frame )
if
(
eyes
.
size
()
==
2
)
if
(
eyes
.
size
()
==
2
)
{
{
//-- Draw the face
//-- Draw the face
Point
center
(
faces
[
i
].
x
+
faces
[
i
].
width
*
0.5
,
faces
[
i
].
y
+
faces
[
i
].
height
*
0.5
);
Point
center
(
faces
[
i
].
x
+
faces
[
i
].
width
/
2
,
faces
[
i
].
y
+
faces
[
i
].
height
/
2
);
ellipse
(
frame
,
center
,
Size
(
faces
[
i
].
width
*
0.5
,
faces
[
i
].
height
*
0.5
),
0
,
0
,
360
,
Scalar
(
255
,
0
,
0
),
2
,
8
,
0
);
ellipse
(
frame
,
center
,
Size
(
faces
[
i
].
width
/
2
,
faces
[
i
].
height
/
2
),
0
,
0
,
360
,
Scalar
(
255
,
0
,
0
),
2
,
8
,
0
);
for
(
in
t
j
=
0
;
j
<
eyes
.
size
();
j
++
)
for
(
size_
t
j
=
0
;
j
<
eyes
.
size
();
j
++
)
{
//-- Draw the eyes
{
//-- Draw the eyes
Point
center
(
faces
[
i
].
x
+
eyes
[
j
].
x
+
eyes
[
j
].
width
*
0.5
,
faces
[
i
].
y
+
eyes
[
j
].
y
+
eyes
[
j
].
height
*
0.5
);
Point
eye_center
(
faces
[
i
].
x
+
eyes
[
j
].
x
+
eyes
[
j
].
width
/
2
,
faces
[
i
].
y
+
eyes
[
j
].
y
+
eyes
[
j
].
height
/
2
);
int
radius
=
cvRound
(
(
eyes
[
j
].
width
+
eyes
[
j
].
height
)
*
0.25
);
int
radius
=
cvRound
(
(
eyes
[
j
].
width
+
eyes
[
j
].
height
)
*
0.25
);
circle
(
frame
,
center
,
radius
,
Scalar
(
255
,
0
,
255
),
3
,
8
,
0
);
circle
(
frame
,
eye_
center
,
radius
,
Scalar
(
255
,
0
,
255
),
3
,
8
,
0
);
}
}
}
}
...
...
samples/gpu/CMakeLists.txt
View file @
a2185075
...
@@ -35,7 +35,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
...
@@ -35,7 +35,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
target_link_libraries
(
${
the_target
}
${
OPENCV_LINKER_LIBS
}
${
OPENCV_GPU_SAMPLES_REQUIRED_DEPS
}
)
target_link_libraries
(
${
the_target
}
${
OPENCV_LINKER_LIBS
}
${
OPENCV_GPU_SAMPLES_REQUIRED_DEPS
}
)
set_target_properties
(
${
the_target
}
PROPERTIES
set_target_properties
(
${
the_target
}
PROPERTIES
OUTPUT_NAME
"
${
name
}
_
${
project
}
"
OUTPUT_NAME
"
${
project
}
-example-
${
name
}
"
PROJECT_LABEL
"(EXAMPLE_
${
project_upper
}
)
${
name
}
"
)
PROJECT_LABEL
"(EXAMPLE_
${
project_upper
}
)
${
name
}
"
)
if
(
ENABLE_SOLUTION_FOLDERS
)
if
(
ENABLE_SOLUTION_FOLDERS
)
...
...
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