Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
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_contrib
Commits
3a43af81
Commit
3a43af81
authored
Mar 27, 2017
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1080 from pengli:dis_optflow
parents
d8be3fe9
6f907c33
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
74 additions
and
0 deletions
+74
-0
dis_opticalflow.cpp
modules/optflow/samples/dis_opticalflow.cpp
+74
-0
No files found.
modules/optflow/samples/dis_opticalflow.cpp
0 → 100644
View file @
3a43af81
#include "opencv2/core/utility.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/optflow.hpp"
using
namespace
std
;
using
namespace
cv
;
using
namespace
optflow
;
static
void
help
()
{
printf
(
"Usage: dis_optflow <video_file>
\n
"
);
}
int
main
(
int
argc
,
char
**
argv
)
{
VideoCapture
cap
;
if
(
argc
<
2
)
{
help
();
exit
(
1
);
}
cap
.
open
(
argv
[
1
]);
if
(
!
cap
.
isOpened
())
{
printf
(
"ERROR: Cannot open file %s
\n
"
,
argv
[
1
]);
return
-
1
;
}
Mat
prevgray
,
gray
,
rgb
,
frame
;
Mat
flow
,
flow_uv
[
2
];
Mat
mag
,
ang
;
Mat
hsv_split
[
3
],
hsv
;
char
ret
;
namedWindow
(
"flow"
,
1
);
namedWindow
(
"orig"
,
1
);
Ptr
<
DenseOpticalFlow
>
algorithm
=
createOptFlow_DIS
(
DISOpticalFlow
::
PRESET_MEDIUM
);
while
(
true
)
{
cap
>>
frame
;
if
(
frame
.
empty
())
break
;
cvtColor
(
frame
,
gray
,
COLOR_BGR2GRAY
);
if
(
!
prevgray
.
empty
())
{
algorithm
->
calc
(
prevgray
,
gray
,
flow
);
split
(
flow
,
flow_uv
);
multiply
(
flow_uv
[
1
],
-
1
,
flow_uv
[
1
]);
cartToPolar
(
flow_uv
[
0
],
flow_uv
[
1
],
mag
,
ang
,
true
);
normalize
(
mag
,
mag
,
0
,
1
,
NORM_MINMAX
);
hsv_split
[
0
]
=
ang
;
hsv_split
[
1
]
=
mag
;
hsv_split
[
2
]
=
Mat
::
ones
(
ang
.
size
(),
ang
.
type
());
merge
(
hsv_split
,
3
,
hsv
);
cvtColor
(
hsv
,
rgb
,
COLOR_HSV2BGR
);
imshow
(
"flow"
,
rgb
);
imshow
(
"orig"
,
frame
);
}
if
((
ret
=
(
char
)
waitKey
(
20
))
>
0
)
break
;
std
::
swap
(
prevgray
,
gray
);
}
return
0
;
}
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