Ask Your Question

Sulfred's profile - activity

2017-05-16 12:14:30 -0600 received badge  Popular Question (source)
2015-07-19 05:51:31 -0600 received badge  Supporter (source)
2015-07-19 03:54:25 -0600 asked a question How to read a video under OpenCV 3.0.0

I am using win 8.1 and visual studio 2013 community. I download openCV3.0.0 from here. What I want to do is read a video. Following is my code

#include "stdafx.h"
#include "opencv2/opencv.hpp"
#include <iostream>


int _tmain(int argc, _TCHAR* argv[])
{
    cv::VideoCapture cap("bb.mp4");
    if (!cap.isOpened()){
        std::cout << "Cannot open video!\n";
        return -1;
    }
    cv::Mat frame;
    while (cap.read(frame)){
        cv::imshow("frame", frame);
        char key = cv::waitKey(1) & 0xFF;
    }
    return 0;
}

The problem is that cap.isOpened() always return false even I give an absolute path cv::VideoCapture cap("D:\bb.mp4"). Following is another toy program that operates normally.

#include "stdafx.h"
#include "opencv2/opencv.hpp"
#include <iostream>


int _tmain(int argc, _TCHAR* argv[])
{
    cv::Mat img = cv::imread("aa.jpg");
    cv::imshow("img", img);
    char key = cv::waitKey(1) & 0xFF;
    return 0;
}

The second program shows that I can compile a program included openCV library correctly and also the path to the file should be correct since the aa.jpg and bb.mp4 are placed in the same folder. Anyone knows how to solve the problem?