According to the Emgu specification , these parameters mean:
/// <param name="type">Mat element type /// <param name="channels">Number of channels /// <param name="data"> /// Pointer to the user data. Matrix constructors that take data and step parameters do not /// allocate matrix data. Instead, they just initialize the matrix header that points to the /// specified data, which means that no data is copied. This operation is very efficient and /// can be used to process external data using OpenCV functions. The external data is not /// automatically deallocated, so you should take care of it. /// <param name="step"> /// Number of bytes each matrix row occupies. /// The value should include the padding bytes at the end of each row, if any.
type is of type CvEnum.DepthType , which is the image depth, you can go through CvEnum.DepthType.Cv32F , which means 32-bit depth images, other possible values ββare CvEnum.DepthType.Cv{x}{t} , where {x} - any value of the set {8,16,32,64}, and {t} can be S for Single or F for Float .
channels , depends on the type of image, but I think you can use 4 of ARGB.
For the remaining 2 parameters, if you do not need the optimization part, you can simply use this constructor of the Mat class:
public Mat(int rows, int cols, DepthType type, int channels)
If you really want to use the optimized version, then (continued):
data , you can pass Bitmap.GetHbitmap (), which returns IntPtr to user data.
step , for this guy I will give you a reasonable assumption if for each pixel you have 4 channels and each channel is in the range from 0 to 255 (8 bits), 8*4 = 32 , so for each block width you need 32 bit. Assuming this is correct, each line contains 32*width bits, converting it to bytes ((8*4)*width)/8 = 4*width , which is the number of channels multiplied by the image width.
UPDATE
Another way to get data and step is with the BitmapData class, like this (excerpt from the MSDN resource):
Bitmap bmp = new Bitmap(Image.FromStream(httpPostedFileBase.InputStream, true, true));
Did not test this solution, but you can try. My answer was based on Emgu code here . Bitmap IntPtr is here , as well as on this post , which will help me also get a further understanding of this.
I have seen other ways to do this, and if you really don't need to call this full constructor, I would try using this approach, it seems cleaner:
HttpPostedFileBase file
Note
The OpenCV documentation has some great tutorials. Just take a look at the available tutorials for the core module. In particular, this one .