Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <pre><code> value=cvQueryFrame( capture ); </code></pre> <p>when I change value, lastValue changes too</p> </blockquote> <p>No, it doesn't. The pointer <code>value</code> gets overwritten, as you desire. It is impossible for this line of code to affect <code>lastValue</code>.</p> <blockquote> <p>but because they are pointers, both end up with the same value</p> </blockquote> <p>No, it doesn't matter that they are pointers. Pointers are still objects in and of themselves.</p> <hr> <p><strong>However</strong>, <code>cvQueryFrame</code> returns a pointer to a buffer which <a href="http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/opencv-intro.html" rel="nofollow">you shall not modify or free</a> as this is done for you:</p> <blockquote> <p>Note that the image captured by the device is allocated/released by the capture function. There is no need to release it explicitly. </p> </blockquote> <p>Though <a href="http://opencv.jp/opencv-1.0.0_org/docs/ref/opencvref_highgui.htm" rel="nofollow">the documentation</a> is a little unclear, it seems likely to me that the buffer is only valid until the next call to <code>cvQueryFrame</code> (which will then re-use the allocated memory). So even though <code>lastValue</code> can't and doesn't change, it <em>happens</em> to end up pointing to the new frame anyway.</p> <p>To get around this, you can explicitly copy the object that <code>lastValue</code> points to:</p> <pre><code>lastValue = cvCloneImage(value); </code></pre> <p><em>Now</em> you probably take on responsibility for freeing it (but again it's not entirely clear from my cursory glance at the documentation):</p> <pre><code>cvReleaseImage(&amp;lastValue); </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