segmentation fault (core dumped)

asked 2020-05-17 13:58:18 -0600

Nbb gravatar image

this code gives me a segmentation fault (core dumped). can anyone tell me why ?

 //************************************************************************
// compute_flow.cpp
// Computes OpenCV GPU Brox et al. [1] and Zach et al. [2] TVL1 Optical Flow
// Dependencies: OpenCV and Qt5 for iterating (sub)directories
// Author: Christoph Feichtenhofer
// Institution: Graz University of Technology
// Email: feichtenhofer@tugraz
// Date: Nov. 2015
// [1] T. Brox, A. Bruhn, N. Papenberg, J. Weickert. High accuracy optical flow estimation based on a theory for warping. ECCV 2004.
// [2] C. Zach, T. Pock, H. Bischof: A duality based approach for realtime TV-L 1 optical flow. DAGM 2007.
//************************************************************************

#define N_CHAR 500
#define WRITEOUT_IMGS 1

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <string>
#include <vector>
#include <math.h>
#include <iostream>
#include <fstream>
#include <sys/time.h>
#include <time.h>
#include <sstream>

#include <QDirIterator>
#include <QFileInfo>
#include <QString>

#include <opencv2/core/core.hpp>
#include "opencv2/video/tracking.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/cuda.hpp"
#include "opencv2/cudaoptflow.hpp"

#include <dirent.h>

using namespace std;
using namespace cv;
using namespace cv::cuda;

float MIN_SZ = 256;
float OUT_SZ = 256;

bool clipFlow = true; // clips flow to [-20 20]
bool resize_img = false;

// These are default paths

std::string vid_path = "/home/katou2/github-home/gpu_flow/build/test";
std::string out_path    = "/home/katou2/github-home/gpu_flow/build/test_out";
std::string out_path_jpeg   = "/home/katou2/github-home/gpu_flow/build/test_out";

bool createOutDirs = true;

/* THESE ARE MY PARAMS, NOT FEICHENHOFER'S */

bool debug = false;
bool rgb = false;
bool bins = false;

// Global variables for cuda::BroxOpticalFlow
const float alpha_ = 0.197;
const float gamma_ = 50;
const float scale_factor_ = 0.8;
const int inner_iterations_ = 10;
const int outer_iterations_ = 77;
const int solver_iterations_ = 10;

const int RESIZE_WIDTH = 224;
const int RESIZE_HEIGHT = 224;
const bool warp = false;

void converFlowMat(Mat& flowIn, Mat& flowOut,float min_range_, float max_range_)
{
    float value = 0.0f;
    for(int i = 0; i < flowIn.rows; i++)
    {
        float* Di = flowIn.ptr<float>(i);
        char* Ii = flowOut.ptr<char>(i);
        for(int j = 0; j < flowIn.cols; j++)
        {
            value = (Di[j]-min_range_)/(max_range_-min_range_);

            value *= 255;
            value = cvRound(value);

            Ii[j] = (char) value;
        }
    }
}

static void convertFlowToImage(const Mat &flowIn, Mat &flowOut,
        float lowerBound, float higherBound) {
    #define CAST(v, L, H) ((v) > (H) ? 255 : (v) < (L) ? 0 : cvRound(255*((v) - (L))/((H)-(L))))
    for (int i = 0; i < flowIn.rows; ++i) {
        for (int j = 0; j < flowIn.cols; ++j) {
            float x = flowIn.at<float>(i,j);
            flowOut.at<uchar>(i,j) = CAST(x, lowerBound, higherBound);
        }
    }
    #undef CAST
}

int main( int argc, char *argv[] )
{
    GpuMat frame0GPU, frame1GPU, flowGPU;
    Mat frame0_rgb_, frame1_rgb_, frame0_rgb, frame1_rgb, frame0, frame1, rgb_out;
    Mat frame0_32, frame1_32, imgU, imgV;
    Mat motion_flow, flow_rgb;
    Mat flowCPU, planes[3], mag;
    char cad[N_CHAR];
    struct timeval tod1;
    double t1 = 0.0, t2 = 0.0, tdflow = 0.0, t1fr = 0.0, t2fr = 0.0, tdframe = 0.0;

    int start_with_vid = 1;
    int gpuID = 0;
    int type = 1;
    int frameSkip = 1;


    int vidcount = 0;

    const char* keys = 
                "{ help h usage ? |       | print this message   }"
                "{ start_video    |   1   | start video id       }"
                "{ gpuID          |   1   | use this gpu ...
(more)
edit retag flag offensive close merge delete

Comments

You should learn about debugging, that's the thing programmers do to find where and why code crashes with the data they pass to it.

mvuori gravatar imagemvuori ( 2020-05-17 14:14:31 -0600 )edit