Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

optflowgf.cpp, line 1102 terminate called after throwing an instance of 'cv::Exception'

There is an exception in running the below : When I debugged I found that the code is crashing in the function call calcOpticalFlowFarneback(). I have just run the sample code written below. Could anyone help me solve this issue.I am working in the Qt Creator programming environment -----------------------------------------exception---------------------------------------------------- Starting /home/santhosh/opencv-qt/OpticalFlowDense2/OpticalFlowDense2... OpenCV Error: Assertion failed (prev0.size() == next0.size() && prev0.channels() == next0.channels() && prev0.channels() == 1 && pyr_scale < 1) in calcOpticalFlowFarneback, file /home/santhosh/opencv/opencv-3.1.0-source/modules/video/src/optflowgf.cpp, line 1102 terminate called after throwing an instance of 'cv::Exception' what(): /home/santhosh/opencv/opencv-3.1.0-source/modules/video/src/optflowgf.cpp:1102: error: (-215) prev0.size() == next0.size() && prev0.channels() == next0.channels() && prev0.channels() == 1 && pyr_scale < 1 in function calcOpticalFlowFarneback

The program has unexpectedly finished.

----------------------------Code--------------------------------------------------------------------------- void drawOptFlowMap (const Mat& flow, Mat& cflowmap, int step, const Scalar& color);

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); Mat prev_im,nex_im,flow;

prev_im=imread("image1.jpg",0);
if (!prev_im.data)
{
    QMessageBox msg;
    msg.setText("Could not Load image1");
    msg.exec();
}
//namedWindow("previm", cv::WINDOW_AUTOSIZE);
imshow("previm",prev_im);


nex_im=imread("image2.jpg",0);
if (!nex_im.data)
{
    QMessageBox msg;
    msg.setText("Could not Load image2");
    msg.exec();
}
//namedWindow("nextim", cv::WINDOW_AUTOSIZE);
imshow("nextim",nex_im);


calcOpticalFlowFarneback(prev_im,nex_im,flow,0.5, 1, 12, 2, 7, 1.5, 0);

Mat cflow;
cvtColor(prev_im, cflow, CV_GRAY2BGR);
drawOptFlowMap(flow, cflow, 10, CV_RGB(0, 255, 0));


imshow("OpticalFlowFarneback", cflow);


waitKey(0);

}

void drawOptFlowMap (const Mat& flow, Mat& cflowmap, int step, const Scalar& color) { for(int y = 0; y < cflowmap.rows; y += step) { for(int x = 0; x < cflowmap.cols; x += step) { const Point2f& fxy = flow.at< Point2f>(y, x); line(cflowmap, Point(x,y), Point(cvRound(x+fxy.x), cvRound(y+fxy.y)), color); circle(cflowmap, Point(cvRound(x+fxy.x), cvRound(y+fxy.y)), 1, color, -1);

  }

} }

optflowgf.cpp, line 1102 terminate called after throwing an instance of 'cv::Exception''cv::Exception' in calcOpticalFlowFarneback

There is an exception in running the below : When I debugged I found that the code is crashing in the function call calcOpticalFlowFarneback(). I have just run the sample code written below. Could anyone help me solve this issue.I am working in the Qt Creator programming environment -----------------------------------------exception---------------------------------------------------- Starting /home/santhosh/opencv-qt/OpticalFlowDense2/OpticalFlowDense2... OpenCV Error: Assertion failed (prev0.size() == next0.size() && prev0.channels() == next0.channels() && prev0.channels() == 1 && pyr_scale < 1) in calcOpticalFlowFarneback, file /home/santhosh/opencv/opencv-3.1.0-source/modules/video/src/optflowgf.cpp, line 1102 terminate called after throwing an instance of 'cv::Exception' what(): /home/santhosh/opencv/opencv-3.1.0-source/modules/video/src/optflowgf.cpp:1102: error: (-215) prev0.size() == next0.size() && prev0.channels() == next0.channels() && prev0.channels() == 1 && pyr_scale < 1 in function calcOpticalFlowFarneback

The program has unexpectedly finished.

----------------------------Code--------------------------------------------------------------------------- void drawOptFlowMap (const Mat& flow, Mat& cflowmap, int step, const Scalar& color);

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); Mat prev_im,nex_im,flow;

prev_im=imread("image1.jpg",0);
if (!prev_im.data)
{
    QMessageBox msg;
    msg.setText("Could not Load image1");
    msg.exec();
}
//namedWindow("previm", cv::WINDOW_AUTOSIZE);
imshow("previm",prev_im);


