Ask Your Question
0

During startap, gives an error in console

asked 2016-11-24 02:41:15 -0500

petro gravatar image

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.

edit retag flag offensive close merge delete

Comments

What is value of argv[1]?

LBerger gravatar imageLBerger ( 2016-11-24 04:06:16 -0500 )edit

Honestly speaking, I myself find it difficult to answer. This example I took from the book "Adrian Kaehler - Learning OpenCV Computer Vision". The second Chapter.

petro gravatar imagepetro ( 2016-11-24 04:19:51 -0500 )edit
1

in cmd windows : myprogram fullpathtovideo

LBerger gravatar imageLBerger ( 2016-11-24 04:23:54 -0500 )edit

you program expects a video filename as console argument

berak gravatar imageberak ( 2016-11-24 04:33:50 -0500 )edit

give an example of how to write it

petro gravatar imagepetro ( 2016-11-24 04:36:36 -0500 )edit

like in the comment above: myprog.exe /full/path/to/videofile

berak gravatar imageberak ( 2016-11-24 04:38:42 -0500 )edit

I feel like an idiot. Prompt please where it is necessary to prescribe.

petro gravatar imagepetro ( 2016-11-24 04:45:48 -0500 )edit

(you're a noob, not an idiot)

but now, i don't understand, what you mean ??

berak gravatar imageberak ( 2016-11-24 04:53:23 -0500 )edit

Ok. I have instead of argv[1] to set the path to the file?

petro gravatar imagepetro ( 2016-11-24 05:04:07 -0500 )edit

yes, that's another idea (have it hardcoded)

berak gravatar imageberak ( 2016-11-24 05:27:07 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-11-24 05:18:58 -0500

petro gravatar image

Thanks, I understand how to fix.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-11-24 02:22:59 -0500

Seen: 245 times

Last updated: Nov 24 '16