Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

During startap, gives an error in console

Hi. I wrote the program code. The compliler does not give error, but the console throws the following error:

terminate called after throwing an instance of 'std::logic_error' what(): basic_string::_M_construct null not valid

This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.

Here is my program code:

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <fstream>
using namespace std;
using namespace cv;

int g_slider_position = 0;
int g_run = 1, g_dontset = 0;
//start out in single step mode
VideoCapture g_cap;
void onTrackbarSlide( int pos, void *) {
    g_cap.set( CV_CAP_PROP_POS_FRAMES, pos );
    if( !g_dontset )
        g_run = 1;
    g_dontset = 0;
}
int main( int argc, char** argv )
{
    namedWindow( "Example2_4", WINDOW_AUTOSIZE );
    g_cap.open( string(argv[1]) );
    int frames = (int) g_cap.get(CV_CAP_PROP_FRAME_COUNT);
    int tmpw   = (int) g_cap.get(CV_CAP_PROP_FRAME_WIDTH);
    int tmph   = (int) g_cap.get(CV_CAP_PROP_FRAME_HEIGHT);
    cout << "Video has " << frames << " frames of dimensions(" << tmpw << ", " << tmph << ")." << endl;
    createTrackbar("Position", "Example2_4", &g_slider_position, frames, onTrackbarSlide);
    Mat frame;
    while(1) {
        if( g_run != 0 ) {
            g_cap >> frame;
            if(!frame.data) break;
            int current_pos = (int)g_cap.get(CV_CAP_PROP_POS_FRAMES);
            g_dontset = 1;
            setTrackbarPos("Position", "Example2_4", current_pos);
            imshow( "Example2_4", frame );
            g_run-=1;
        }
        char c = (char) waitKey(10);
        if(c == 's') // single step
        {g_run = 1;
            cout << "Single step, run = " << g_run << endl;
        }
        if(c == 'r') // run mode
        {g_run = -1;
            cout << "Run mode, run = " << g_run <<endl;
        }
        if( c == 27 )
            break;
    }
    return(0);
}

This code i took from the textbook. Explain please where did i go wrong.