read sequence of videos from folder

asked 2018-12-30 23:55:15 -0500

arti gravatar image

Hello all i'm trying to read sequence of videos from the folder..please check the error. each folde has 12 to 20 images. after reading one frame, i'm getting error. Here id the my code

include "opencv2/opencv.hpp"

include <sstream>

include <iostream>

using namespace cv; using namespace std;

int main(int argc, char** argv) {

int i = 1;
char filename[80];
Mat src;
int count = 1;
while (1)
{

    //cap.read (frame);

    sprintf(filename, "action_youtube_naudio/biking/biking/biking_%d.avi", i);
    VideoCapture vid(filename);

    while (!vid.isOpened())
    {
        //VideoCapture vid("video.avi");
        cout << "charging" << endl;
        waitKey(1000);

    }

    Mat frame;
    Mat  gray;

    while (1)
    {
        vid.read(frame);
        if (frame.empty()) break;


        //if(!frame.data || src.rows == 0 ||  i == 21 ) break; 
        if (frame.empty()) break;
        imshow("frame", frame);
        count++;
    }

    cout << count;
    i++;
}
    waitKey(27);

}

edit retag flag offensive close merge delete

Comments

and the error is ? do we have to guess it ?

berak gravatar imageberak ( 2018-12-31 00:42:10 -0500 )edit

only first frame is read and then get error of opening file.

arti gravatar imagearti ( 2018-12-31 01:06:10 -0500 )edit

please be exact

you also have to put the waitKey(27) after the imshow(), else you won't see anything

berak gravatar imageberak ( 2018-12-31 01:11:35 -0500 )edit

thanks...yes problem resolved.

arti gravatar imagearti ( 2018-12-31 01:27:33 -0500 )edit