1

So I have played around in OpenCV a bunch before and never run into this problem. I am implementing a MeanShift algorithm and trying to do it on video devices, images, and videos. Devices and images work; however, no matter what I try, when I run VideoCapture on my filename (whether setting it in the Constructor or using the VideoCapture::open() method, and whether local or with a full path) I always get stuck in my error check.

Thoughts? Ideas? code below. running in Visual Studio 2012

    #include "opencv2\highgui\highgui.hpp"
#include "opencv2\core\core.hpp"
#include "opencv2\opencv.hpp"
#include "opencv2\video\video.hpp"
#include <string>

using cv::Mat;
using std::string;

enum Filetype{Image, Video};

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

    string filename = "short_front.avi";// "C:\\Users\\Jonathan\\Videos\\short_front.mp4"; //"hallways.jpg";


    Mat cv_image;       //convert to unsigned char * with data
    Mat filtImage_;
    Mat segmImage_;
    Mat whiteImage_;

    cv::VideoCapture vid;
    vid.open("C:/Users/Jonathan/Desktop/TestMeanShift/TestMeanShift/short_front.avi");
    cv::waitKey(1000);
    if ( !vid.isOpened() ){
        throw "Error when reading vid";
        cv::waitKey(0);
        return -1;
    }

//  cv_image = cv::imread(filename);//, CV_LOAD_IMAGE_COLOR);

//  if(! cv_image.data){
//      std::cerr << "Image Failure: " << std::endl;
//      system("pause");
//      return -1;
//  }
    //Mat cv_image_gray;
    //cv::cvtColor(cv_image,cv_image_gray,CV_RGB2GRAY);

    for (;;)
    {
        vid >> cv_image;
        if ( !cv_image.data)
            continue;


    cv::imshow("Input",cv_image); //add a normal window here to resizable
}

EDIT: This is a distinct problem from the one listed here because it deals with a specific corner case: VideoCapture and ImageCapture both work, only not VideoCapture with a file. When it doesn't work, the code runs properly, except that the "video" it creates is incomplete as it didn't open properly. Therefore, as the code above does not crash in compile time or run time, the only indicator is bad output (6KB video output file). If you are having issues not with the corner case I am describing but general issues with the above functions in OpenCV, the aforementioned link could help you.

Community
  • 1
  • 1
physincubus
  • 986
  • 2
  • 11
  • 26
  • please check if you have included opencv dll's in the directory! – Rahul galgali May 27 '15 at 11:52
  • possible duplicate of [VideoCapture OpenCV 2.4.2 error in windows](http://stackoverflow.com/questions/12279833/videocapture-opencv-2-4-2-error-in-windows) – Rahul galgali May 27 '15 at 11:53
  • 1
    not a duplicate as `VideoCapture cap(0)` works. However, I did resolve this by reexamining which .dlls and includes I used. When I have a grasp on this that is more helpful, I will write it as a response and mark it as a solution. However, until then, the short answer for anyone who encounters this problem is: if something isn't working in opencv, and you haven't already, first step is to include ALL libs and .dlls to ensure that this isn't the problem. In my case, its not obvious, as capture devices and imread both still worked, and no errors, at runtime or otherwise, were being thrown – physincubus Jun 01 '15 at 22:08

0 Answers0