Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make -j, error #14

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
89f5c80
refactoring extraction
Nov 18, 2015
00d13d0
change log format
Nov 18, 2015
fdf1bb2
change project structure
Nov 18, 2015
d721d8c
save previous frame
Nov 18, 2015
7009a84
add gpu video reader
Nov 18, 2015
071809f
add gpu video reader
Nov 18, 2015
c708f9e
add gpu video reader
Nov 18, 2015
d4adcb0
add gpu video reader
Nov 18, 2015
721647d
try prefetch frames
Nov 18, 2015
ceb9350
add image writeout
Nov 18, 2015
6453450
update usage info
Nov 18, 2015
d0df2e5
update usage info
Nov 18, 2015
de4bc61
now support zip file output
Nov 18, 2015
791e37e
remove zip truncate to fix linux libzip
Nov 18, 2015
31784e5
fix old version libzip
Nov 18, 2015
c74cc2c
Update and rename README to README.md
yjxiong Nov 18, 2015
1822a88
Update README.md
yjxiong Nov 18, 2015
27d3d66
Update README.md
yjxiong Nov 20, 2015
d99a214
Update README.md
yjxiong Dec 17, 2015
794b003
fix flow extraction bug
Dec 17, 2015
c1fd330
Merge branch 'master' of https://github.com/yjxiong/dense_flow
Dec 17, 2015
891f5b1
add anet_builder
Dec 24, 2015
99bc834
add experimental python wrapper
Apr 3, 2016
aa967af
remove debug print
Apr 3, 2016
0563a3f
improve python wrapper
Apr 4, 2016
a128881
init warp flow extraction
Apr 27, 2016
f64d0d0
add tool to extract warp
Apr 28, 2016
8306a66
Merge remote-tracking branch 'origin/py_denseflow'
Apr 28, 2016
6dd37bc
updates
Apr 28, 2016
0694913
add python scripts
May 1, 2016
8645027
fix linking problem of warp flow
May 25, 2016
a282d61
fix warp py interface
May 25, 2016
a5db11b
Update README.md
yjxiong Aug 1, 2016
60ac8c3
add resize before flow extraction
Aug 1, 2016
93918c0
fix resize command tool
Aug 10, 2016
98e511f
Update README.md
yjxiong Aug 11, 2016
0df27a2
Update README.md
yjxiong Oct 11, 2016
41b0c7b
Fix CPU Flow Image Encoding
yjxiong Jan 4, 2017
997977f
Update README.md
yjxiong May 17, 2017
c9369a3
Create LICENSE
yjxiong Jul 30, 2017
a0b3ad9
supports Opencv 4.1.0 (#4)
zhaoyue-zephyrus Jun 27, 2019
4490b4e
Fix typo & formatting (#6)
innerlee Aug 19, 2019
49f0701
Update README.md
yjxiong May 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.o
.idea/
build/
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "include/easylogging++"]
path = include/easylogging++
url = https://github.com/easylogging/easyloggingpp
[submodule "include/CLUE"]
path = include/CLUE
url = https://github.com/lindahua/CLUE
49 changes: 46 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,49 @@
cmake_minimum_required(VERSION 2.8)
project( denseFlow )

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()


find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( denseFlow_gpu denseFlow_gpu.cpp )
target_link_libraries( denseFlow_gpu ${OpenCV_LIBS} )
find_package( LibZip REQUIRED )

# BOOST
FIND_PACKAGE(Boost REQUIRED python)
FIND_PACKAGE(PythonLibs REQUIRED)

if(LIBZIP_VERSION VERSION_LESS 0.11)
#old version LibZip
add_definitions(-DUSE_OBSEL_LIBZIP)
endif()

include_directories( ${OpenCV_INCLUDE_DIRS} ${LIBZIP_INCLUDE_DIR_ZIP} ${LIBZIP_INCLUDE_DIR_ZIPCONF} include/ include/easylogging++/src include/CLUE/include)
include_directories(SYSTEM ${Boost_INCLUDE_DIR} ${PYTHON_INCLUDE_DIR})

add_library(denseflow src/common.cpp src/dense_flow.cpp src/dense_flow_gpu.cpp src/dense_warp_flow_gpu.cpp src/zip_utils.cpp)
target_link_libraries( denseflow ${OpenCV_LIBS} ${LIBZIP_LIBRARY})

add_library(pydenseflow SHARED src/py_denseflow.cpp)
target_link_libraries(pydenseflow
denseflow
${Boost_LIBRARIES} ${PYTHON_LIBRARIES} ${OpenCV_LIBS}
)

add_executable( extract_cpu tools/extract_flow.cpp)
target_link_libraries( extract_cpu ${OpenCV_LIBS} ${LIBZIP_LIBRARY} denseflow)

add_executable( extract_gpu tools/extract_flow_gpu.cpp)
target_link_libraries( extract_gpu ${OpenCV_LIBS} ${LIBZIP_LIBRARY} denseflow)

add_executable( extract_warp_gpu tools/extract_warp_flow_gpu.cpp)
target_link_libraries( extract_warp_gpu ${OpenCV_LIBS} ${LIBZIP_LIBRARY} denseflow)
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2016 Multimedia Laboratory, The Chinese University of Hong Kong.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 0 additions & 6 deletions README

This file was deleted.

50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
**Please Note**: This repository is no longer maintained. For extracting optical flow from videos please use [this latest tool](https://github.com/open-mmlab/denseflow) from Open-MMLAB.
----


Extracting dense flow field given a video.

#### Dependencies:
- LibZip:
to install on ubuntu ```apt-get install libzip-dev``` on mac ```brew install libzip```

#### For OpenCV 3 Users
Please see the [opencv-3.1](https://github.com/yjxiong/dense_flow/tree/opencv-3.1) branch. Many thanks to @victorhcm for the contributions!

### Install
```
git clone --recursive http://github.com/yjxiong/dense_flow
mkdir build && cd build
cmake .. && make -j
```

### Usage
```
./extract_gpu -f=test.avi -x=tmp/flow_x -y=tmp/flow_y -i=tmp/image -b=20 -t=1 -d=0 -s=1 -o=dir
```
- `test.avi`: input video
- `tmp`: folder containing RGB images and optical flow images
- `dir`: output generated images to folder. if set to `zip`, will write images to zip files instead.

### Warp Flow
The warp optical flow is used in the following paper

```
@inproceedings{TSN2016ECCV,
author = {Limin Wang and
Yuanjun Xiong and
Zhe Wang and
Yu Qiao and
Dahua Lin and
Xiaoou Tang and
Luc {Van Gool}},
title = {Temporal Segment Networks: Towards Good Practices for Deep Action Recognition},
booktitle = {ECCV},
year = {2016},
}
```

To extract warp flow, use the command
```
./extract_warp_gpu -f test.avi -x tmp/flow_x -y tmp/flow_y -i tmp/image -b 20 -t 1 -d 0 -s 1 -o dir
```
97 changes: 97 additions & 0 deletions build_of.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
__author__ = 'yjxiong'

import cv2
import os
from multiprocessing import Pool, current_process

import argparse
out_path = ''


def dump_frames(vid_path):
video = cv2.VideoCapture(vid_path)
vid_name = vid_path.split('/')[-1].split('.')[0]
out_full_path = os.path.join(out_path, vid_name)

fcount = int(video.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT))
try:
os.mkdir(out_full_path)
except OSError:
pass
file_list = []
for i in xrange(fcount):
ret, frame = video.read()
assert ret
cv2.imwrite('{}/{:06d}.jpg'.format(out_full_path, i), frame)
access_path = '{}/{:06d}.jpg'.format(vid_name, i)
file_list.append(access_path)
print '{} done'.format(vid_name)
return file_list


def run_optical_flow(vid_item, dev_id=0):
vid_path = vid_item[0]
vid_id = vid_item[1]
vid_name = vid_path.split('/')[-1].split('.')[0]
out_full_path = os.path.join(out_path, vid_name)
try:
os.mkdir(out_full_path)
except OSError:
pass

current = current_process()
dev_id = int(current._identity[0]) - 1
image_path = '{}/img'.format(out_full_path)
flow_x_path = '{}/flow_x'.format(out_full_path)
flow_y_path = '{}/flow_y'.format(out_full_path)

cmd = './build/extract_gpu -f={} -x={} -y={} -i={} -b=20 -t=1 -d={} -s=1 -o=zip'.format(vid_path, flow_x_path, flow_y_path, image_path, dev_id)

os.system(cmd)
print '{} {} done'.format(vid_id, vid_name)
return True

def run_warp_optical_flow(vid_item, dev_id=0):
vid_path = vid_item[0]
vid_id = vid_item[1]
vid_name = vid_path.split('/')[-1].split('.')[0]
out_full_path = os.path.join(out_path, vid_name)
try:
os.mkdir(out_full_path)
except OSError:
pass

current = current_process()
dev_id = int(current._identity[0]) - 1
flow_x_path = '{}/flow_x'.format(out_full_path)
flow_y_path = '{}/flow_y'.format(out_full_path)

cmd = './build/extract_warp_gpu -f {} -x {} -y {} -b 20 -t 1 -d {} -s 1 -o zip'.format(vid_path, flow_x_path, flow_y_path, dev_id)

os.system(cmd)
print 'warp on {} {} done'.format(vid_id, vid_name)
return True


if __name__ == '__main__':
parser = argparse.ArgumentParser(description="extract optical flows")
parser.add_argument("src_dir")
parser.add_argument("out_dir")
parser.add_argument("--num_worker", type=int, default=8)
parser.add_argument("--flow_type", type=str, default='tvl1', choices=['tvl1', 'warp_tvl1'])

args = parser.parse_args()

out_path = args.out_dir
src_path = args.src_dir
num_worker = args.num_worker
flow_type = args.flow_type


vid_list = glob.glob(src_path+'/*.mp4')
print len(vid_list)
pool = Pool(num_worker)
if flow_type == 'tvl1':
pool.map(run_optical_flow, zip(vid_list, xrange(len(vid_list))))
elif flow_type == 'warp_tvl1':
pool.map(run_warp_optical_flow, zip(vid_list, xrange(len(vid_list))))
37 changes: 37 additions & 0 deletions cmake/Modules/FindLibZip.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Finds libzip.
#
# This module defines:
# LIBZIP_INCLUDE_DIR_ZIP
# LIBZIP_INCLUDE_DIR_ZIPCONF
# LIBZIP_LIBRARY
#

find_package(PkgConfig)
pkg_check_modules(PC_LIBZIP QUIET libzip)

find_path(LIBZIP_INCLUDE_DIR_ZIP
NAMES zip.h
HINTS ${PC_LIBZIP_INCLUDE_DIRS})

find_path(LIBZIP_INCLUDE_DIR_ZIPCONF
NAMES zipconf.h
HINTS ${PC_LIBZIP_INCLUDE_DIRS})

find_library(LIBZIP_LIBRARY
NAMES zip)

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
LIBZIP DEFAULT_MSG
LIBZIP_LIBRARY LIBZIP_INCLUDE_DIR_ZIP LIBZIP_INCLUDE_DIR_ZIPCONF)

set(LIBZIP_VERSION 0)

if (LIBZIP_INCLUDE_DIR_ZIPCONF)
FILE(READ "${LIBZIP_INCLUDE_DIR_ZIPCONF}/zipconf.h" _LIBZIP_VERSION_CONTENTS)
if (_LIBZIP_VERSION_CONTENTS)
STRING(REGEX REPLACE ".*#define LIBZIP_VERSION \"([0-9.]+)\".*" "\\1" LIBZIP_VERSION "${_LIBZIP_VERSION_CONTENTS}")
endif ()
endif ()

set(LIBZIP_VERSION ${LIBZIP_VERSION} CACHE STRING "Version number of libzip")
107 changes: 0 additions & 107 deletions denseFlow.cpp

This file was deleted.

Loading