Hi I am trying to play a video using the following code:
//#include <stdio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
//#include <iostream>
using namespace cv;
int main(int argc, char** argv)
{
string filename = "anime.avi";
VideoCapture capture(filename);
Mat frame;
if( !capture.isOpened() )
throw "Error when reading steam_avi";
namedWindow( "w", 1);
for( ; ; )
{
capture >> frame;
if(!frame)
break;
imshow("w", frame);
waitKey(20); // waits to display frame
}
waitKey(0); // key press to close window
// releases and window destroy are automatic in C++ interface
}
When I run it though, I get the following errors:
project.cpp: In function ‘int main(int, char**)’:
project.cpp:23:13: error: no match for ‘operator!’ in ‘!frame’
project.cpp:23:13: note: candidates are:
project.cpp:23:13: note: operator!(bool) <built-in>
project.cpp:23:13: note: no known conversion for argument 1 from ‘cv::Mat’ to ‘bool’
/usr/local/include/opencv2/core/operations.hpp:2220:20: note: bool cv::operator!(const cv::Range&)
/usr/local/include/opencv2/core/operations.hpp:2220:20: note: no known conversion for argument 1 from ‘cv::Mat’ to ‘const cv::Range&’
Could you possibly help. I’ve been on this for hours without success 🙁
Because there is no
operator!overloaded for classcv::Mat. In the documentation, it not said clearly, what should happen with the image in case of acquisition failed. That’s the implementation ofcv::VideoCapture::operator>>fromcap.cpp:Now go to documentation on
cv::Mat:release. And let’s double check it’s implementation from themat.hpp:Hence, finally, you can check the
datapointer to find out, whether the grab was successful:However, I recommend to use function-style call
cv::VideoCapture::readin this case, since it explicitly returns whether it was successful, or not:HTH