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
6bb9342a
Commit
6bb9342a
authored
May 30, 2013
by
Vadim Pisarevsky
Committed by
OpenCV Buildbot
May 30, 2013
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #918 from bitwangyaoyao:2.4_samples
parents
5a4efe8b
fad96b95
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
352 additions
and
2 deletions
+352
-2
aloe-L.png
samples/ocl/aloe-L.png
+0
-0
aloe-R.png
samples/ocl/aloe-R.png
+0
-0
aloe-disp.png
samples/ocl/aloe-disp.png
+0
-0
facedetect.cpp
samples/ocl/facedetect.cpp
+0
-0
hog.cpp
samples/ocl/hog.cpp
+62
-2
pyrlk_optical_flow.cpp
samples/ocl/pyrlk_optical_flow.cpp
+290
-0
stereo_match.cpp
samples/ocl/stereo_match.cpp
+0
-0
No files found.
samples/ocl/aloe-L.png
deleted
100644 → 0
View file @
5a4efe8b
720 KB
samples/ocl/aloe-R.png
deleted
100644 → 0
View file @
5a4efe8b
722 KB
samples/ocl/aloe-disp.png
deleted
100644 → 0
View file @
5a4efe8b
59 KB
samples/ocl/facedetect.cpp
View file @
6bb9342a
This diff is collapsed.
Click to expand it.
samples/ocl/hog.cpp
View file @
6bb9342a
...
...
@@ -45,7 +45,6 @@ public:
bool
gamma_corr
;
};
class
App
{
public
:
...
...
@@ -64,6 +63,13 @@ public:
string
message
()
const
;
// This function test if gpu_rst matches cpu_rst.
// If the two vectors are not equal, it will return the difference in vector size
// Else if will return
// (total diff of each cpu and gpu rects covered pixels)/(total cpu rects covered pixels)
double
checkRectSimilarity
(
Size
sz
,
std
::
vector
<
Rect
>&
cpu_rst
,
std
::
vector
<
Rect
>&
gpu_rst
);
private
:
App
operator
=
(
App
&
);
...
...
@@ -290,6 +296,7 @@ void App::run()
ocl
::
oclMat
gpu_img
;
// Iterate over all frames
bool
verify
=
false
;
while
(
running
&&
!
frame
.
empty
())
{
workBegin
();
...
...
@@ -316,7 +323,18 @@ void App::run()
gpu_img
.
upload
(
img
);
gpu_hog
.
detectMultiScale
(
gpu_img
,
found
,
hit_threshold
,
win_stride
,
Size
(
0
,
0
),
scale
,
gr_threshold
);
}
if
(
!
verify
)
{
// verify if GPU output same objects with CPU at 1st run
verify
=
true
;
vector
<
Rect
>
ref_rst
;
cvtColor
(
img
,
img
,
CV_BGRA2BGR
);
cpu_hog
.
detectMultiScale
(
img
,
ref_rst
,
hit_threshold
,
win_stride
,
Size
(
0
,
0
),
scale
,
gr_threshold
-
2
);
double
accuracy
=
checkRectSimilarity
(
img
.
size
(),
ref_rst
,
found
);
cout
<<
"
\n
accuracy value: "
<<
accuracy
<<
endl
;
}
}
else
cpu_hog
.
detectMultiScale
(
img
,
found
,
hit_threshold
,
win_stride
,
Size
(
0
,
0
),
scale
,
gr_threshold
);
hogWorkEnd
();
...
...
@@ -457,3 +475,45 @@ inline string App::workFps() const
return
ss
.
str
();
}
double
App
::
checkRectSimilarity
(
Size
sz
,
std
::
vector
<
Rect
>&
ob1
,
std
::
vector
<
Rect
>&
ob2
)
{
double
final_test_result
=
0.0
;
size_t
sz1
=
ob1
.
size
();
size_t
sz2
=
ob2
.
size
();
if
(
sz1
!=
sz2
)
return
sz1
>
sz2
?
(
double
)(
sz1
-
sz2
)
:
(
double
)(
sz2
-
sz1
);
else
{
cv
::
Mat
cpu_result
(
sz
,
CV_8UC1
);
cpu_result
.
setTo
(
0
);
for
(
vector
<
Rect
>::
const_iterator
r
=
ob1
.
begin
();
r
!=
ob1
.
end
();
r
++
)
{
cv
::
Mat
cpu_result_roi
(
cpu_result
,
*
r
);
cpu_result_roi
.
setTo
(
1
);
cpu_result
.
copyTo
(
cpu_result
);
}
int
cpu_area
=
cv
::
countNonZero
(
cpu_result
>
0
);
cv
::
Mat
gpu_result
(
sz
,
CV_8UC1
);
gpu_result
.
setTo
(
0
);
for
(
vector
<
Rect
>::
const_iterator
r2
=
ob2
.
begin
();
r2
!=
ob2
.
end
();
r2
++
)
{
cv
::
Mat
gpu_result_roi
(
gpu_result
,
*
r2
);
gpu_result_roi
.
setTo
(
1
);
gpu_result
.
copyTo
(
gpu_result
);
}
cv
::
Mat
result_
;
multiply
(
cpu_result
,
gpu_result
,
result_
);
int
result
=
cv
::
countNonZero
(
result_
>
0
);
final_test_result
=
1.0
-
(
double
)
result
/
(
double
)
cpu_area
;
}
return
final_test_result
;
}
samples/ocl/pyrlk_optical_flow.cpp
0 → 100644
View file @
6bb9342a
#include <iostream>
#include <vector>
#include <iomanip>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/ocl/ocl.hpp"
#include "opencv2/video/video.hpp"
using
namespace
std
;
using
namespace
cv
;
using
namespace
cv
::
ocl
;
typedef
unsigned
char
uchar
;
#define LOOP_NUM 10
int64
work_begin
=
0
;
int64
work_end
=
0
;
static
void
workBegin
()
{
work_begin
=
getTickCount
();
}
static
void
workEnd
()
{
work_end
+=
(
getTickCount
()
-
work_begin
);
}
static
double
getTime
(){
return
work_end
*
1000.
/
getTickFrequency
();
}
static
void
download
(
const
oclMat
&
d_mat
,
vector
<
Point2f
>&
vec
)
{
vec
.
resize
(
d_mat
.
cols
);
Mat
mat
(
1
,
d_mat
.
cols
,
CV_32FC2
,
(
void
*
)
&
vec
[
0
]);
d_mat
.
download
(
mat
);
}
static
void
download
(
const
oclMat
&
d_mat
,
vector
<
uchar
>&
vec
)
{
vec
.
resize
(
d_mat
.
cols
);
Mat
mat
(
1
,
d_mat
.
cols
,
CV_8UC1
,
(
void
*
)
&
vec
[
0
]);
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
))
{
for
(
size_t
i
=
0
;
i
<
prevPts
.
size
();
++
i
)
{
if
(
status
[
i
])
{
int
line_thickness
=
1
;
Point
p
=
prevPts
[
i
];
Point
q
=
nextPts
[
i
];
double
angle
=
atan2
((
double
)
p
.
y
-
q
.
y
,
(
double
)
p
.
x
-
q
.
x
);
double
hypotenuse
=
sqrt
(
(
double
)(
p
.
y
-
q
.
y
)
*
(
p
.
y
-
q
.
y
)
+
(
double
)(
p
.
x
-
q
.
x
)
*
(
p
.
x
-
q
.
x
)
);
if
(
hypotenuse
<
1.0
)
continue
;
// Here we lengthen the arrow by a factor of three.
q
.
x
=
(
int
)
(
p
.
x
-
3
*
hypotenuse
*
cos
(
angle
));
q
.
y
=
(
int
)
(
p
.
y
-
3
*
hypotenuse
*
sin
(
angle
));
// Now we draw the main line of the arrow.
line
(
frame
,
p
,
q
,
line_color
,
line_thickness
);
// Now draw the tips of the arrow. I do some scaling so that the
// tips look proportional to the main line of the arrow.
p
.
x
=
(
int
)
(
q
.
x
+
9
*
cos
(
angle
+
CV_PI
/
4
));
p
.
y
=
(
int
)
(
q
.
y
+
9
*
sin
(
angle
+
CV_PI
/
4
));
line
(
frame
,
p
,
q
,
line_color
,
line_thickness
);
p
.
x
=
(
int
)
(
q
.
x
+
9
*
cos
(
angle
-
CV_PI
/
4
));
p
.
y
=
(
int
)
(
q
.
y
+
9
*
sin
(
angle
-
CV_PI
/
4
));
line
(
frame
,
p
,
q
,
line_color
,
line_thickness
);
}
}
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
static
std
::
vector
<
Info
>
ocl_info
;
ocl
::
getDevice
(
ocl_info
);
//if you want to use undefault device, set it here
setDevice
(
ocl_info
[
0
]);
//set this to save kernel compile time from second time you run
ocl
::
setBinpath
(
"./"
);
const
char
*
keys
=
"{ h | help | false | print help message }"
"{ l | left | | specify left image }"
"{ r | right | | specify right image }"
"{ c | camera | 0 | enable camera capturing }"
"{ s | use_cpu | false | use cpu or gpu to process the image }"
"{ v | video | | use video as input }"
"{ points | points | 1000 | specify points count [GoodFeatureToTrack] }"
"{ min_dist | min_dist | 0 | specify minimal distance between points [GoodFeatureToTrack] }"
;
CommandLineParser
cmd
(
argc
,
argv
,
keys
);
if
(
cmd
.
get
<
bool
>
(
"help"
))
{
cout
<<
"Usage: pyrlk_optical_flow [options]"
<<
endl
;
cout
<<
"Avaible options:"
<<
endl
;
cmd
.
printParams
();
return
0
;
}
bool
defaultPicturesFail
=
false
;
string
fname0
=
cmd
.
get
<
string
>
(
"left"
);
string
fname1
=
cmd
.
get
<
string
>
(
"right"
);
string
vdofile
=
cmd
.
get
<
string
>
(
"video"
);
int
points
=
cmd
.
get
<
int
>
(
"points"
);
double
minDist
=
cmd
.
get
<
double
>
(
"min_dist"
);
bool
useCPU
=
cmd
.
get
<
bool
>
(
"s"
);
bool
useCamera
=
cmd
.
get
<
bool
>
(
"c"
);
int
inputName
=
cmd
.
get
<
int
>
(
"c"
);
oclMat
d_nextPts
,
d_status
;
Mat
frame0
=
imread
(
fname0
,
cv
::
IMREAD_GRAYSCALE
);
Mat
frame1
=
imread
(
fname1
,
cv
::
IMREAD_GRAYSCALE
);
PyrLKOpticalFlow
d_pyrLK
;
vector
<
cv
::
Point2f
>
pts
;
vector
<
cv
::
Point2f
>
nextPts
;
vector
<
unsigned
char
>
status
;
vector
<
float
>
err
;
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
;
}
}
cout
<<
"Points count : "
<<
points
<<
endl
<<
endl
;
if
(
useCamera
)
{
CvCapture
*
capture
=
0
;
Mat
frame
,
frameCopy
;
Mat
frame0Gray
,
frame1Gray
;
Mat
ptr0
,
ptr1
;
if
(
vdofile
==
""
)
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
;
else
cout
<<
"Capture from file "
<<
vdofile
<<
" failed"
<<
endl
;
if
(
defaultPicturesFail
)
{
return
-
1
;
}
goto
nocamera
;
}
cout
<<
"In capture ..."
<<
endl
;
for
(
int
i
=
0
;;
i
++
)
{
frame
=
cvQueryFrame
(
capture
);
if
(
frame
.
empty
()
)
break
;
if
(
i
==
0
)
{
frame
.
copyTo
(
frame0
);
cvtColor
(
frame0
,
frame0Gray
,
COLOR_BGR2GRAY
);
}
else
{
if
(
i
%
2
==
1
)
{
frame
.
copyTo
(
frame1
);
cvtColor
(
frame1
,
frame1Gray
,
COLOR_BGR2GRAY
);
ptr0
=
frame0Gray
;
ptr1
=
frame1Gray
;
}
else
{
frame
.
copyTo
(
frame0
);
cvtColor
(
frame0
,
frame0Gray
,
COLOR_BGR2GRAY
);
ptr0
=
frame1Gray
;
ptr1
=
frame0Gray
;
}
pts
.
clear
();
cv
::
goodFeaturesToTrack
(
ptr0
,
pts
,
points
,
0.01
,
0.0
);
if
(
pts
.
size
()
==
0
)
{
continue
;
}
if
(
useCPU
)
{
cv
::
calcOpticalFlowPyrLK
(
ptr0
,
ptr1
,
pts
,
nextPts
,
status
,
err
);
}
else
{
oclMat
d_prevPts
(
1
,
points
,
CV_32FC2
,
(
void
*
)
&
pts
[
0
]);
d_pyrLK
.
sparse
(
oclMat
(
ptr0
),
oclMat
(
ptr1
),
d_prevPts
,
d_nextPts
,
d_status
);
download
(
d_prevPts
,
pts
);
download
(
d_nextPts
,
nextPts
);
download
(
d_status
,
status
);
}
if
(
i
%
2
==
1
)
frame1
.
copyTo
(
frameCopy
);
else
frame0
.
copyTo
(
frameCopy
);
drawArrows
(
frameCopy
,
pts
,
nextPts
,
status
,
Scalar
(
255
,
0
,
0
));
imshow
(
"PyrLK [Sparse]"
,
frameCopy
);
}
if
(
waitKey
(
10
)
>=
0
)
goto
_cleanup_
;
}
waitKey
(
0
);
_cleanup_
:
cvReleaseCapture
(
&
capture
);
}
else
{
nocamera
:
for
(
int
i
=
0
;
i
<=
LOOP_NUM
;
i
++
)
{
cout
<<
"loop"
<<
i
<<
endl
;
if
(
i
>
0
)
workBegin
();
cv
::
goodFeaturesToTrack
(
frame0
,
pts
,
points
,
0.01
,
minDist
);
if
(
useCPU
)
{
cv
::
calcOpticalFlowPyrLK
(
frame0
,
frame1
,
pts
,
nextPts
,
status
,
err
);
}
else
{
oclMat
d_prevPts
(
1
,
points
,
CV_32FC2
,
(
void
*
)
&
pts
[
0
]);
d_pyrLK
.
sparse
(
oclMat
(
frame0
),
oclMat
(
frame1
),
d_prevPts
,
d_nextPts
,
d_status
);
download
(
d_prevPts
,
pts
);
download
(
d_nextPts
,
nextPts
);
download
(
d_status
,
status
);
}
if
(
i
>
0
&&
i
<=
LOOP_NUM
)
workEnd
();
if
(
i
==
LOOP_NUM
)
{
if
(
useCPU
)
cout
<<
"average CPU time (noCamera) : "
;
else
cout
<<
"average GPU time (noCamera) : "
;
cout
<<
getTime
()
/
LOOP_NUM
<<
" ms"
<<
endl
;
drawArrows
(
frame0
,
pts
,
nextPts
,
status
,
Scalar
(
255
,
0
,
0
));
imshow
(
"PyrLK [Sparse]"
,
frame0
);
}
}
}
waitKey
();
return
0
;
}
samples/ocl/stereo_match.cpp
0 → 100644
View file @
6bb9342a
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