1.背景
在(1)中已经完成了opencv_contrib的配置工作,接下来完成dense_flow的配置
2.配置dense_flow
按照网站操作进行:https://github.com/yjxiong/dense_flow/tree/opencv-3.1
(1) 添加依赖
终端执行: apt-get install libzip-dev
(2)因为已经克隆过了,直接进入dense_flow文件夹
需要注意的是:必须是克隆下的工程,不能是zip下载的,否则easylogging++会为空!!!
执行:mkdir build && cd build
执行:cmake .. && make -j8
报错1:
error: ‘DualTVL1OpticalFlow’ is not a member of ‘cv::optflow
这是dense_flow.cpp中的错误,因为dense_flow.cpp使用cpu提取光流,而我要的是gpu提取,因此该文件与我关系不大,因此我删除了src下的该文件,一并删除tools下的extract_flow.cpp文件,并注释掉CMakeLists.txt文件中的关于dense_flow.cpp的项:
#add_executable( extract_cpu tools/extract_flow.cpp)
#target_link_libraries( extract_cpu ${OpenCV_LIBS} ${LIBZIP_LIBRARY} denseflow)
如果确实需要,可以参考这里:https://github.com/open-mmlab/mmaction/issues/15
重新执行cmake .. && make -j8
成功!撒花......
3.测试
(1)在build目录下不要退出,在该文件夹下放一个视频文件test.mp4,然后执行:
./extract_gpu -f=test.mp4 -x=tmp/flow_x -y=tmp/flow_y -i=tmp/image -b=20 -t=1 -d=0 -s=1 -o=dir
报错:
2019-10-26 17:11:22,353 FATAL [default] CRASH HANDLED; Application has crashed due to [SIGSEGV] signal
2019-10-26 17:11:22,353 WARN [default] Aborting application. Reason: Fatal log at[/dense_flow_opencv3.1/dense_flow/include/easylogging++/src/easylogging++.h:5583]
已放弃 (核心已转储)
解决方案:在build文件夹下新建tmp文件夹,在tmp中新建flow_x;flow_y;image文件夹,重新执行,不在报错
可以在tmp文件加下看到提取出来的x,y方向的光流图,但是没有image文件
(2)按照官网执行提取warp的光流:
./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
会报错:
./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
OpenCV Error: Bad argument (can not convert: [true] to [int]) in from_str, file /opencv-3.1.0/modules/core/src/command_line_parser.cpp, line 98
OpenCV Error: Bad argument (can not convert: [true] to [int]) in from_str, file /opencv-3.1.0/modules/core/src/command_line_parser.cpp, line 98
OpenCV Error: Bad argument (can not convert: [true] to [int]) in from_str, file /opencv-3.1.0/modules/core/src/command_line_parser.cpp, line 98
OpenCV Error: Bad argument (can not convert: [true] to [int]) in from_str, file /opencv-3.1.0/modules/core/src/command_line_parser.cpp, line 98
2019-10-26 17:32:00,096 FATAL [default] Check failed: [video_stream.isOpened()] Cannot open video stream "true" for optical flow extraction.
2019-10-26 17:32:00,096 WARN [default] Aborting application. Reason: Fatal log at [/dense_flow_opencv3.1/dense_flow/src/dense_flow_gpu.cpp:19]
已放弃 (核心已转储)
仔细和上一条命令对比,发现后面的参数没有加=号,加上就不会报错了,即执行:
./extract_warp_gpu -f=test.mp4 -x=tmp/flow_x -y=tmp/flow_y -i=tmp/image -b=20 -t=1 -d=0 -s=1 -o=di
(3) 如果想要提取视频帧图像,可以参考build_of.py文件,并修改:
fcount = int(video.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT))
为:
fcount = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
否则会报错.
至此,所有需要的功能均已实现,剩下的就是慢慢提取光流了.............