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
f2a3e7e3
Commit
f2a3e7e3
authored
Nov 28, 2010
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
converted some more samples to C++
parent
4c160acc
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
124 additions
and
185 deletions
+124
-185
3calibration.cpp
samples/cpp/3calibration.cpp
+0
-16
CMakeLists.txt
samples/cpp/CMakeLists.txt
+10
-10
calibration_artificial.cpp
samples/cpp/calibration_artificial.cpp
+0
-0
camshiftdemo.cpp
samples/cpp/camshiftdemo.cpp
+0
-0
fitellipse.cpp
samples/cpp/fitellipse.cpp
+0
-0
image.cpp
samples/cpp/image.cpp
+0
-0
inpaint.cpp
samples/cpp/inpaint.cpp
+40
-42
lkdemo.cpp
samples/cpp/lkdemo.cpp
+74
-117
stereo_calib.cpp
samples/cpp/stereo_calib.cpp
+0
-0
No files found.
samples/cpp/3calibration.cpp
View file @
f2a3e7e3
...
...
@@ -17,7 +17,6 @@ enum { DETECTION = 0, CAPTURING = 1, CALIBRATED = 2 };
void
help
()
{
printf
(
"This is a camera calibration sample that calibrates 3 horizontally placed cameras together.
\n
"
"Usage: 3calibration
\n
"
" -w <board_width> # the number of inner corners per one of board dimension
\n
"
...
...
@@ -32,20 +31,6 @@ void help()
}
static
void
calcChessboardCorners
(
Size
boardSize
,
float
squareSize
,
vector
<
Point3f
>&
corners
)
{
corners
.
resize
(
0
);
...
...
@@ -56,7 +41,6 @@ static void calcChessboardCorners(Size boardSize, float squareSize, vector<Point
float
(
i
*
squareSize
),
0
));
}
static
bool
run3Calibration
(
vector
<
vector
<
Point2f
>
>
imagePoints1
,
vector
<
vector
<
Point2f
>
>
imagePoints2
,
vector
<
vector
<
Point2f
>
>
imagePoints3
,
...
...
samples/cpp/CMakeLists.txt
View file @
f2a3e7e3
...
...
@@ -29,16 +29,16 @@ if (BUILD_EXAMPLES)
# ---------------------------------------------
MACRO
(
MY_DEFINE_EXAMPLE name srcs
)
set
(
the_target
"example_
${
name
}
"
)
add_executable
(
${
the_target
}
${
srcs
}
)
set_target_properties
(
${
the_target
}
PROPERTIES
OUTPUT_NAME
"
${
name
}
"
PROJECT_LABEL
"(EXAMPLE)
${
name
}
"
)
add_dependencies
(
${
the_target
}
opencv_core opencv_flann opencv_imgproc opencv_highgui
opencv_ml opencv_video opencv_objdetect opencv_features2d
opencv_calib3d opencv_legacy opencv_contrib
)
target_link_libraries
(
${
the_target
}
${
OPENCV_LINKER_LIBS
}
opencv_core
opencv_flann opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_objdetect
opencv_features2d opencv_calib3d opencv_legacy opencv_contrib
)
add_executable
(
${
the_target
}
${
srcs
}
)
set_target_properties
(
${
the_target
}
PROPERTIES
OUTPUT_NAME
"
${
name
}
"
PROJECT_LABEL
"(EXAMPLE)
${
name
}
"
)
add_dependencies
(
${
the_target
}
opencv_core opencv_flann opencv_imgproc opencv_highgui
opencv_ml opencv_video opencv_objdetect opencv_features2d
opencv_calib3d opencv_legacy opencv_contrib
)
target_link_libraries
(
${
the_target
}
${
OPENCV_LINKER_LIBS
}
opencv_core
opencv_flann opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_objdetect
opencv_features2d opencv_calib3d opencv_legacy opencv_contrib
)
if
(
WIN32
)
install
(
TARGETS
${
the_target
}
...
...
samples/c/calibration_artificial.cpp
→
samples/c
pp
/calibration_artificial.cpp
View file @
f2a3e7e3
This diff is collapsed.
Click to expand it.
samples/cpp/camshiftdemo.cpp
View file @
f2a3e7e3
This diff is collapsed.
Click to expand it.
samples/c/fitellipse.cpp
→
samples/c
pp
/fitellipse.cpp
View file @
f2a3e7e3
File moved
samples/c/image.cpp
→
samples/c
pp
/image.cpp
View file @
f2a3e7e3
File moved
samples/c/inpaint.cpp
→
samples/c
pp
/inpaint.cpp
View file @
f2a3e7e3
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc
_c.h
"
#include "opencv2/imgproc/imgproc
.hpp
"
#include <
stdio.h
>
#include <
iostream
>
IplImage
*
inpaint_mask
=
0
;
IplImage
*
img0
=
0
,
*
img
=
0
,
*
inpainted
=
0
;
CvPoint
prev_pt
=
{
-
1
,
-
1
};
using
namespace
cv
;
using
namespace
std
;
void
on_mouse
(
int
event
,
int
x
,
int
y
,
int
flags
,
void
*
)
{
if
(
!
img
)
return
;
Mat
img
,
inpaintMask
;
Point
prevPt
(
-
1
,
-
1
);
void
onMouse
(
int
event
,
int
x
,
int
y
,
int
flags
,
void
*
)
{
if
(
event
==
CV_EVENT_LBUTTONUP
||
!
(
flags
&
CV_EVENT_FLAG_LBUTTON
)
)
prev
_pt
=
cv
Point
(
-
1
,
-
1
);
prev
Pt
=
Point
(
-
1
,
-
1
);
else
if
(
event
==
CV_EVENT_LBUTTONDOWN
)
prev
_pt
=
cv
Point
(
x
,
y
);
prev
Pt
=
Point
(
x
,
y
);
else
if
(
event
==
CV_EVENT_MOUSEMOVE
&&
(
flags
&
CV_EVENT_FLAG_LBUTTON
)
)
{
CvPoint
pt
=
cvPoin
t
(
x
,
y
);
if
(
prev
_p
t
.
x
<
0
)
prev
_p
t
=
pt
;
cvLine
(
inpaint_mask
,
prev_pt
,
pt
,
cvScalarA
ll
(
255
),
5
,
8
,
0
);
cvLine
(
img
,
prev_pt
,
pt
,
cvScalarA
ll
(
255
),
5
,
8
,
0
);
prev
_p
t
=
pt
;
cvShowImage
(
"image"
,
img
);
Point
p
t
(
x
,
y
);
if
(
prev
P
t
.
x
<
0
)
prev
P
t
=
pt
;
line
(
inpaintMask
,
prevPt
,
pt
,
Scalar
::
a
ll
(
255
),
5
,
8
,
0
);
line
(
img
,
prevPt
,
pt
,
Scalar
::
a
ll
(
255
),
5
,
8
,
0
);
prev
P
t
=
pt
;
imshow
(
"image"
,
img
);
}
}
...
...
@@ -32,49 +31,48 @@ void on_mouse( int event, int x, int y, int flags, void* )
int
main
(
int
argc
,
char
**
argv
)
{
char
*
filename
=
argc
>=
2
?
argv
[
1
]
:
(
char
*
)
"fruits.jpg"
;
if
(
(
img0
=
cvLoadImage
(
filename
,
-
1
))
==
0
)
Mat
img0
=
imread
(
filename
,
-
1
);
if
(
img0
.
empty
())
{
cout
<<
"Usage: inpaint <image_name>
\n
"
;
return
0
;
}
printf
(
"Hot keys:
\n
"
cout
<<
"Hot keys:
\n
"
"
\t
ESC - quit the program
\n
"
"
\t
r - restore the original image
\n
"
"
\t
i or SPACE - run inpainting algorithm
\n
"
"
\t\t
(before running it, paint something on the image)
\n
"
)
;
"
\t\t
(before running it, paint something on the image)
\n
"
;
cvN
amedWindow
(
"image"
,
1
);
n
amedWindow
(
"image"
,
1
);
img
=
cvCloneImage
(
img0
);
inpainted
=
cvCloneImage
(
img0
);
inpaint_mask
=
cvCreateImage
(
cvGetSize
(
img
),
8
,
1
);
img
=
img0
.
clone
();
inpaintMask
=
Mat
::
zeros
(
img
.
size
(),
CV_8U
);
cvZero
(
inpaint_mask
);
cvZero
(
inpainted
);
cvShowImage
(
"image"
,
img
);
cvShowImage
(
"inpainted image"
,
inpainted
);
cvSetMouseCallback
(
"image"
,
on_mouse
,
0
);
imshow
(
"image"
,
img
);
setMouseCallback
(
"image"
,
onMouse
,
0
);
for
(;;)
{
int
c
=
cvWaitKey
(
0
);
char
c
=
(
char
)
waitKey
(
);
if
(
(
char
)
c
==
27
)
if
(
c
==
27
)
break
;
if
(
(
char
)
c
==
'r'
)
if
(
c
==
'r'
)
{
cvZero
(
inpaint_mask
);
cvCopy
(
img0
,
img
);
cvShowImage
(
"image"
,
img
);
inpaintMask
=
Scalar
::
all
(
0
);
img0
.
copyTo
(
img
);
imshow
(
"image"
,
img
);
}
if
(
(
char
)
c
==
'i'
||
(
char
)
c
==
' '
)
if
(
c
==
'i'
||
c
==
' '
)
{
cvNamedWindow
(
"inpainted image"
,
1
)
;
cvInpaint
(
img
,
inpaint_mask
,
inpainted
,
3
,
CV_INPAINT_TELEA
);
cvShowImage
(
"inpainted image"
,
inpainted
);
Mat
inpainted
;
inpaint
(
img
,
inpaintMask
,
inpainted
,
3
,
CV_INPAINT_TELEA
);
imshow
(
"inpainted image"
,
inpainted
);
}
}
return
1
;
return
0
;
}
samples/cpp/lkdemo.cpp
View file @
f2a3e7e3
#include "opencv2/video/tracking.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <ctype.h>
#include <stdio.h>
IplImage
*
image
=
0
,
*
grey
=
0
,
*
prev_grey
=
0
,
*
pyramid
=
0
,
*
prev_pyramid
=
0
,
*
swap_temp
;
using
namespace
cv
;
using
namespace
std
;
int
win_size
=
10
;
const
int
MAX_COUNT
=
500
;
CvPoint2D32f
*
points
[
2
]
=
{
0
,
0
},
*
swap_points
;
char
*
status
=
0
;
int
count
=
0
;
int
need_to_init
=
0
;
int
night_mode
=
0
;
int
flags
=
0
;
int
add_remove_pt
=
0
;
CvPoint
pt
;
Point2f
pt
;
bool
addRemovePt
=
false
;
void
on_mouse
(
int
event
,
int
x
,
int
y
,
int
flags
,
void
*
param
)
void
onMouse
(
int
event
,
int
x
,
int
y
,
int
flags
,
void
*
param
)
{
if
(
!
image
)
return
;
if
(
image
->
origin
)
y
=
image
->
height
-
y
;
if
(
event
==
CV_EVENT_LBUTTONDOWN
)
{
pt
=
cvPoint
(
x
,
y
);
add
_remove_pt
=
1
;
pt
=
Point2f
((
float
)
x
,(
float
)
y
);
add
RemovePt
=
true
;
}
}
int
main
(
int
argc
,
char
**
argv
)
{
CvCapture
*
capture
=
0
;
VideoCapture
cap
;
TermCriteria
termcrit
(
CV_TERMCRIT_ITER
|
CV_TERMCRIT_EPS
,
20
,
0.03
);
Size
winSize
(
10
,
10
);
const
int
MAX_COUNT
=
500
;
bool
needToInit
=
false
;
bool
nightMode
=
false
;
if
(
argc
==
1
||
(
argc
==
2
&&
strlen
(
argv
[
1
])
==
1
&&
isdigit
(
argv
[
1
][
0
])))
cap
ture
=
cvCaptureFromCAM
(
argc
==
2
?
argv
[
1
][
0
]
-
'0'
:
0
);
cap
.
open
(
argc
==
2
?
argv
[
1
][
0
]
-
'0'
:
0
);
else
if
(
argc
==
2
)
cap
ture
=
cvCaptureFromAVI
(
argv
[
1
]
);
cap
.
open
(
argv
[
1
]
);
if
(
!
cap
ture
)
if
(
!
cap
.
isOpened
()
)
{
fprintf
(
stderr
,
"Could not initialize capturing...
\n
"
)
;
return
-
1
;
cout
<<
"Could not initialize capturing...
\n
"
;
return
0
;
}
/* print a welcome message, and the OpenCV version */
printf
(
"Welcome to lkdemo, using OpenCV version %s (%d.%d.%d)
\n
"
,
CV_VERSION
,
CV_MAJOR_VERSION
,
CV_MINOR_VERSION
,
CV_SUBMINOR_VERSION
);
// print a welcome message, and the OpenCV version
cout
<<
"Welcome to lkdemo, using OpenCV version %s
\n
"
<<
CV_VERSION
;
printf
(
"
Hot keys:
\n
"
cout
<<
"
\n
Hot keys:
\n
"
"
\t
ESC - quit the program
\n
"
"
\t
r - auto-initialize tracking
\n
"
"
\t
c - delete all the points
\n
"
"
\t
n - switch the
\"
night
\"
mode on/off
\n
"
"To add/remove a feature point click it
\n
"
)
;
"To add/remove a feature point click it
\n
"
;
cvNamedWindow
(
"LkDemo"
,
0
);
cvSetMouseCallback
(
"LkDemo"
,
on_m
ouse
,
0
);
namedWindow
(
"LK Demo"
,
1
);
setMouseCallback
(
"LK Demo"
,
onM
ouse
,
0
);
Mat
gray
,
prevGray
,
image
;
vector
<
Point2f
>
points
[
2
];
for
(;;)
{
IplImage
*
frame
=
0
;
int
i
,
k
,
c
;
frame
=
cvQueryFrame
(
capture
);
if
(
!
frame
)
Mat
frame
;
cap
>>
frame
;
if
(
frame
.
empty
()
)
break
;
if
(
!
image
)
{
/* allocate all the buffers */
image
=
cvCreateImage
(
cvGetSize
(
frame
),
8
,
3
);
image
->
origin
=
frame
->
origin
;
grey
=
cvCreateImage
(
cvGetSize
(
frame
),
8
,
1
);
prev_grey
=
cvCreateImage
(
cvGetSize
(
frame
),
8
,
1
);
pyramid
=
cvCreateImage
(
cvGetSize
(
frame
),
8
,
1
);
prev_pyramid
=
cvCreateImage
(
cvGetSize
(
frame
),
8
,
1
);
points
[
0
]
=
(
CvPoint2D32f
*
)
cvAlloc
(
MAX_COUNT
*
sizeof
(
points
[
0
][
0
]));
points
[
1
]
=
(
CvPoint2D32f
*
)
cvAlloc
(
MAX_COUNT
*
sizeof
(
points
[
0
][
0
]));
status
=
(
char
*
)
cvAlloc
(
MAX_COUNT
);
flags
=
0
;
}
cvCopy
(
frame
,
image
,
0
);
cvCvtColor
(
image
,
grey
,
CV_BGR2GRAY
);
frame
.
copyTo
(
image
);
cvtColor
(
image
,
gray
,
CV_BGR2GRAY
);
if
(
night
_m
ode
)
cvZero
(
image
);
if
(
night
M
ode
)
image
=
Scalar
::
all
(
0
);
if
(
need
_to_i
nit
)
if
(
need
ToI
nit
)
{
/* automatic initialization */
IplImage
*
eig
=
cvCreateImage
(
cvGetSize
(
grey
),
32
,
1
);
IplImage
*
temp
=
cvCreateImage
(
cvGetSize
(
grey
),
32
,
1
);
double
quality
=
0.01
;
double
min_distance
=
10
;
count
=
MAX_COUNT
;
cvGoodFeaturesToTrack
(
grey
,
eig
,
temp
,
points
[
1
],
&
count
,
quality
,
min_distance
,
0
,
3
,
0
,
0.04
);
cvFindCornerSubPix
(
grey
,
points
[
1
],
count
,
cvSize
(
win_size
,
win_size
),
cvSize
(
-
1
,
-
1
),
cvTermCriteria
(
CV_TERMCRIT_ITER
|
CV_TERMCRIT_EPS
,
20
,
0.03
));
cvReleaseImage
(
&
eig
);
cvReleaseImage
(
&
temp
);
add_remove_pt
=
0
;
// automatic initialization
goodFeaturesToTrack
(
gray
,
points
[
1
],
MAX_COUNT
,
0.01
,
10
,
Mat
(),
3
,
0
,
0.04
);
cornerSubPix
(
gray
,
points
[
1
],
winSize
,
Size
(
-
1
,
-
1
),
termcrit
);
addRemovePt
=
false
;
}
else
if
(
count
>
0
)
else
if
(
!
points
[
0
].
empty
()
)
{
cvCalcOpticalFlowPyrLK
(
prev_grey
,
grey
,
prev_pyramid
,
pyramid
,
points
[
0
],
points
[
1
],
count
,
cvSize
(
win_size
,
win_size
),
3
,
status
,
0
,
cvTermCriteria
(
CV_TERMCRIT_ITER
|
CV_TERMCRIT_EPS
,
20
,
0.03
),
flags
);
flags
|=
CV_LKFLOW_PYR_A_READY
;
for
(
i
=
k
=
0
;
i
<
count
;
i
++
)
vector
<
uchar
>
status
;
vector
<
float
>
err
;
if
(
prevGray
.
empty
())
gray
.
copyTo
(
prevGray
);
calcOpticalFlowPyrLK
(
prevGray
,
gray
,
points
[
0
],
points
[
1
],
status
,
err
,
winSize
,
3
,
termcrit
,
0
);
size_t
i
,
k
;
for
(
i
=
k
=
0
;
i
<
points
[
1
].
size
();
i
++
)
{
if
(
add
_remove_p
t
)
if
(
add
RemoveP
t
)
{
double
dx
=
pt
.
x
-
points
[
1
][
i
].
x
;
double
dy
=
pt
.
y
-
points
[
1
][
i
].
y
;
if
(
dx
*
dx
+
dy
*
dy
<=
25
)
if
(
norm
(
pt
-
points
[
1
][
i
])
<=
5
)
{
add
_remove_pt
=
0
;
add
RemovePt
=
false
;
continue
;
}
}
...
...
@@ -137,51 +101,44 @@ int main( int argc, char** argv )
continue
;
points
[
1
][
k
++
]
=
points
[
1
][
i
];
c
vCircle
(
image
,
cvPointFrom32f
(
points
[
1
][
i
]),
3
,
CV_RGB
(
0
,
255
,
0
),
-
1
,
8
,
0
);
c
ircle
(
image
,
points
[
1
][
i
],
3
,
Scalar
(
0
,
255
,
0
),
-
1
,
8
);
}
count
=
k
;
points
[
1
].
resize
(
k
)
;
}
if
(
add
_remove_pt
&&
count
<
MAX_COUNT
)
if
(
add
RemovePt
&&
points
[
1
].
size
()
<
MAX_COUNT
)
{
points
[
1
][
count
++
]
=
cvPointTo32f
(
pt
)
;
cvFindCornerSubPix
(
grey
,
points
[
1
]
+
count
-
1
,
1
,
cvSize
(
win_size
,
win_size
),
cvSize
(
-
1
,
-
1
),
cvTermCriteria
(
CV_TERMCRIT_ITER
|
CV_TERMCRIT_EPS
,
20
,
0.03
)
);
add
_remove_pt
=
0
;
vector
<
Point2f
>
tmp
;
tmp
.
push_back
(
pt
);
cornerSubPix
(
gray
,
tmp
,
winSize
,
cvSize
(
-
1
,
-
1
),
termcrit
);
points
[
1
].
push_back
(
tmp
[
0
]
);
add
RemovePt
=
false
;
}
CV_SWAP
(
prev_grey
,
grey
,
swap_temp
);
CV_SWAP
(
prev_pyramid
,
pyramid
,
swap_temp
);
CV_SWAP
(
points
[
0
],
points
[
1
],
swap_points
);
need_to_init
=
0
;
cvShowImage
(
"LkDemo"
,
image
);
needToInit
=
false
;
imshow
(
"LK Demo"
,
image
);
c
=
cvW
aitKey
(
10
);
if
(
(
char
)
c
==
27
)
c
har
c
=
(
char
)
w
aitKey
(
10
);
if
(
c
==
27
)
break
;
switch
(
(
char
)
c
)
switch
(
c
)
{
case
'r'
:
need
_to_init
=
1
;
need
ToInit
=
true
;
break
;
case
'c'
:
count
=
0
;
points
[
1
].
clear
()
;
break
;
case
'n'
:
night
_mode
^=
1
;
night
Mode
=
!
nightMode
;
break
;
default:
;
}
std
::
swap
(
points
[
1
],
points
[
0
]);
swap
(
prevGray
,
gray
);
}
cvReleaseCapture
(
&
capture
);
cvDestroyWindow
(
"LkDemo"
);
return
0
;
}
#ifdef _EiC
main
(
1
,
"lkdemo.c"
);
#endif
samples/cpp/stereo_calib.cpp
View file @
f2a3e7e3
This diff is collapsed.
Click to expand it.
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