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?

sflee
  • 1,659
  • 5
  • 32
  • 63
  • Any error printed to console? – Miki Jul 19 '15 at 08:52
  • `Cannot open video!`, this is the only line /.\ Btw, I have the opencv 2.4.10 on my computer, I can use this function `cv::VideoCapture` with 2.4.10 on the other VS solution /.\ – sflee Jul 19 '15 at 09:45
  • 1
    Double check if you added all required libraries as the other solution – Miki Jul 19 '15 at 10:19
  • Here is the list of lib I have under opencv 3.0.0 `opencv_ts300.lib opencv_world300.lib`. Is that means I have to build the libraries by myself@@? – sflee Jul 19 '15 at 10:34
  • 1
    You may want to try it with an .avi container, see http://stackoverflow.com/questions/20852514/list-file-extensions-supported-by-opencv. – Baris Demiray Jul 19 '15 at 12:22
  • can your program access the opencv_ffmpeg dll? – Micka Jul 19 '15 at 19:53

0 Answers0