Debug_is_block_type_valid(header->_block_use) た 入场券 2022-09-30 14:45 110阅读 0赞 # [Debug Assertion Failed OpenCv is\_block\_type\_valid(header->\_block\_use)][Debug Assertion Failed OpenCv is_block_type_valid_header-_block_use] # [Ask Question][] <table> <tbody> <tr> <td> <div> <a title="This question shows research effort; it is useful and clear" rel="nofollow"> up vote</a> <span>2</span> <a title="This question does not show any research effort; it is unclear or not useful" rel="nofollow">down vote</a> <a href="http://stackoverflow.com/questions/34760254/debug-assertion-failed-opencv-is-block-type-validheader-block-use#" rel="nofollow">favorite</a> <div> <strong></strong> </div> </div> </td> <td> <div> <div> <p>I am new to Programming using Visual Studio and openCv. I wrote a simple program to display the red channel of an image, but every time i run the code it throws "DEBUG ASSERTION FAILED" error.</p> <pre><code>#include <opencv2\imgproc\imgproc.hpp> #include <opencv2\highgui\highgui.hpp> #include <iostream> using namespace std; using namespace cv; int main() { Mat image; image = imread("C:/Users/siddartha/Pictures/sample.jpg"); if (!image.data) { cout << "Cannot load image"; return -1; } else { if (image.channels() >= 3) { vector<Mat> rgb; split(image, rgb); namedWindow("r"); imshow("r", rgb[0]); } } while (1); return 0; } </code></pre> <p>Error:</p> <pre><code>Debug Assertion Failed! Program: ...sual Studio 2015\Projects\sampleOpenCV\Debug\sampleOpenCV.exe File: minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp Line: 892 Expression: is_block_type_valid(header->_block_use) </code></pre> <p><a href="https://i.stack.imgur.com/mKwlH.png" rel="nofollow"><img alt="Error Window" src="https://i.stack.imgur.com/mKwlH.png"></a></p> </div> <div> <a title="show questions tagged 'c++'" href="http://stackoverflow.com/questions/tagged/c%2b%2b" rel="nofollow">c++</a> <a title="show questions tagged 'opencv'" href="http://stackoverflow.com/questions/tagged/opencv" rel="nofollow">opencv</a> <a title="show questions tagged 'visual-studio-2015'" href="http://stackoverflow.com/questions/tagged/visual-studio-2015" rel="nofollow"> visual-studio-2015</a> <a title="show questions tagged 'visual-studio-debugging'" href="http://stackoverflow.com/questions/tagged/visual-studio-debugging" rel="nofollow"> visual-studio-debugging</a> </div> <table> <tbody> <tr> <td> <div> <a title="short permalink to this question" href="http://stackoverflow.com/q/34760254" rel="nofollow">share</a> <span>|</span> <a title="" href="http://stackoverflow.com/posts/34760254/edit" rel="nofollow">improve this question</a> </div> </td> <td> <div> <div> asked <span title="2016-01-13 06:59:30Z"> Jan 13 '16 at 6:59</span> </div> <div> <a href="http://stackoverflow.com/users/2772093/sidd607" rel="nofollow"></a> <div> <img width="32" height="32" alt="" src="https://www.gravatar.com/avatar/8d457b2ee895205265c927425fa72bd6?s=32&d=identicon&r=PG&f=1"> </div> </div> <div> <a href="http://stackoverflow.com/users/2772093/sidd607" rel="nofollow">sidd607</a> <div> <span title="reputation score ">284</span> <span title="3 silver badges"><span></span><span>3</span></span> <span title="15 bronze badges"><span></span><span>15</span></span> </div> </div> </div> </td> </tr> </tbody> </table> </div> </td> </tr> <tr> <td> </td> <td> <div> <table> <tbody> <tr> <td></td> <td> </td> </tr> </tbody> </table> </div> <div> <a title="Use comments to ask for more information or suggest improvements. Avoid answering questions in comments." rel="nofollow">add a comment</a> <span> | </span> <a title="expand to show all comments on this post" href="http://stackoverflow.com/questions/34760254/debug-assertion-failed-opencv-is-block-type-validheader-block-use#" rel="nofollow"></a> </div> </td> </tr> </tbody> </table> ## 2 Answers 2 ## [active][] [oldest][] [ votes][votes] <table> <tbody> <tr> <td> <div> <a title="This answer is useful" rel="nofollow"> up vote</a> <span>4</span> <a title="This answer is not useful" rel="nofollow">down vote</a> <span title="loading when this answer was accepted...">accepted</span> </div> </td> <td> <div> <p>Are you absolutely sure that the image has been loaded correctly? </p> <p>I would think that it hasn't been loaded correctly and because of that the vector<code>rgb</code> is empty and, in turn, the element <code>rgb[0]</code> doesn't exist which triggers the exception ...</p> <p>A couple of things I noted:</p> <ol> <li> <p>Use slashes (<code>/</code>) for include-statements not backslashes (<code>\</code>), i.e.</p> <pre><code>#include <opencv2\core.hpp> // Bad! #include <opencv2/core.hpp> // Good! </code></pre> </li> <li> <p>In your check</p> <pre><code>if (!image.data) { ... } </code></pre> <p><strong>do not</strong> assume that <code>image.data</code> is set to <code>NULL</code> or<code>nullptr</code> for empty images. Instead check </p> <pre><code>if (!image.empty()) { ... } </code></pre> </li> <li> <p>Make sure that calls to <code>cv::imshow(...)</code> are followed by a call to<code>cv::waitKey( /* delay in ms or 0 to wait for user input */ )</code>, cf. the note in the<a href="http://docs.opencv.org/3.1.0/d7/dfc/group__highgui.html#ga453d42fe4cb60e5723281a89973ee563" rel="nofollow">OpenCV reference</a>.</p> </li> <li> <p><code>while (1);</code> -- is that intentional? What you want is probably <code> cv::waitKey( 0 )</code> (see 3.).</p> </li> </ol> <p><strong>UPDATE:</strong></p> <ol> <li> <p>Make sure the vector <code>rgb</code> has been initialized to the number of channels, i.e.</p> <pre><code>vector<Mat> rgb(image.channels()); split(image, rgb); // ... </code></pre> </li> </ol> <p><strong>UPDATE 2:</strong></p> <blockquote> <p>Can you tell me what exactly the error meant ?</p> </blockquote> <p>Three things:</p> <ol> <li>The default constructor of <code>std::vector<T></code> creates an <em>empty</em> vector.</li> <li>Apparently, <code>cv::split()</code> expects the caller, i.e. <em>you</em>, to allocate data for the output. If you fail to do so, it's likely provoke a<a href="http://stackoverflow.com/questions/2346806/what-is-segmentation-fault" rel="nofollow">segmentation fault</a>.</li> <li>For debug builds some compilers add padding or safety memory around objects in memory which is never to be touched. If this padding memory is altered at runtime, the program "knows" that something bad happened and throws an exception like the one you saw.</li> </ol> </div> <table> <tbody> <tr> <td> <div> <a title="short permalink to this answer" href="http://stackoverflow.com/a/34762095" rel="nofollow">share</a> <span>|</span> <a title="" href="http://stackoverflow.com/posts/34762095/edit" rel="nofollow">improve this answer</a> </div> </td> <td align="right"> <div> <div> <a title="show all edits to this post" href="http://stackoverflow.com/posts/34762095/revisions" rel="nofollow">edited<span title="2016-01-15 09:05:14Z">Jan 15 '16 at 9:05</span></a> </div> <div></div> <div> <div></div> </div> </div> </td> <td align="right"> <div> <div> answered <span title="2016-01-13 08:51:05Z"> Jan 13 '16 at 8:51</span> </div> <div> <a href="http://stackoverflow.com/users/1141118/nils" rel="nofollow"></a> <div> <img width="32" height="32" alt="" src="https://www.gravatar.com/avatar/0b8d585e1d99173a8bfb15eafd79098f?s=32&d=identicon&r=PG&f=1"> </div> </div> <div> <a href="http://stackoverflow.com/users/1141118/nils" rel="nofollow">nils</a> <div> <span title="reputation score ">1,618</span> <span title="9 silver badges"><span></span><span>9</span></span> <span title="26 bronze badges"><span></span><span>26</span></span> </div> </div> </div> </td> </tr> </tbody> </table> </td> </tr> <tr> <td> </td> <td> <div> <table> <tbody> <tr> <td> <table> <tbody> <tr> <td></td> <td> </td> </tr> </tbody> </table> </td> <td> <div style="display:block"> <span>I did all the corrections you stated. but now it shows DEBUG Assertion Failure when i press a key in the end to exit.</span> – <a title="284 reputation" href="http://stackoverflow.com/users/2772093/sidd607" rel="nofollow">sidd607</a> <span><span title="2016-01-14 13:30:07Z">Jan 14 '16 at 13:30</span></span> <span title="this comment was edited 3 times"></span> </div> </td> </tr> <tr> <td> <table> <tbody> <tr> <td></td> <td> </td> </tr> </tbody> </table> </td> <td> <div style="display:block"> <span>Updated my answer.</span> – <a title="1,618 reputation" href="http://stackoverflow.com/users/1141118/nils" rel="nofollow">nils</a> <span><span title="2016-01-14 14:01:07Z">Jan 14 '16 at 14:01</span></span> </div> </td> </tr> <tr> <td> <table> <tbody> <tr> <td></td> <td> </td> </tr> </tbody> </table> </td> <td> <div style="display:block"> <span>updating the rgb worked for me. Can you tell me what exactly the error meant ?</span> – <a title="284 reputation" href="http://stackoverflow.com/users/2772093/sidd607" rel="nofollow">sidd607</a> <span><span title="2016-01-14 15:09:33Z">Jan 14 '16 at 15:09</span></span> <span title="this comment was edited 1 time"></span> </div> </td> </tr> <tr> <td> <table> <tbody> <tr> <td></td> <td> </td> </tr> </tbody> </table> </td> <td> <div style="display:block"> <span>Updated my answer again.</span> – <a title="1,618 reputation" href="http://stackoverflow.com/users/1141118/nils" rel="nofollow">nils</a> <span><span title="2016-01-15 09:05:27Z">Jan 15 '16 at 9:05</span></span> </div> </td> </tr> </tbody> </table> </div> <div> <a title="Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”." rel="nofollow">add a comment</a> <span> | </span> <a title="expand to show all comments on this post" href="http://stackoverflow.com/questions/34760254/debug-assertion-failed-opencv-is-block-type-validheader-block-use#" rel="nofollow"></a> </div> </td> </tr> </tbody> </table> [ ][Link 1] ![i.gif_e_eyJhdiI6NDE0LCJhdCI6NCwiYnQiOjAsImNtIjo0NzE0OTMsImNoIjoxMTc4LCJjayI6e30sImNyIjoxNjM4OTkxLCJkaSI6ImM1M2E4NzQ2NWVmOTRkM2ZiNzQyZTUyMWU4YjgyNmQzIiwiZG0iOjEsImZjIjoxOTQzNDQ1LCJmbCI6MjE0MjMxMiwiaXAiOiI0Mi4yMzYuMTU3LjE2NyIsImt3IjoiYysrLG9wZW5jdix2aXN1YWwtc3R1ZGlvLTIwMTUsdmlzdWFsLXN0dWRpby1kZWJ1Z2dpbmciLCJudyI6MjIsInBjIjowLCJlYyI6MCwicHIiOjE2MDQsInJ0IjoxLCJyZiI6Imh0dHBzOi8vd3d3LmJhaWR1LmNvbS9saW5rP3VybD1KWjVxVEhmME5aMzFPdi1YUmRPSGZ2ZmdKVk1ZQUNNbDg5emFHc1V1eVI4MWJQU1NJZ0NfODJZR2hGemFMdC1TcHVKRnZDbEZvYTNMWXZqR3RGSzlpTEI0YjZzcktuaGtRNXAydDZpMmNoSWV3NmNCVHpKdWFWemRCYlh6cTRyTzZiQUw5WFR4Tl9VdXFCZUNIS09tdzNnMnFrMlVhRlQ1MjE5TnZWUzE0RnEmd2Q9JmVxaWQ9ZTcxMmJkMzYwMDA0NTE3YjAwMDAwMDA2NThkMjdmNzYiLCJzdCI6ODI3NywidWsiOiJ1ZTEtMDVhN2Q2MWNkNGNhNGQwZjg1NDg4OTc0NmRiOTBjOGEiLCJ6biI6NDQsInRzIjoxNDkwMTk0MzAyNjc3LCJiZiI6dHJ1ZSwicG4iOiJhZHplcms0MTgxNTYzMzUiLCJmcSI6MH0_s_HcC4XNI_-WEkLqUpoDK5ID7vag][] <table> <tbody> <tr> <td> <div> <a title="This answer is useful" rel="nofollow"> up vote</a> <span>0</span> <a title="This answer is not useful" rel="nofollow">down vote</a> </div> </td> <td> <div> <p>it is compiling just fine for me. I am on visual-studio-2013. </p> <p>here you have a case similar to yours, maybe it will help: <a href="http://stackoverflow.com/questions/1102123/debug-assertion-failed-expression-block-type-is-valid" rel="nofollow"> debug-assertion-failed</a></p> </div> <table> <tbody> <tr> <td> <div> <a title="short permalink to this answer" href="http://stackoverflow.com/a/34761457" rel="nofollow">share</a> <span>|</span> <a title="" href="http://stackoverflow.com/posts/34761457/edit" rel="nofollow">improve this answer</a> </div> </td> <td align="right"> <div> <div> <a title="show all edits to this post" href="http://stackoverflow.com/posts/34761457/revisions" rel="nofollow">edited<span title="2016-01-13 08:53:49Z">Jan 13 '16 at 8:53</span></a> </div> <div></div> <div> <div></div> </div> </div> </td> <td align="right"> <div> <div> answered <span title="2016-01-13 08:15:29Z"> Jan 13 '16 at 8:15</span> </div> <div> <a href="http://stackoverflow.com/users/4465567/dominik" rel="nofollow"></a> <div> <img width="32" height="32" alt=""> </div> </div> <div> <a href="http://stackoverflow.com/users/4465567/dominik" rel="nofollow">Dominik</a> <div> <span title="reputation score ">176</span> <span title="1 gold badge"><span></span><span>1</span></span> <span title="1 silver badge"><span></span><span>1</span></span> <span title="11 bronze badges"><span></span><span>11</span></span> </div> </div> </div> </td> </tr> </tbody> </table> </td> </tr> <tr> <td> </td> <td> <div> <table> <tbody> <tr> <td> <table> <tbody> <tr> <td></td> <td> </td> </tr> </tbody> </table> </td> <td> <div style="display:block"> <span>thanks dude, how could i forget about it?</span> – <a title="176 reputation" href="http://stackoverflow.com/users/4465567/dominik" rel="nofollow">Dominik</a> <span><span title="2016-01-13 08:35:47Z">Jan 13 '16 at 8:35</span></span> </div> </td> </tr> <tr> <td> <table> <tbody> <tr> <td></td> <td> </td> </tr> </tbody> </table> </td> <td> <div style="display:block"> <span>true, it was wrong hypothesis then : )</span> – <a title="176 reputation" href="http://stackoverflow.com/users/4465567/dominik" rel="nofollow">Dominik</a> <span><span title="2016-01-13 08:54:37Z">Jan 13 '16 at 8:54</span></span> </div> </td> </tr> </tbody> </table> </div> <div> <a title="Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”." rel="nofollow">add a comment</a> <span> | </span> </div> </td> </tr> </tbody> </table> [Debug Assertion Failed OpenCv is_block_type_valid_header-_block_use]: http://stackoverflow.com/questions/34760254/debug-assertion-failed-opencv-is-block-type-validheader-block-use [Ask Question]: http://stackoverflow.com/questions/ask [active]: http://stackoverflow.com/questions/34760254/debug-assertion-failed-opencv-is-block-type-validheader-block-use?answertab=active#tab-top [oldest]: http://stackoverflow.com/questions/34760254/debug-assertion-failed-opencv-is-block-type-validheader-block-use?answertab=oldest#tab-top [votes]: http://stackoverflow.com/questions/34760254/debug-assertion-failed-opencv-is-block-type-validheader-block-use?answertab=votes#tab-top [Link 1]: http://engine.adzerk.net/r?e=eyJhdiI6NDE0LCJhdCI6NCwiYnQiOjAsImNtIjo0NzE0OTMsImNoIjoxMTc4LCJjayI6e30sImNyIjoxNjM4OTkxLCJkaSI6ImM1M2E4NzQ2NWVmOTRkM2ZiNzQyZTUyMWU4YjgyNmQzIiwiZG0iOjEsImZjIjoxOTQzNDQ1LCJmbCI6MjE0MjMxMiwiaXAiOiI0Mi4yMzYuMTU3LjE2NyIsImt3IjoiYysrLG9wZW5jdix2aXN1YWwtc3R1ZGlvLTIwMTUsdmlzdWFsLXN0dWRpby1kZWJ1Z2dpbmciLCJudyI6MjIsInBjIjowLCJlYyI6MCwicHIiOjE2MDQsInJ0IjoxLCJyZiI6Imh0dHBzOi8vd3d3LmJhaWR1LmNvbS9saW5rP3VybD1KWjVxVEhmME5aMzFPdi1YUmRPSGZ2ZmdKVk1Z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