Some resolutions cause segmentation faults in DISOpticalFlow()

asked 2017-05-16 23:11:16 -0500

philboske gravatar image

updated 2017-05-17 18:48:51 -0500

EDIT 1: Changed code snippet for complete reproducibility and added G++ compile also.


I'm having a weird problem with the Dense-Inverse-Search (DIS) optical flow implementation. Certain resolutions are causing a 'Segmentation fault (core dumped)' condition. The resolution of my video stream varies from 210 x 36 up to 750 x 144 between datasets. In example, if I run 720 x 144, no problems. 724 x 144, no problems. 725 x 144, Segmentation fault. However, larger resolutions, such as the 1024 x 436 used in the original DIS-flow paper, do not pose a problem. Is there some undocumented requirement for aspect ratio? Or minimum number of rows?

Any help would be greatly appreciated.

Original Git pull request for DIS-flow:

OpenCV API Class Reference for DISOpticalFlow():

Minimalist code to reproduce problem:

#include "opencv2/imgproc.hpp"
#include "opencv2/optflow.hpp"

int main()
    cv::Ptr<cv::optflow::DISOpticalFlow> dense_inverse_search = cv::optflow::createOptFlow_DIS(2);

    // This works.
    cv::Size image_size = cv::Size(724, 144);

    // This doesn't work.
    // cv::Size image_size = cv::Size(725, 144);

    const int MAXIMUM_ITERATIONS = 1001;

    for (int iteration = 0; iteration < MAXIMUM_ITERATIONS; iteration++)
        cv::Mat frame_0 = cv::Mat::zeros(image_size, CV_8UC1);
        cv::Mat frame_1 = cv::Mat::zeros(image_size, CV_8UC1);
        cv::Mat flow_frame = cv::Mat::zeros(image_size, CV_32FC2);

        dense_inverse_search->calc(frame_0, frame_1, flow_frame);

Compiled on Ubuntu MATE 16.04.1 (kernel 4.8.0-51-generic) using:

g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L/usr/local/lib/ -g -o run_dis_minimalist run_dis_minimalist.cpp -lopencv_core -lopencv_imgproc -lopencv_optflow

OpenCV build details (newest Git repository as of this time):

General configuration for OpenCV 3.2.0-dev =====================================
  Version control:               3.2.0-583-gfe4555e-dirty

  Extra modules:
    Location (extra):            /scratch/opencv_contrib/modules
    Version control (extra):     3.2.0-231-gdea8d5f

    Timestamp:                   2017-05-17T03:20:52Z
    Host:                        Linux 4.8.0-51-generic x86_64
    CMake:                       3.5.1
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3 SSSE3
      requested:                 SSSE3
    Dispatched code generation:  SSE4_1 FP16 AVX AVX2
      requested:                 SSE4_1 AVX FP16 AVX2
      SSE4_1 (0 files):          + SSE4_1
      FP16 (0 files):            + SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (1 files):             + SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (1 files):            + SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2

    Built as dynamic libs?:      YES
    C++ Compiler:                /usr/bin/c++  (ver 5.4.0)
    C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -mssse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -mssse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  /usr/bin/cc
    C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow ...
edit retag flag offensive close merge delete


A video of 725 x 144 are you sure that you can read this video using opencv without optflow?

Segmentation fault : What is exactly error message? Have you got stacktrace?

LBerger gravatar imageLBerger ( 2017-05-17 01:19:42 -0500 )edit

Yes, I'm sure that the video files are correct. My own OF algorithm, Lucas-Kanade, Farneback, DeepFlow and DenseFlow all have no problems. Custom file format, custom video stream, cast in this instance to CV_8UC1. I can run my data through DIS at 720x144 and it doesn't have a problem, but I require 750x144 (among other resolutions). No stack trace available at this stage, which is strange for OpenCV. If I had a stack trace I could possibly track down the problem in the source code and fix it myself.

philboske gravatar imagephilboske ( 2017-05-17 03:07:49 -0500 )edit

Using windows and msvc I changed source code to build an example. I can reproduce issue using example in opencv_contrib. How do you build your example ?

LBerger gravatar imageLBerger ( 2017-05-17 10:47:58 -0500 )edit

I have updated my question with entirely implementable code snippet and compilation details. This is based off of the TEST_PERF for the optflow modules, but is same principle as the opencv_contrib example you provided. It's worth noting that I'm passing cv::Mat::zero() images to the function, and it deals with this fine at certain resolutions producing a flow estimate of 0.

philboske gravatar imagephilboske ( 2017-05-17 18:51:36 -0500 )edit