Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
e0c65499
O
Opencv
项目概览
Greenplum
/
Opencv
大约 1 年 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e0c65499
编写于
3月 19, 2016
作者:
B
berak
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove opencv_contrib dependancy from planar_tracking.cpp
上级
fbc221d3
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
77 addition
and
45 deletion
+77
-45
doc/tutorials/features2d/akaze_tracking/akaze_tracking.markdown
...torials/features2d/akaze_tracking/akaze_tracking.markdown
+2
-2
samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp
...torial_code/features2D/AKAZE_tracking/planar_tracking.cpp
+20
-43
samples/cpp/tutorial_code/features2D/AKAZE_tracking/utils.h
samples/cpp/tutorial_code/features2D/AKAZE_tracking/utils.h
+55
-0
未找到文件。
doc/tutorials/features2d/akaze_tracking/akaze_tracking.markdown
浏览文件 @
e0c65499
...
...
@@ -28,9 +28,9 @@ To do the tracking we need a video and object position on the first frame.
You can download our example video and data from
[
here
](
https://docs.google.com/file/d/0B72G7D4snftJandBb0taLVJHMFk
)
.
To run the code you have to specify input
and output video path and object bounding box.
To run the code you have to specify input
(camera id or video_file). Then, select a bounding box with the mouse, and press any key to start tracking
@code{.none}
./planar_tracking blais.mp4
result.avi blais_bb.xml.gz
./planar_tracking blais.mp4
@endcode
Source Code
...
...
samples/cpp/tutorial_code/features2D/AKAZE_tracking/planar_tracking.cpp
浏览文件 @
e0c65499
#include <opencv2/features2d.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/tracking.hpp> //for ROI
#include <opencv2/highgui.hpp> //for imshow
#include <vector>
#include <iostream>
...
...
@@ -121,43 +120,29 @@ Mat Tracker::process(const Mat frame, Stats& stats)
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
<
3
)
{
if
(
argc
<
2
)
{
cerr
<<
"Usage: "
<<
endl
<<
"akaze_track input_path
output_path [bounding_box_path]
"
<<
endl
<<
" (
for camera input_path=N for camera N
)"
<<
endl
;
<<
"akaze_track input_path"
<<
endl
<<
" (
input_path can be a camera id, like 0,1,2 or a video filename
)"
<<
endl
;
return
1
;
}
std
::
string
video_name
=
argv
[
1
];
std
::
stringstream
ssFormat
;
ssFormat
<<
atoi
(
argv
[
1
]);
VideoCapture
video_in
;
int
iFourCC
=
0
,
frame_count
=
0
;
if
(
video_name
.
compare
(
ssFormat
.
str
())
==
0
)
{
//test str==str(num)
video_in
.
open
(
atoi
(
argv
[
1
]));
cerr
<<
"Capturing for 10 seconds from camera..."
<<
endl
;
iFourCC
=
CV_FOURCC
(
'D'
,
'I'
,
'V'
,
'X'
);
//default to mp4 (sample)
frame_count
=
10
*
static_cast
<
int
>
(
video_in
.
get
(
CAP_PROP_FPS
));
}
else
{
video_in
.
open
(
video_name
);
iFourCC
=
static_cast
<
int
>
(
video_in
.
get
(
CAP_PROP_FOURCC
));
frame_count
=
static_cast
<
int
>
(
video_in
.
get
(
CAP_PROP_FRAME_COUNT
));
}
VideoWriter
video_out
(
argv
[
2
],
iFourCC
,
(
int
)
video_in
.
get
(
CAP_PROP_FPS
),
Size
(
2
*
(
int
)
video_in
.
get
(
CAP_PROP_FRAME_WIDTH
),
2
*
(
int
)
video_in
.
get
(
CAP_PROP_FRAME_HEIGHT
)));
if
(
!
video_in
.
isOpened
())
{
cerr
<<
"Couldn't open "
<<
argv
[
1
]
<<
endl
;
return
1
;
}
if
(
!
video_out
.
isOpened
())
{
cerr
<<
"Couldn't open "
<<
argv
[
2
]
<<
endl
;
return
1
;
}
Stats
stats
,
akaze_stats
,
orb_stats
;
Ptr
<
AKAZE
>
akaze
=
AKAZE
::
create
();
...
...
@@ -169,33 +154,29 @@ int main(int argc, char **argv)
Mat
frame
;
video_in
>>
frame
;
namedWindow
(
video_name
,
WINDOW_NORMAL
);
cv
::
resizeWindow
(
video_name
,
frame
.
cols
,
frame
.
rows
);
cout
<<
"Please select a bounding box, and press any key to continue."
<<
endl
;
vector
<
Point2f
>
bb
;
if
(
argc
<
4
)
{
//attempt to alow GUI selection
cv
::
Rect2d
uBox
=
selectROI
(
video_name
,
frame
);
bb
.
push_back
(
cv
::
Point2f
(
static_cast
<
float
>
(
uBox
.
x
),
static_cast
<
float
>
(
uBox
.
y
)));
bb
.
push_back
(
cv
::
Point2f
(
static_cast
<
float
>
(
uBox
.
x
+
uBox
.
width
),
static_cast
<
float
>
(
uBox
.
y
)));
bb
.
push_back
(
cv
::
Point2f
(
static_cast
<
float
>
(
uBox
.
x
+
uBox
.
width
),
static_cast
<
float
>
(
uBox
.
y
+
uBox
.
height
)));
bb
.
push_back
(
cv
::
Point2f
(
static_cast
<
float
>
(
uBox
.
x
),
static_cast
<
float
>
(
uBox
.
y
+
uBox
.
height
)));
}
else
{
FileStorage
fs
(
argv
[
3
],
FileStorage
::
READ
);
if
(
fs
[
"bounding_box"
].
empty
())
{
cerr
<<
"Couldn't read bounding_box from "
<<
argv
[
3
]
<<
endl
;
return
1
;
}
fs
[
"bounding_box"
]
>>
bb
;
}
akaze_tracker
.
setFirstFrame
(
frame
,
bb
,
"AKAZE"
,
stats
);
orb_tracker
.
setFirstFrame
(
frame
,
bb
,
"ORB"
,
stats
);
Stats
akaze_draw_stats
,
orb_draw_stats
;
Mat
akaze_res
,
orb_res
,
res_frame
;
int
i
=
1
;
for
(
i
=
1
;
i
<
frame_count
;
i
++
)
{
int
i
=
0
;
for
(;;)
{
i
++
;
bool
update_stats
=
(
i
%
stats_update_period
==
0
);
video_in
>>
frame
;
// stop the program if no more images
if
(
frame
.
rows
==
0
||
frame
.
cols
==
0
)
break
;
if
(
frame
.
empty
()
)
break
;
akaze_res
=
akaze_tracker
.
process
(
frame
,
stats
);
akaze_stats
+=
stats
;
...
...
@@ -213,12 +194,8 @@ int main(int argc, char **argv)
drawStatistics
(
akaze_res
,
akaze_draw_stats
);
drawStatistics
(
orb_res
,
orb_draw_stats
);
vconcat
(
akaze_res
,
orb_res
,
res_frame
);
video_out
<<
res_frame
;
cv
::
imshow
(
video_name
,
res_frame
);
if
(
i
==
1
)
//resize for easier display
cv
::
resizeWindow
(
video_name
,
frame
.
cols
,
frame
.
rows
);
if
(
cv
::
waitKey
(
1
)
==
27
)
break
;
//quit on ESC button
cout
<<
i
<<
"/"
<<
frame_count
-
1
<<
endl
;
if
(
cv
::
waitKey
(
1
)
==
27
)
break
;
//quit on ESC button
}
akaze_stats
/=
i
-
1
;
orb_stats
/=
i
-
1
;
...
...
samples/cpp/tutorial_code/features2D/AKAZE_tracking/utils.h
浏览文件 @
e0c65499
...
...
@@ -12,6 +12,7 @@ void drawBoundingBox(Mat image, vector<Point2f> bb);
void
drawStatistics
(
Mat
image
,
const
Stats
&
stats
);
void
printStatistics
(
string
name
,
Stats
stats
);
vector
<
Point2f
>
Points
(
vector
<
KeyPoint
>
keypoints
);
Rect2d
selectROI
(
const
String
&
video_name
,
const
Mat
&
frame
);
void
drawBoundingBox
(
Mat
image
,
vector
<
Point2f
>
bb
)
{
...
...
@@ -56,4 +57,58 @@ vector<Point2f> Points(vector<KeyPoint> keypoints)
return
res
;
}
Rect2d
selectROI
(
const
String
&
video_name
,
const
Mat
&
frame
)
{
struct
Data
{
Point
center
;
Rect2d
box
;
static
void
mouseHandler
(
int
event
,
int
x
,
int
y
,
int
flags
,
void
*
param
)
{
Data
*
data
=
(
Data
*
)
param
;
switch
(
event
)
{
// start to select the bounding box
case
EVENT_LBUTTONDOWN
:
data
->
box
=
cvRect
(
x
,
y
,
0
,
0
);
data
->
center
=
Point2f
((
float
)
x
,(
float
)
y
);
break
;
// update the selected bounding box
case
EVENT_MOUSEMOVE
:
if
(
flags
==
1
)
{
data
->
box
.
width
=
2
*
(
x
-
data
->
center
.
x
);
data
->
box
.
height
=
2
*
(
y
-
data
->
center
.
y
);
data
->
box
.
x
=
data
->
center
.
x
-
data
->
box
.
width
/
2.0
;
data
->
box
.
y
=
data
->
center
.
y
-
data
->
box
.
height
/
2.0
;
}
break
;
// cleaning up the selected bounding box
case
EVENT_LBUTTONUP
:
if
(
data
->
box
.
width
<
0
)
{
data
->
box
.
x
+=
data
->
box
.
width
;
data
->
box
.
width
*=
-
1
;
}
if
(
data
->
box
.
height
<
0
)
{
data
->
box
.
y
+=
data
->
box
.
height
;
data
->
box
.
height
*=
-
1
;
}
break
;
}
}
}
data
;
setMouseCallback
(
video_name
,
Data
::
mouseHandler
,
&
data
);
while
(
waitKey
(
1
)
<
0
)
{
Mat
draw
=
frame
.
clone
();
rectangle
(
draw
,
data
.
box
,
Scalar
(
255
,
0
,
0
),
2
,
1
);
imshow
(
video_name
,
draw
);
}
return
data
.
box
;
}
#endif // UTILS_H
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录