Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your example doesn't keep a reference to the <em>result image</em> from Image.SmoothBilatral. The input images are rooted in a static array so are fine. </p> <p>An Emgu.CV Image's data array is pinned to a GCHandle inside the actual image, this is no different from the fact that image contains the array and doesn't prevent collection while the GCHandle's pointer is in use by unmanaged code (in the abscence of a managed root to the image).</p> <p>Because the Image.SmoothBilatral method doesn't do anything with its temporary result image other than pass its pointer and return it, I think it gets optimised away to the extent that the result image can be collected while the smooth is processing.</p> <p>Because there's no finalizer for this class, opencv will not get called upon to release it's unmanaged image header (which has a pointer to the managed image data) so opencv still thinks it has a usable image structure.</p> <p>You can fix it by taking a reference to the result of SmoothBilatral and doing something with it (like disposing it).</p> <p>This extension method would also work (i.e. allow it to be called successfuly for benchmarking without the result being used):</p> <pre><code>public static class BilateralExtensionFix { public static Emgu.CV.Image&lt;testchannels, testtype&gt; SmoothBilateral(this Emgu.CV.Image&lt;testchannels, testtype&gt; image, int p1, int p2 , int p3) { var result = image.CopyBlank(); var handle = GCHandle.Alloc(result); Emgu.CV.CvInvoke.cvSmooth(image.Ptr, result.Ptr, Emgu.CV.CvEnum.SMOOTH_TYPE.CV_BILATERAL, p1, p1, p2, p3); handle.Free(); return result; } } </code></pre> <p>I think what EmguCV should be doing is only pinning pointers to pass to opencv while making an interop call.</p> <p>p.s The OpenCv bilateral filter crashes (producing a very similar error to your problem) on any kind of float image passed with zero variation (min() = max()) across all channels. I think because of how it builds it's binned exp() lookup table. </p> <p>This can be reproduced with:</p> <pre><code> // create new blank image var zeroesF1 = new Emgu.CV.Image&lt;Rgb, float&gt;(75, 75); // uncomment next line for failure zeroesF1.Data[0, 0, 0] += 1.2037063600E-035f; zeroesF1.SmoothBilatral(15, 50, 50); </code></pre> <p>This was confusing me as I was actually sometimes getting this error due to a bug in my test code...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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