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
4d86e214
Commit
4d86e214
authored
Oct 21, 2013
by
Ilya Lavrenov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
OpenCL examples refactoring
parent
aec7d9c1
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
128 additions
and
158 deletions
+128
-158
adaptive_bilateral_filter.cpp
samples/ocl/adaptive_bilateral_filter.cpp
+18
-13
bgfg_segm.cpp
samples/ocl/bgfg_segm.cpp
+9
-16
clahe.cpp
samples/ocl/clahe.cpp
+30
-28
facedetect.cpp
samples/ocl/facedetect.cpp
+16
-31
hog.cpp
samples/ocl/hog.cpp
+9
-1
pyrlk_optical_flow.cpp
samples/ocl/pyrlk_optical_flow.cpp
+8
-12
squares.cpp
samples/ocl/squares.cpp
+13
-9
stereo_match.cpp
samples/ocl/stereo_match.cpp
+5
-1
surf_matcher.cpp
samples/ocl/surf_matcher.cpp
+14
-20
tvl1_optical_flow.cpp
samples/ocl/tvl1_optical_flow.cpp
+6
-27
No files found.
samples/ocl/adaptive_bilateral_filter.cpp
View file @
4d86e214
...
...
@@ -12,17 +12,27 @@ int main( int argc, const char** argv )
{
const
char
*
keys
=
"{ i | input | | specify input image }"
"{ k | ksize | 5 | specify kernel size }"
;
"{ k | ksize | 5 | specify kernel size }"
"{ h | help | false | print help message }"
;
CommandLineParser
cmd
(
argc
,
argv
,
keys
);
if
(
cmd
.
get
<
bool
>
(
"help"
))
{
cout
<<
"Usage : adaptive_bilateral_filter [options]"
<<
endl
;
cout
<<
"Available options:"
<<
endl
;
cmd
.
printParams
();
return
EXIT_SUCCESS
;
}
string
src_path
=
cmd
.
get
<
string
>
(
"i"
);
int
ks
=
cmd
.
get
<
int
>
(
"k"
);
const
char
*
winName
[]
=
{
"input"
,
"adaptive bilateral CPU"
,
"adaptive bilateral OpenCL"
,
"bilateralFilter OpenCL"
};
Mat
src
=
imread
(
src_path
);
Mat
abFilterCPU
;
if
(
src
.
empty
())
{
//
cout << "error read image: " << src_path << endl;
return
-
1
;
Mat
src
=
imread
(
src_path
)
,
abFilterCPU
;
if
(
src
.
empty
())
{
cout
<<
"error read image: "
<<
src_path
<<
endl
;
return
EXIT_FAILURE
;
}
ocl
::
oclMat
dsrc
(
src
),
dABFilter
,
dBFilter
;
...
...
@@ -32,17 +42,12 @@ int main( int argc, const char** argv )
ocl
::
adaptiveBilateralFilter
(
dsrc
,
dABFilter
,
ksize
,
10
);
ocl
::
bilateralFilter
(
dsrc
,
dBFilter
,
ks
,
30
,
9
);
Mat
abFilter
=
dABFilter
;
Mat
bFilter
=
dBFilter
;
Mat
abFilter
=
dABFilter
,
bFilter
=
dBFilter
;
imshow
(
winName
[
0
],
src
);
imshow
(
winName
[
1
],
abFilterCPU
);
imshow
(
winName
[
2
],
abFilter
);
imshow
(
winName
[
3
],
bFilter
);
waitKey
();
return
0
;
return
EXIT_SUCCESS
;
}
samples/ocl/bgfg_segm.cpp
View file @
4d86e214
...
...
@@ -14,7 +14,6 @@ using namespace cv::ocl;
int
main
(
int
argc
,
const
char
**
argv
)
{
cv
::
CommandLineParser
cmd
(
argc
,
argv
,
"{ c | camera | false | use camera }"
"{ f | file | 768x576.avi | input video file }"
...
...
@@ -26,7 +25,7 @@ int main(int argc, const char** argv)
cout
<<
"Usage : bgfg_segm [options]"
<<
endl
;
cout
<<
"Available options:"
<<
endl
;
cmd
.
printParams
();
return
0
;
return
EXIT_SUCCESS
;
}
bool
useCamera
=
cmd
.
get
<
bool
>
(
"camera"
);
...
...
@@ -36,13 +35,12 @@ int main(int argc, const char** argv)
if
(
method
!=
"mog"
&&
method
!=
"mog2"
)
{
cerr
<<
"Incorrect method"
<<
endl
;
return
-
1
;
return
EXIT_FAILURE
;
}
int
m
=
method
==
"mog"
?
M_MOG
:
M_MOG2
;
VideoCapture
cap
;
if
(
useCamera
)
cap
.
open
(
0
);
else
...
...
@@ -50,8 +48,8 @@ int main(int argc, const char** argv)
if
(
!
cap
.
isOpened
())
{
c
err
<<
"can not open camera or video file"
<<
endl
;
return
-
1
;
c
out
<<
"can not open camera or video file"
<<
endl
;
return
EXIT_FAILURE
;
}
Mat
frame
;
...
...
@@ -62,15 +60,11 @@ int main(int argc, const char** argv)
cv
::
ocl
::
MOG
mog
;
cv
::
ocl
::
MOG2
mog2
;
oclMat
d_fgmask
;
oclMat
d_fgimg
;
oclMat
d_bgimg
;
oclMat
d_fgmask
,
d_fgimg
,
d_bgimg
;
d_fgimg
.
create
(
d_frame
.
size
(),
d_frame
.
type
());
Mat
fgmask
;
Mat
fgimg
;
Mat
bgimg
;
Mat
fgmask
,
fgimg
,
bgimg
;
switch
(
m
)
{
...
...
@@ -83,7 +77,7 @@ int main(int argc, const char** argv)
break
;
}
for
(;;)
for
(;;)
{
cap
>>
frame
;
if
(
frame
.
empty
())
...
...
@@ -123,10 +117,9 @@ int main(int argc, const char** argv)
if
(
!
bgimg
.
empty
())
imshow
(
"mean background image"
,
bgimg
);
int
key
=
waitKey
(
30
);
if
(
key
==
27
)
if
(
27
==
waitKey
(
30
))
break
;
}
return
0
;
return
EXIT_SUCCESS
;
}
samples/ocl/clahe.cpp
View file @
4d86e214
...
...
@@ -9,14 +9,12 @@ using namespace std;
Ptr
<
CLAHE
>
pFilter
;
int
tilesize
;
int
cliplimit
;
string
outfile
;
static
void
TSize_Callback
(
int
pos
)
{
if
(
pos
==
0
)
{
pFilter
->
setTilesGridSize
(
Size
(
1
,
1
));
}
else
pFilter
->
setTilesGridSize
(
Size
(
tilesize
,
tilesize
));
}
...
...
@@ -31,63 +29,64 @@ int main(int argc, char** argv)
"{ i | input | | specify input image }"
"{ c | camera | 0 | specify camera id }"
"{ s | use_cpu | false | use cpu algorithm }"
"{ o | output | clahe_output.jpg | specify output save path}"
;
"{ o | output | clahe_output.jpg | specify output save path}"
"{ h | help | false | print help message }"
;
cv
::
CommandLineParser
cmd
(
argc
,
argv
,
keys
);
if
(
cmd
.
get
<
bool
>
(
"help"
))
{
cout
<<
"Usage : clahe [options]"
<<
endl
;
cout
<<
"Available options:"
<<
endl
;
cmd
.
printParams
();
return
EXIT_SUCCESS
;
}
CommandLineParser
cmd
(
argc
,
argv
,
keys
);
string
infile
=
cmd
.
get
<
string
>
(
"i"
);
outfile
=
cmd
.
get
<
string
>
(
"o"
);
string
infile
=
cmd
.
get
<
string
>
(
"i"
),
outfile
=
cmd
.
get
<
string
>
(
"o"
);
int
camid
=
cmd
.
get
<
int
>
(
"c"
);
bool
use_cpu
=
cmd
.
get
<
bool
>
(
"s"
);
CvCapture
*
capture
=
0
;
bool
running
=
true
;
namedWindow
(
"CLAHE"
);
createTrackbar
(
"Tile Size"
,
"CLAHE"
,
&
tilesize
,
32
,
(
TrackbarCallback
)
TSize_Callback
);
createTrackbar
(
"Clip Limit"
,
"CLAHE"
,
&
cliplimit
,
20
,
(
TrackbarCallback
)
Clip_Callback
);
Mat
frame
,
outframe
;
ocl
::
oclMat
d_outframe
;
ocl
::
oclMat
d_outframe
,
d_frame
;
int
cur_clip
;
Size
cur_tilesize
;
if
(
use_cpu
)
{
pFilter
=
createCLAHE
();
}
else
{
pFilter
=
ocl
::
createCLAHE
();
}
pFilter
=
use_cpu
?
createCLAHE
()
:
ocl
::
createCLAHE
();
cur_clip
=
(
int
)
pFilter
->
getClipLimit
();
cur_tilesize
=
pFilter
->
getTilesGridSize
();
setTrackbarPos
(
"Tile Size"
,
"CLAHE"
,
cur_tilesize
.
width
);
setTrackbarPos
(
"Clip Limit"
,
"CLAHE"
,
cur_clip
);
if
(
infile
!=
""
)
{
frame
=
imread
(
infile
);
if
(
frame
.
empty
())
{
cout
<<
"error read image: "
<<
infile
<<
endl
;
return
-
1
;
return
EXIT_FAILURE
;
}
}
else
{
capture
=
cvCaptureFromCAM
(
camid
);
}
cout
<<
"
\n
Controls:
\n
"
<<
"
\t
o - save output image
\n
"
<<
"
\t
ESC - exit
\n
"
;
while
(
running
)
for
(;;)
{
if
(
capture
)
frame
=
cvQueryFrame
(
capture
);
else
frame
=
imread
(
infile
);
if
(
frame
.
empty
())
{
continue
;
}
if
(
use_cpu
)
{
cvtColor
(
frame
,
frame
,
COLOR_BGR2GRAY
);
...
...
@@ -95,15 +94,18 @@ int main(int argc, char** argv)
}
else
{
ocl
::
oclMat
d_frame
(
frame
);
ocl
::
cvtColor
(
d_frame
,
d_outframe
,
COLOR_BGR2GRAY
);
ocl
::
cvtColor
(
d_frame
=
frame
,
d_outframe
,
COLOR_BGR2GRAY
);
pFilter
->
apply
(
d_outframe
,
d_outframe
);
d_outframe
.
download
(
outframe
);
}
imshow
(
"CLAHE"
,
outframe
);
char
key
=
(
char
)
cvWaitKey
(
3
);
if
(
key
==
'o'
)
imwrite
(
outfile
,
outframe
);
else
if
(
key
==
27
)
running
=
false
;
if
(
key
==
'o'
)
imwrite
(
outfile
,
outframe
);
else
if
(
key
==
27
)
break
;
}
return
0
;
return
EXIT_SUCCESS
;
}
samples/ocl/facedetect.cpp
View file @
4d86e214
...
...
@@ -28,27 +28,29 @@ static void workBegin()
{
work_begin
=
getTickCount
();
}
static
void
workEnd
()
{
work_end
+=
(
getTickCount
()
-
work_begin
);
}
static
double
getTime
()
{
return
work_end
/
((
double
)
cvGetTickFrequency
()
*
1000.
);
}
void
detect
(
Mat
&
img
,
vector
<
Rect
>&
faces
,
static
void
detect
(
Mat
&
img
,
vector
<
Rect
>&
faces
,
ocl
::
OclCascadeClassifierBuf
&
cascade
,
double
scale
,
bool
calTime
);
void
detectCPU
(
Mat
&
img
,
vector
<
Rect
>&
faces
,
static
void
detectCPU
(
Mat
&
img
,
vector
<
Rect
>&
faces
,
CascadeClassifier
&
cascade
,
double
scale
,
bool
calTime
);
void
Draw
(
Mat
&
img
,
vector
<
Rect
>&
faces
,
double
scale
);
static
void
Draw
(
Mat
&
img
,
vector
<
Rect
>&
faces
,
double
scale
);
// This function test if gpu_rst matches cpu_rst.
...
...
@@ -56,7 +58,6 @@ void Draw(Mat& img, vector<Rect>& faces, double scale);
// Else if will return (total diff of each cpu and gpu rects covered pixels)/(total cpu rects covered pixels)
double
checkRectSimilarity
(
Size
sz
,
vector
<
Rect
>&
cpu_rst
,
vector
<
Rect
>&
gpu_rst
);
int
main
(
int
argc
,
const
char
**
argv
)
{
const
char
*
keys
=
...
...
@@ -72,10 +73,12 @@ int main( int argc, const char** argv )
CommandLineParser
cmd
(
argc
,
argv
,
keys
);
if
(
cmd
.
get
<
bool
>
(
"help"
))
{
cout
<<
"Usage : facedetect [options]"
<<
endl
;
cout
<<
"Available options:"
<<
endl
;
cmd
.
printParams
();
return
0
;
return
EXIT_SUCCESS
;
}
CvCapture
*
capture
=
0
;
Mat
frame
,
frameCopy
,
image
;
...
...
@@ -89,8 +92,8 @@ int main( int argc, const char** argv )
if
(
!
cascade
.
load
(
cascadeName
)
||
!
cpu_cascade
.
load
(
cascadeName
)
)
{
c
err
<<
"ERROR: Could not load classifier cascade"
<<
endl
;
return
-
1
;
c
out
<<
"ERROR: Could not load classifier cascade"
<<
endl
;
return
EXIT_FAILURE
;
}
if
(
inputName
.
empty
()
)
...
...
@@ -99,26 +102,18 @@ int main( int argc, const char** argv )
if
(
!
capture
)
cout
<<
"Capture from CAM 0 didn't work"
<<
endl
;
}
else
if
(
inputName
.
size
()
)
else
{
image
=
imread
(
inputName
,
1
);
image
=
imread
(
inputName
,
CV_LOAD_IMAGE_COLOR
);
if
(
image
.
empty
()
)
{
capture
=
cvCaptureFromAVI
(
inputName
.
c_str
()
);
if
(
!
capture
)
cout
<<
"Capture from AVI didn't work"
<<
endl
;
return
-
1
;
}
return
EXIT_FAILURE
;
}
else
{
image
=
imread
(
"lena.jpg"
,
1
);
if
(
image
.
empty
())
cout
<<
"Couldn't read lena.jpg"
<<
endl
;
return
-
1
;
}
cvNamedWindow
(
"result"
,
1
);
if
(
capture
)
{
...
...
@@ -134,24 +129,16 @@ int main( int argc, const char** argv )
frame
.
copyTo
(
frameCopy
);
else
flip
(
frame
,
frameCopy
,
0
);
if
(
useCPU
)
{
detectCPU
(
frameCopy
,
faces
,
cpu_cascade
,
scale
,
false
);
}
else
{
detect
(
frameCopy
,
faces
,
cascade
,
scale
,
false
);
}
Draw
(
frameCopy
,
faces
,
scale
);
if
(
waitKey
(
10
)
>=
0
)
goto
_cleanup_
;
break
;
}
waitKey
(
0
);
_cleanup_:
cvReleaseCapture
(
&
capture
);
}
else
...
...
@@ -164,9 +151,7 @@ _cleanup_:
{
cout
<<
"loop"
<<
i
<<
endl
;
if
(
useCPU
)
{
detectCPU
(
image
,
faces
,
cpu_cascade
,
scale
,
i
==
0
?
false
:
true
);
}
else
{
detect
(
image
,
faces
,
cascade
,
scale
,
i
==
0
?
false
:
true
);
...
...
samples/ocl/hog.cpp
View file @
4d86e214
...
...
@@ -72,6 +72,14 @@ int main(int argc, char** argv)
"{ l |larger_win| false | use 64x128 window}"
"{ o | output | | specify output path when input is images}"
;
CommandLineParser
cmd
(
argc
,
argv
,
keys
);
if
(
cmd
.
get
<
bool
>
(
"help"
))
{
cout
<<
"Usage : hog [options]"
<<
endl
;
cout
<<
"Available options:"
<<
endl
;
cmd
.
printParams
();
return
EXIT_SUCCESS
;
}
App
app
(
cmd
);
try
{
...
...
@@ -89,7 +97,7 @@ int main(int argc, char** argv)
{
return
cout
<<
"unknown exception"
<<
endl
,
1
;
}
return
0
;
return
EXIT_SUCCESS
;
}
App
::
App
(
CommandLineParser
&
cmd
)
...
...
samples/ocl/pyrlk_optical_flow.cpp
View file @
4d86e214
...
...
@@ -44,7 +44,8 @@ static void download(const oclMat& d_mat, vector<uchar>& vec)
d_mat
.
download
(
mat
);
}
static
void
drawArrows
(
Mat
&
frame
,
const
vector
<
Point2f
>&
prevPts
,
const
vector
<
Point2f
>&
nextPts
,
const
vector
<
uchar
>&
status
,
Scalar
line_color
=
Scalar
(
0
,
0
,
255
))
static
void
drawArrows
(
Mat
&
frame
,
const
vector
<
Point2f
>&
prevPts
,
const
vector
<
Point2f
>&
nextPts
,
const
vector
<
uchar
>&
status
,
Scalar
line_color
=
Scalar
(
0
,
0
,
255
))
{
for
(
size_t
i
=
0
;
i
<
prevPts
.
size
();
++
i
)
{
...
...
@@ -104,7 +105,7 @@ int main(int argc, const char* argv[])
cout
<<
"Usage: pyrlk_optical_flow [options]"
<<
endl
;
cout
<<
"Available options:"
<<
endl
;
cmd
.
printParams
();
return
0
;
return
EXIT_SUCCESS
;
}
bool
defaultPicturesFail
=
false
;
...
...
@@ -136,7 +137,7 @@ int main(int argc, const char* argv[])
Mat
frame0Gray
,
frame1Gray
;
Mat
ptr0
,
ptr1
;
if
(
vdofile
==
""
)
if
(
vdofile
.
empty
()
)
capture
=
cvCaptureFromCAM
(
inputName
);
else
capture
=
cvCreateFileCapture
(
vdofile
.
c_str
());
...
...
@@ -144,14 +145,12 @@ int main(int argc, const char* argv[])
int
c
=
inputName
;
if
(
!
capture
)
{
if
(
vdofile
==
""
)
if
(
vdofile
.
empty
()
)
cout
<<
"Capture from CAM "
<<
c
<<
" didn't work"
<<
endl
;
else
cout
<<
"Capture from file "
<<
vdofile
<<
" failed"
<<
endl
;
if
(
defaultPicturesFail
)
{
return
-
1
;
}
return
EXIT_FAILURE
;
goto
nocamera
;
}
...
...
@@ -212,12 +211,9 @@ int main(int argc, const char* argv[])
}
if
(
waitKey
(
10
)
>=
0
)
goto
_cleanup_
;
break
;
}
waitKey
(
0
);
_cleanup_:
cvReleaseCapture
(
&
capture
);
}
else
...
...
@@ -264,5 +260,5 @@ nocamera:
waitKey
();
return
0
;
return
EXIT_SUCCESS
;
}
samples/ocl/squares.cpp
View file @
4d86e214
...
...
@@ -13,9 +13,9 @@
using
namespace
cv
;
using
namespace
std
;
#define ACCURACY_CHECK
1
#define ACCURACY_CHECK
#if ACCURACY_CHECK
#if
def
ACCURACY_CHECK
// check if two vectors of vector of points are near or not
// prior assumption is that they are in correct order
static
bool
checkPoints
(
...
...
@@ -278,27 +278,31 @@ int main(int argc, char** argv)
{
const
char
*
keys
=
"{ i | input | | specify input image }"
"{ o | output | squares_output.jpg | specify output save path}"
;
"{ o | output | squares_output.jpg | specify output save path}"
"{ h | help | false | print help message }"
;
CommandLineParser
cmd
(
argc
,
argv
,
keys
);
string
inputName
=
cmd
.
get
<
string
>
(
"i"
);
string
outfile
=
cmd
.
get
<
string
>
(
"o"
);
if
(
inputName
.
empty
())
if
(
cmd
.
get
<
bool
>
(
"help"
))
{
cout
<<
"Usage : squares [options]"
<<
endl
;
cout
<<
"Available options:"
<<
endl
;
cmd
.
printParams
();
return
0
;
return
EXIT_SUCCESS
;
}
int
iterations
=
10
;
namedWindow
(
wndname
,
1
);
namedWindow
(
wndname
,
CV_LOAD_IMAGE_COLOR
);
vector
<
vector
<
Point
>
>
squares_cpu
,
squares_ocl
;
Mat
image
=
imread
(
inputName
,
1
);
if
(
image
.
empty
()
)
{
cout
<<
"Couldn't load "
<<
inputName
<<
endl
;
return
-
1
;
return
EXIT_FAILURE
;
}
int
j
=
iterations
;
int64
t_ocl
=
0
,
t_cpp
=
0
;
//warm-ups
...
...
@@ -307,7 +311,7 @@ int main(int argc, char** argv)
findSquares_ocl
(
image
,
squares_ocl
);
#if ACCURACY_CHECK
#if
def
ACCURACY_CHECK
cout
<<
"Checking ocl accuracy ... "
<<
endl
;
cout
<<
(
checkPoints
(
squares_cpu
,
squares_ocl
)
?
"Pass"
:
"Failed"
)
<<
endl
;
#endif
...
...
@@ -332,5 +336,5 @@ int main(int argc, char** argv)
imwrite
(
outfile
,
result
);
cvWaitKey
(
0
);
return
0
;
return
EXIT_SUCCESS
;
}
samples/ocl/stereo_match.cpp
View file @
4d86e214
...
...
@@ -78,6 +78,7 @@ int main(int argc, char** argv)
"{ m | method | BM | specify match method(BM/BP/CSBP) }"
"{ n | ndisp | 64 | specify number of disparity levels }"
"{ o | output | stereo_match_output.jpg | specify output path when input is images}"
;
CommandLineParser
cmd
(
argc
,
argv
,
keys
);
if
(
cmd
.
get
<
bool
>
(
"help"
))
{
...
...
@@ -85,6 +86,7 @@ int main(int argc, char** argv)
cmd
.
printParams
();
return
0
;
}
try
{
App
app
(
cmd
);
...
...
@@ -96,7 +98,8 @@ int main(int argc, char** argv)
{
cout
<<
"error: "
<<
e
.
what
()
<<
endl
;
}
return
0
;
return
EXIT_SUCCESS
;
}
App
::
App
(
CommandLineParser
&
cmd
)
...
...
@@ -114,6 +117,7 @@ App::App(CommandLineParser& cmd)
<<
"
\t
2/w - increase/decrease window size (for BM only)
\n
"
<<
"
\t
3/e - increase/decrease iteration count (for BP and CSBP only)
\n
"
<<
"
\t
4/r - increase/decrease level count (for BP and CSBP only)
\n
"
;
l_img
=
cmd
.
get
<
string
>
(
"l"
);
r_img
=
cmd
.
get
<
string
>
(
"r"
);
string
mstr
=
cmd
.
get
<
string
>
(
"m"
);
...
...
samples/ocl/surf_matcher.cpp
View file @
4d86e214
...
...
@@ -14,21 +14,20 @@ const int LOOP_NUM = 10;
const
int
GOOD_PTS_MAX
=
50
;
const
float
GOOD_PORTION
=
0.15
f
;
namespace
{
int64
work_begin
=
0
;
int64
work_end
=
0
;
void
workBegin
()
static
void
workBegin
()
{
work_begin
=
getTickCount
();
}
void
workEnd
()
static
void
workEnd
()
{
work_end
=
getTickCount
()
-
work_begin
;
}
double
getTime
()
static
double
getTime
()
{
return
work_end
/
((
double
)
cvGetTickFrequency
()
*
1000.
);
}
...
...
@@ -59,7 +58,7 @@ struct SURFMatcher
}
};
Mat
drawGoodMatches
(
static
Mat
drawGoodMatches
(
const
Mat
&
cpu_img1
,
const
Mat
&
cpu_img2
,
const
vector
<
KeyPoint
>&
keypoints1
,
...
...
@@ -129,7 +128,6 @@ Mat drawGoodMatches(
return
img_matches
;
}
}
////////////////////////////////////////////////////
// This program demonstrates the usage of SURF_OCL.
// use cpu findHomography interface to calculate the transformation matrix
...
...
@@ -142,12 +140,14 @@ int main(int argc, char* argv[])
"{ o | output | SURF_output.jpg | specify output save path (only works in CPU or GPU only mode) }"
"{ c | use_cpu | false | use CPU algorithms }"
"{ a | use_all | false | use both CPU and GPU algorithms}"
;
CommandLineParser
cmd
(
argc
,
argv
,
keys
);
if
(
cmd
.
get
<
bool
>
(
"help"
))
{
std
::
cout
<<
"Usage: surf_matcher [options]"
<<
std
::
endl
;
std
::
cout
<<
"Available options:"
<<
std
::
endl
;
cmd
.
printParams
();
return
0
;
return
EXIT_SUCCESS
;
}
Mat
cpu_img1
,
cpu_img2
,
cpu_img1_grey
,
cpu_img2_grey
;
...
...
@@ -168,23 +168,17 @@ int main(int argc, char* argv[])
cvtColor
(
cpu_img2
,
cpu_img2_grey
,
CV_BGR2GRAY
);
img2
=
cpu_img2_grey
;
if
(
useALL
)
{
useCPU
=
false
;
useGPU
=
false
;
}
else
if
(
useCPU
==
false
&&
useALL
==
false
)
{
if
(
useALL
)
useCPU
=
useGPU
=
false
;
else
if
(
!
useCPU
&&
!
useALL
)
useGPU
=
true
;
}
if
(
!
useCPU
)
{
std
::
cout
<<
"Device name:"
<<
cv
::
ocl
::
Context
::
getContext
()
->
getDeviceInfo
().
deviceName
<<
std
::
endl
;
}
double
surf_time
=
0.
;
//declare input/output
...
...
@@ -330,5 +324,5 @@ int main(int argc, char* argv[])
imshow
(
"ocl surf matches"
,
ocl_img_matches
);
}
waitKey
(
0
);
return
0
;
return
EXIT_SUCCESS
;
}
samples/ocl/tvl1_optical_flow.cpp
View file @
4d86e214
...
...
@@ -96,10 +96,9 @@ int main(int argc, const char* argv[])
cout
<<
"Usage: pyrlk_optical_flow [options]"
<<
endl
;
cout
<<
"Available options:"
<<
endl
;
cmd
.
printParams
();
return
0
;
return
EXIT_SUCCESS
;
}
bool
defaultPicturesFail
=
false
;
string
fname0
=
cmd
.
get
<
string
>
(
"l"
);
string
fname1
=
cmd
.
get
<
string
>
(
"r"
);
string
vdofile
=
cmd
.
get
<
string
>
(
"v"
);
...
...
@@ -113,22 +112,10 @@ int main(int argc, const char* argv[])
cv
::
Ptr
<
cv
::
DenseOpticalFlow
>
alg
=
cv
::
createOptFlow_DualTVL1
();
cv
::
ocl
::
OpticalFlowDual_TVL1_OCL
d_alg
;
Mat
flow
,
show_flow
;
Mat
flow_vec
[
2
];
if
(
frame0
.
empty
()
||
frame1
.
empty
())
{
useCamera
=
true
;
defaultPicturesFail
=
true
;
CvCapture
*
capture
=
0
;
capture
=
cvCaptureFromCAM
(
inputName
);
if
(
!
capture
)
{
cout
<<
"Can't load input images"
<<
endl
;
return
-
1
;
}
}
if
(
useCamera
)
{
...
...
@@ -137,22 +124,17 @@ int main(int argc, const char* argv[])
Mat
frame0Gray
,
frame1Gray
;
Mat
ptr0
,
ptr1
;
if
(
vdofile
==
""
)
if
(
vdofile
.
empty
()
)
capture
=
cvCaptureFromCAM
(
inputName
);
else
capture
=
cvCreateFileCapture
(
vdofile
.
c_str
());
int
c
=
inputName
;
if
(
!
capture
)
{
if
(
vdofile
==
""
)
cout
<<
"Capture from CAM "
<<
c
<<
" didn't work"
<<
endl
;
if
(
vdofile
.
empty
()
)
cout
<<
"Capture from CAM "
<<
inputName
<<
" didn't work"
<<
endl
;
else
cout
<<
"Capture from file "
<<
vdofile
<<
" failed"
<<
endl
;
if
(
defaultPicturesFail
)
{
return
-
1
;
}
goto
nocamera
;
}
...
...
@@ -206,12 +188,9 @@ int main(int argc, const char* argv[])
}
if
(
waitKey
(
10
)
>=
0
)
goto
_cleanup_
;
break
;
}
waitKey
(
0
);
_cleanup_
:
cvReleaseCapture
(
&
capture
);
}
else
...
...
@@ -254,5 +233,5 @@ nocamera:
waitKey
();
return
0
;
return
EXIT_SUCCESS
;
}
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