I'm having difficulty reading in some video files when using OpenCV with the C ++ interface in Visual Studio 2013. I could read in other video formats, so I think my code is fine.
Problems with the video files were made using Go Pro and mp4. I can play them on the same machine that I use OpenCV using a classic media player. I used MediaInfo to collect information about the video file:
Format: MPEG-4 Profile Profile: JVT Codec ID: avc1 File Size: 126 MiB
I tried to provide 4ccc codes explicitly using the installed OpenCV function and providing divx as code and avc1, but no luck.
My program code is as follows:
int main(int argc, char** argv) {
if (argc != 2) {
help(argv);
system("Pause");
return 1;
}
std::string arg = argv[1];
VideoCapture capture;
capture.set(CV_CAP_PROP_FOURCC, CV_FOURCC('A', 'V', 'C', '1'));
capture.open(arg);
if (!capture.isOpened()) {
cerr << "Failed to open video file!\n" << endl;
help(argv);
system("Pause");
return 1;
}
return process(capture);
}
void help(char** argv) {
cout << "\n TBC" << endl;
}
int process(VideoCapture& src) {
Scalar const LOW_HSV_THRESHOLD(120, 45, 75);
Scalar const HIGH_HSV_THRESHOLD(140, 55, 85);
string windowName[] = { "Original", "HSV", "In Range", "Binary"};
namedWindow(windowName[0], CV_WINDOW_KEEPRATIO);
namedWindow(windowName[1], CV_WINDOW_KEEPRATIO);
namedWindow(windowName[2], CV_WINDOW_KEEPRATIO);
namedWindow(windowName[3], CV_WINDOW_KEEPRATIO);
Mat matOriginal;
Mat matHsv;
Mat matInRange;
Mat dst;
src >> matOriginal;
cvtColor(matOriginal, matHsv, CV_BGR2HSV);
GaussianBlur(matHsv, matHsv, Size(5, 5), 1.5);
cvtColor(matOriginal, matInRange, CV_BGR2GRAY);
threshold(matInRange, dst, 100, 255, THRESH_BINARY);
imshow(windowName[0], matOriginal);
imshow(windowName[1], matHsv);
imshow(windowName[2], matInRange);
imshow(windowName[3], dst);
waitKey(0);
return 0;
}
}
Any help would be greatly appreciated.
Many thanks,
Kevin