I'm trying to use some openCV Ml functions in c#, but i dont want to use the emugcv because my teachers wont let me, so i'm trying to marshall this two lines of code using p/invoke. (oh and should i use the normal dll or the d.dll ?? ) and should i use calling conventions??
CVAPI(CvMat*) cvCreateMat( int rows, int cols, int type );//header def
CvMat * rowtest = cvCreateMat(1,5,CV_32FC1);
for this one i have
[DllImportAttribute("opencv_ml242.dll.dll", EntryPoint="cvCreateMat")]
public static extern IntPtr cvCreateMat(int dims, const ref int sizes, int type);
#define CV_MAT_ELEM( mat, elemtype, row, col ) \
(*(elemtype*)CV_MAT_ELEM_PTR_FAST( mat, row, col, sizeof(elemtype)))
#define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size ) \
(assert( (unsigned)(row) < (unsigned)(mat).rows && \
(unsigned)(col) < (unsigned)(mat).cols ), \
(mat).data.ptr + (size_t)(mat).step*(row) + (pix_size)*(col))
Im having trouble doing the this line (header above), can anyone help me pls? Thank you!
CV_MAT_ELEM(*rowtest,float,0,0)
edit: i found something for cv_mat_elem
public static void CV_MAT_ELEM(ref Image<Gray, float> mat, Type elemtype, int row, int col, float val)
{
MCvMat cvMat = new MCvMat();
cvMat.data = mat;
CV_MAT_ELEM_PTR_FAST(ref cvMat, row, col, sizeof(float), val);
public static void CV_MAT_ELEM_PTR_FAST(ref MCvMat mat, int row, int col, int pix_size, float val)
{
unsafe
{
int sz = sizeof(float);
if (row < mat.rows)
{
if (col < mat.cols)
{
IntPtr x = new IntPtr(&mat.data + sz * mat.step * row + sz * col);
}
}
} }
EDIT: solved using a DLL with my opencv functions, just hope i dont lose performance.