Note that there are some explanatory texts on larger screens.

plurals
  1. POReading a video with openCV
    text
    copied!<p>I have a video <strong>engine2.avi</strong> that I want to read and show with openCV. Here's my code:</p> <pre><code>#include &lt;opencv2/core/core.hpp&gt; #include &lt;opencv2/highgui/highgui.hpp&gt; #include &lt;iostream&gt; using namespace cv; int main(int argc, char** argv) { string filename = "D:\\BMDvideos\\engine2.avi"; VideoCapture capture(filename); Mat frame; if( !capture.isOpened() ) throw "Error when reading steam_avi"; namedWindow("w", 1); for( ; ; ) { capture &gt;&gt; frame; //if(!frame) // break; imshow("w", frame); waitKey(20); // waits to display frame } waitKey(0); } </code></pre> <p>This code doesn't work if my file has the codec <code>YUV 4:2:2 (UYVY)</code> (I recorded the video using Direct-Show), but works when I use a video I grabbed whit openCV !!</p> <p>Has anybody an Idea how this could work ? </p> <p><strong>UPDATE:</strong></p> <p>After reading some links, suggesting that catching exception will solve the problem, I modified my code. It didn't help, but here is the modified code:</p> <pre><code>cv::VideoCapture cap("d:\\BMDvideos\\engine2.avi"); cv::Mat frame; try { cap &gt;&gt; frame; } catch(cv::Exception ex) { std::cout &lt;&lt; ex.what() &lt;&lt; std::endl; } catch(...) { std::cout &lt;&lt; "Unknown exception" &lt;&lt; std::endl; } </code></pre> <p>The program crashes in <code>cap&gt;&gt;frame</code>. I readed similar questions but they use a frame in YUV (4:2:0), while my video has UYVY (4:2:2). How can I convert this into RGB color model?</p> <p><strong>UPDATE 2:</strong> </p> <p>After karlphillip's suggestion, I used OpenCV2.4.3, but I still got the same error using the code below:</p> <pre><code>#include &lt;opencv2\core\core.hpp&gt; #include &lt;opencv2\highgui\highgui.hpp&gt; #include &lt;opencv2\opencv.hpp&gt; using namespace cv; using namespace std; int main(){ cv::Mat frame; cv::VideoCapture cap("d:\\BMDvideos\\B\\Aufnahme.avi"); if(!cap.isOpened()) { cout &lt;&lt; "Error can't find the file"&lt;&lt;endl; } while(1){ if(!cap.read(frame)) imshow("",frame); cv::waitKey(33); } return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload