In base alla specifica Emgu quei parametri significa:
/// <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
è del tipo CvEnum.DepthType
, che è la profondità dell'immagine, è possibile passare CvEnum.DepthType.Cv32F
che sta per immagini di profondità a 32 bit , altri possibili valori sono nella forma CvEnum.DepthType.Cv{x}{t}
, dove {x} è qualsiasi valore del set {8,16,32,64} e {t} può essere S
per Single
o F
per Float
.
channels
, dipende dal tipo di immagine ma penso che sia possibile utilizzare 4
da ARGB.
Per gli altri 2 parametri, se non è necessario la parte di ottimizzazione, si può semplicemente utilizzare questo costruttore della classe Mat
:
public Mat(int rows, int cols, DepthType type, int channels)
Se davvero si vuole utilizzare la versione ottimizzata , poi (continua):
data
, è possibile passare il Bitmap.GetHbitmap(), che restituisce un IntPtr ai dati utente.
step
, per questo ragazzo, io ti do un'ipotesi informata, se per ogni pixel si dispone di 4 canali, e ciascun intervallo di canale da 0 a 255 (8 bit), 8*4 = 32
, così per ogni larghezza di unità che si bisogno di 32 bit. Supponendo che sia corretto, ogni riga ha 32*width
bit, convertendolo in byte ((8*4)*width)/8 = 4*width
, che è il numero di canali, moltiplicato per la larghezza dell'immagine.
UPDATE
Altro modo per ottenere il data
e step
è da BitmapData di classe, come questo (estratto dalla risorsa MSDN):
Bitmap bmp = new Bitmap(Image.FromStream(httpPostedFileBase.InputStream, true, true));
// Lock the bitmap's bits.
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
System.Drawing.Imaging.BitmapData bmpData =
bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
bmp.PixelFormat);
// data = scan0 is a pointer to our memory block.
IntPtr data = bmpData.Scan0;
// step = stride = amount of bytes for a single line of the image
int step = bmpData.Stride;
// So you can try to get you Mat instance like this:
Mat mat = new Mat(bmp.Height, bmp.Width, CvEnum.DepthType.Cv32F, 4, data, step);
// Unlock the bits.
bmp.UnlockBits(bmpData);
non ho ancora testato questa soluzione, ma puoi provarlo. La mia risposta è stata basata sul codice Emguhere., Bitmap IntPtrhere e anche su questo post che mi aiuti acquisire anche una maggiore comprensione su questo.
ho visto altri modi per farlo anche, e se non si ha realmente bisogno di chiamare quel costruttore completo, vorrei provare questo approccio, sembra più pulito:
HttpPostedFileBase file //your file must be available is this context.
if (file.ContentLength > 0)
{
string filename = Path.GetFileName(file.FileName);
// your so wanted Mat!
Mat img = imread(filename, CV_LOAD_IMAGE_COLOR);
}
NOTA
Ci sono ottimi tutorial nel OpenCV documentation. Basta dare un'occhiata alle esercitazioni disponibili per il modulo principale. In particolare, questo one.
Hai fatto? O stai ancora provando? Hai bisogno di più aiuto su questo? –