Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

you overcomplicated it (main noob problem).

you also should NOT rely on things like CAP_PROP_FRAME_COUNT, depending on your hw/os/backend/codec it might not be supported. also, those _getch() calls are non-portable, and will be terribly annoying, once you run your program outside your ide, get rid of it.

#include<opencv2/opencv.hpp> // please use opencv3 headers and *forward* slashes

#include<iostream>


int main(void) {

    cv::VideoCapture capVideo;
    capVideo.open("768x576.avi");

    if (!capVideo.isOpened()) {
        std::cout << "\nerror reading video file" << std::endl << std::endl;
        return(0);
    }

    cv::Mat imgFrame;
    while ( capVideo.read(imgFrame) ) { // will stop at the last frame

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

        int k = cv::waitKey(10);
        if (k == 27) // esc. pressed
            break;
    }
    return(0);
}