OpenCV Error: Assertion failed with live stream video [closed]

asked 2017-12-28 10:01:20 -0500

calocabe96 gravatar image

updated 2017-12-28 12:19:32 -0500

Im trying to count traffic with a live stream video of a ip camera in my raspberry pi 3 . One minute after running my programm this error comes out.

OpenCV Error: Assertion failed (dims <= 2 && step[0] > 0) in locateROI, file /home/pi/opencv/opencv-3.3.0/modules/core/src/matrix.cpp, line 981 terminate called after throwing an instance of 'cv::Exception' what(): /home/pi/opencv/opencv-3.3.0/modules/core/src/matrix.cpp:981: error: (-215) dims <= 2 && step[0] > 0 in function locateROI Abortado

This happen everytime I run it. Also when I run a code just to display the live video some times, this comes out.

[h264 @ 0x1f34000] left block unavailable for requested intra mode at 0 40 [h264 @ 0x1f34000] error while decoding MB 0 40, bytestream 0

I'm using a code I found to count cars that works pretty good with videos, but when I set a video stream instead, it crashes. I'm using C++

Actually I'm new on OpenCV and C++, so if anybody can help me understand what am I doing wrong, and why my programm works well just with videos and not with stream videos, I'll apreciate

int main(void) {

    cv::VideoCapture capVideo;
    cv::Mat imgFrame1;
    cv::Mat imgFrame2;
    std::vector<Blob> blobs;
    cv::Point crossingLine[2];"rtsp://myipcamera:554/11");

    if (!capVideo.isOpened()) {                                                 // if unable to open video file
        std::cout << "error reading video file" << std::endl << std::endl;      // show error message
        _getch();                   // it may be necessary to change or remove this line if not using Windows
        return(0);                                                              // and exit program

    if (capVideo.get(CV_CAP_PROP_FRAME_COUNT) < 2) {
        std::cout << "error: video file must have at least two frames";
        _getch();                   // it may be necessary to change or remove this line if not using Windows

    //Puntos para trazar la linea sensor
    int intHorizontalLinePosition = (int)std::round((double)imgFrame1.cols * 0.55);

    crossingLine[0].x = intHorizontalLinePosition;
    crossingLine[0].y = 0;

    crossingLine[1].x = intHorizontalLinePosition;
    crossingLine[1].y = imgFrame1.rows - 1;

    char chCheckForEscKey = 0;
    bool blnFirstFrame = true;
    int frameCount = 2;

    //El loop que se realice mientras el video esté abierto o mientras no presionen esc
    while (capVideo.isOpened() && chCheckForEscKey != 27) {

        std::vector<Blob> currentFrameBlobs;

        cv::Mat imgFrame1Copy = imgFrame1.clone();
        cv::Mat imgFrame2Copy = imgFrame2.clone();

        cv::Mat imgDifference;
        cv::Mat imgThresh;

        cv::cvtColor(imgFrame1Copy, imgFrame1Copy, CV_BGR2GRAY);
        cv::cvtColor(imgFrame2Copy, imgFrame2Copy, CV_BGR2GRAY);

        cv::GaussianBlur(imgFrame1Copy, imgFrame1Copy, cv::Size(5, 5), 0);
        cv::GaussianBlur(imgFrame2Copy, imgFrame2Copy, cv::Size(5, 5), 0);

        cv::absdiff(imgFrame1Copy, imgFrame2Copy, imgDifference);

        cv::threshold(imgDifference, imgThresh, 30, 255.0, CV_THRESH_BINARY);

        //  cv::namedWindow("imgThresh", CV_WINDOW_AUTOSIZE); // Create a window for display.

        cv::imshow("imgThresh", imgThresh);

        cv::Mat structuringElement3x3 = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3));
        cv::Mat structuringElement5x5 = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(5, 5));
        cv::Mat structuringElement7x7 = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(7, 7));
        cv::Mat structuringElement15x15 = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(15, 15));

        for (unsigned int ...
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-12-08 18:24:27.575847


we probably cannot help you, without seeing your code

berak gravatar imageberak ( 2017-12-28 11:03:52 -0500 )edit

Here it's my code

calocabe96 gravatar imagecalocabe96 ( 2017-12-28 11:11:31 -0500 )edit

please put it here, not on an external site

berak gravatar imageberak ( 2017-12-28 11:15:04 -0500 )edit

it has more than 500 lines of code, it doesn't matter ?

calocabe96 gravatar imagecalocabe96 ( 2017-12-28 11:35:23 -0500 )edit

ok, then rather let it be.

but it's all quite unfortunate, now. noone will dig through such a wall anyway..

berak gravatar imageberak ( 2017-12-28 12:06:33 -0500 )edit

I tried to reduce my main method.

calocabe96 gravatar imagecalocabe96 ( 2017-12-28 12:20:25 -0500 )edit

some remarks:

capVideo.get(CV_CAP_PROP_POS_FRAMES) + 1) < capVideo.get(CV_CAP_PROP_FRAME_COUNT)

ipcams don't have a "FRAME_COUNT" ,and you probably don't get a position, either. did you check it ?;

please check return value. probably some frame is empty()

berak gravatar imageberak ( 2017-12-28 13:11:30 -0500 )edit

I already changed that and got the same error. I also tried in my PC and the program runs perfect, but not in my raspberry. I mean the program works for about a minute (in the raspberry pi3), it counts cars and after that minute it crashes, showing this error in console:

**OpenCV Error: Assertion failed (dims <= 2 && step[0] > 0) in locateROI, file /home/pi/opencv/opencv-3.3.0/modules/core/src/matrix.cpp, line 981
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/pi/opencv/opencv-3.3.0/modules/core/src/matrix.cpp:981: error: (-215) dims <= 2 && step[0] > 0 in function locateROI


Is there anything I can do to make it run like in my PC, or the raspberry hardware is not enough for my application?

calocabe96 gravatar imagecalocabe96 ( 2017-12-28 14:32:25 -0500 )edit

it's a flaw in your program, you've got an empty image somewhere (step[0]>0)

berak gravatar imageberak ( 2017-12-28 14:46:26 -0500 )edit

yeah but if my program has a flaw it shouldn't work neither in the Rpi 3 neither in my pc, and in my PC runs perfectly with the same program... that's what I don't understand. So now I want to know if the raspberry pi is robust enough for this aplication. Morever I need my raspberry pi 3 to support 2 cameras at a time, each one running in a thread and the counting to be store in a database every 15minutes for example

calocabe96 gravatar imagecalocabe96 ( 2017-12-28 15:13:55 -0500 )edit