Reputation: 5812
I have encapsulated the OpenCV VideoCapture class into a class of my own and am trying to initialize it from a video file on disk. The .isOpened()
function returns true, but the frames I read later on are empty.
VideoCapture
can't read frames, why is it reporting being open? Here is a tiny excerpt. Init()
later throws an error because the frames read by camera_.read()
are empty. Better scroll through to the code at the bottom, it exemplifies the problem better.
Camera::Camera(int target_width, int target_height, std::string filename)
: target_width_(target_width),
target_height_(target_height),
camera_(filename)
{
if (!camera_.isOpened()){
cerr << "Failed to open video file" << endl;
exit(EXIT_FAILURE);
}
camera_.read(frame_full_);
if (frame_full_.empty()){
cerr << "Failed to read from video file" << endl;
exit(EXIT_FAILURE);
}
Init();
}
EDIT:
So, reading from an actual webcam works fine, it is the code above (reading from a file by filename) that returns empty frames.
EDIT2:
So—as suggested by Mhd.Tahawi—my whole problem can be summarized by the code below:
cv::VideoCapture cap("/Users/Me/Projects/whatev/some_video__640x360.avi");
cv::Mat test;
if (cap.isOpened()){
cap.read(test);
if (test.empty()) {
std::cout << "BRO DO YOU EVEN CAPTURE?" << std::endl;
}
}
Upvotes: 0
Views: 1401
Reputation: 1894
I suspect codec problems - your code looks fine.
On a Mac, use brew install opencv --with-ffmpeg
.
(But double check if you really have a the correct filepath, even though it shouldn't say that it is open). If you are on windows you need "\" in your path.
Upvotes: 1