title: EMGU (openCV) Passing a image back and forth between C# & C++
body: <p>What I am trying to do seems simple in concept. But, I am having a hard time with it (error message at the bottom). I figured out most of it using EMGU documentation and prior questions here. </p>
  
  <p>I have a windows form with an Imagebox control and a button. On button click, I want to load a image (from file) and pass it to a C++ dll that can take the imagefile and pass the same file back to the C# program which can be displayed on the Imagebox control</p>
  
  <p>C#</p>
  
  <pre><code>    private void rbtnLoadImage_Click(object sender, EventArgs e)
      {
          Image&lt;Bgr, Int32&gt; img1 = new Image&lt;Bgr, Int32&gt;("abc_color.jpg");
          IntPtr pnt = CvInvoke.cvCreateImageHeader(new Size(img1.Width, img1.Height), IPL_DEPTH.IPL_DEPTH_32S , img1.NumberOfChannels);
  
          Marshal.StructureToPtr(img1.MIplImage, pnt, false);
          MIplImage mptr = (MIplImage)Marshal.PtrToStructure(testIplImagePass(pnt), typeof(MIplImage));
          Image&lt;Bgr, Int32&gt; img2 = Image&lt;Bgr, Int32&gt;.FromIplImagePtr(mptr.imageData);
          imgbox.Image = img2;
      }
  
      [DllImport("xyz.dll", CallingConvention = CallingConvention.Cdecl)]
      public static extern IntPtr testIplImagePass(IntPtr imagevar);
  </code></pre>
  
  <p>C++</p>
  
  <pre><code>    extern "C" { __declspec(dllexport) IplImage* testIplImagePass(IplImage* imagevar); }
  
      IplImage* testIplImagePass(IplImage* imagevar)
      {
          return imagevar;
      }
  </code></pre>
  
  <p>The error message I got is "An unhandled exception of type 'System.NotImplementedException' occurred in Emgu.CV.dll. Additional information: Loading of 239, 249 channel image is not implemented."</p>
  
  <p>It occurred on the line</p>
  
  <pre><code>    Image&lt;Bgr, Int32&gt; img2 = Image&lt;Bgr, Int32&gt;.FromIplImagePtr(mptr.imageData);
  </code></pre>
  
  <p>What am I doing wrong here? Any advice is appreciated.</p>