Search code examples
opencvc++-cliemgucv

How to create an Emgu::CV::Image with a specific type?


In OpenCV we have access to the CV_XX types which allow you to create a matrix with, for example, CV_32SC1. How do I do this in EmguCV?

The reason for asking is:

I am currently using EmguCV and getting an error where I need to create a specific type of Image and am unable to find those values.

Here is my code:

Emgu::CV::Image<Emgu::CV::Structure::Gray, byte>^ mask = gcnew Emgu::CV::Image<Emgu::CV::Structure::Gray, byte>(gray->Size);
try { CvInvoke::cvDistTransform(255-gray, tmp, CvEnum::DIST_TYPE::CV_DIST_L1, 3, nullptr, mask); }

Which gives the error:

OpenCV: the output array of labels must be 32sC1

So I believe I need to change the byte type to 32sC1, how do I do this?

I am using EmguCV 2.0


Solution

  • From the Working with images page, specifically the section on EmguCV 2.0, it provides the following clarification on image depth:

    Image Depth Image Depth is specified using the second generic parameter Depth. The types of depth supported in Emgu CV 1.4.0.0 include

    • Byte
    • SByte
    • Single (float)
    • Double
    • UInt16
    • Int16
    • Int32 (int)

    I believe this means it does not use the CV_XXX types at all and only the above.

    For my issue i set the type to Int32 and it seemed to stop erroring.