nex_im=imread("image2.jpg",0);
if (!nex_im.data)
{
    QMessageBox msg;
    msg.setText("Could not Load image2");
    msg.exec();
}
//namedWindow("nextim", cv::WINDOW_AUTOSIZE);
imshow("nextim",nex_im);


calcOpticalFlowFarneback(prev_im,nex_im,flow,0.5, 1, 12, 2, 7, 1.5, 0);

Mat cflow;
cvtColor(prev_im, cflow, CV_GRAY2BGR);
drawOptFlowMap(flow, cflow, 10, CV_RGB(0, 255, 0));


imshow("OpticalFlowFarneback", cflow);


waitKey(0);

}

void drawOptFlowMap (const Mat& flow, Mat& cflowmap, int step, const Scalar& color) { for(int y = 0; y < cflowmap.rows; y += step) { for(int x = 0; x < cflowmap.cols; x += step) { const Point2f& fxy = flow.at< Point2f>(y, x); line(cflowmap, Point(x,y), Point(cvRound(x+fxy.x), cvRound(y+fxy.y)), color); circle(cflowmap, Point(cvRound(x+fxy.x), cvRound(y+fxy.y)), 1, color, -1);

  }

} }

click to hide/show revision 3
No.3 Revision

updated 2016-02-10 09:50:29 -0600

berak gravatar image

'cv::Exception' in calcOpticalFlowFarneback

There is an exception in running the below : When I debugged I found that the code is crashing in the function call calcOpticalFlowFarneback(). I have just run the sample code written below. Could anyone help me solve this issue.I am working in the Qt Creator programming environment -----------------------------------------exception---------------------------------------------------- -----------------------------------------exception----------------------------------------------------

Starting /home/santhosh/opencv-qt/OpticalFlowDense2/OpticalFlowDense2...
OpenCV Error: Assertion failed (prev0.size() == next0.size() && prev0.channels() == next0.channels() && prev0.channels() == 1 && pyr_scale < 1) in calcOpticalFlowFarneback, file /home/santhosh/opencv/opencv-3.1.0-source/modules/video/src/optflowgf.cpp, line 1102
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/santhosh/opencv/opencv-3.1.0-source/modules/video/src/optflowgf.cpp:1102: error: (-215) prev0.size() == next0.size() && prev0.channels() == next0.channels() && prev0.channels() == 1 && pyr_scale < 1 in function calcOpticalFlowFarneback

calcOpticalFlowFarneback The program has unexpectedly finished.

finished.

----------------------------Code--------------------------------------------------------------------------- ----------------------------Code---------------------------------------------------------------------------

void drawOptFlowMap (const Mat& flow, Mat& cflowmap, int step, const Scalar& color);

color); MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); Mat prev_im,nex_im,flow;

prev_im,nex_im,flow;

    prev_im=imread("image1.jpg",0);
 if (!prev_im.data)
{
    {
        QMessageBox msg;
     msg.setText("Could not Load image1");
     msg.exec();
}
    }
    //namedWindow("previm", cv::WINDOW_AUTOSIZE);
 imshow("previm",prev_im);


 nex_im=imread("image2.jpg",0);
 if (!nex_im.data)
{
    {
        QMessageBox msg;
     msg.setText("Could not Load image2");
     msg.exec();
}
    }
    //namedWindow("nextim", cv::WINDOW_AUTOSIZE);
 imshow("nextim",nex_im);


 calcOpticalFlowFarneback(prev_im,nex_im,flow,0.5, 1, 12, 2, 7, 1.5, 0);

 Mat cflow;
 cvtColor(prev_im, cflow, CV_GRAY2BGR);
 drawOptFlowMap(flow, cflow, 10, CV_RGB(0, 255, 0));


 imshow("OpticalFlowFarneback", cflow);


 waitKey(0);

}

} void drawOptFlowMap (const Mat& flow, Mat& cflowmap, int step, const Scalar& color) { for(int y = 0; y < cflowmap.rows; y += step) { for(int x = 0; x < cflowmap.cols; x += step) { const Point2f& fxy = flow.at< Point2f>(y, x); line(cflowmap, Point(x,y), Point(cvRound(x+fxy.x), cvRound(y+fxy.y)), color); circle(cflowmap, Point(cvRound(x+fxy.x), cvRound(y+fxy.y)), 1, color, -1);

 -1);

      }
 }
}

} }