video - OpenCV : .avi file doesn't open with C++ API, opens with C -
could explain me why opencv fails open .avi file c++ api, instead opens c api ?
here 2 code snippets:
c++:
mat source; videocapture stream("video.avi"); if (!stream.isopened()){ std::cout << "stream cannot opened" << std::endl; return -1; } while(1) if(!stream.read(source)) { std::cout << "error reading video frame" << endl; } imshow("source", source);
this fails open video.avi, , "error reading video frame" printed time after time. ffmpeg.dll in path , have installed ffdshow.
c:
cvcapture* stream = cvcreatefilecapture( "video.avi" ); iplimage* source; while(1) { source = cvqueryframe( stream ); if( !source ) printf("\n problem"); mat src(source); imshow("source", src); if(waitkey(1) >= 0) break; }
this opens video.avi no problem.
thanks !
ps. maybe it's worth mentioning video.avi created using opencv.
your c , c++ code not equal. code work:
int main( int argc, char** argv ) { mat source; videocapture stream("video.avi"); if (!stream.isopened()) { std::cout << "stream cannot opened" << std::endl; return -1; } while(1) { stream >> source; if(source.empty()) { std::cout << "error reading video frame" << endl; } imshow("source", source); waitkey(20); } stream.release(); getchar(); }
Comments
Post a Comment