<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt"><div>Here is the opencv code i'm trying to convert to lisp<br><br><br><br>int size[] = { 5, 5, 5 };<br>CvMatND* b = cvCreateMatND(3, size, CV_32F);<br>cvSetZero(b);<br> int a=0;<br>for (int x = 0; x < b->dim[0].size; x++)<br>{<br>    for (int y = 0; y < b->dim[1].size; y++)<br>    {<br>        for (int z = 0; z < b->dim[2].size; z++)<br>        {      a++;<br>      cvSet3D(b, x,y,z, cvScalar(a));<br>        <br>        }<br>    }<br>}<br><br><br><br>in the code above it creates a 3 dimensional matrix and adds data to it in the for loop<br>in the
 loop the code accesses the sizes of each dimension of the 3d matrix with dim[0].size dim[1].size and dim[2].size<br>I'm trying to do the same in lisp....I created wrappers for the structs and the c function below and tried everything i could from nested with-foreign-slots to access the members of dim to mem-reffing and mem-areffing the out put of dims....the most i got was a plist for dim (STEP 100 SIZE 5) when i accessed the cv-mat-nd-dim struct with with-foreign-slots inside a with-foreign-slots for MATRIX i set with this<br><br><br><br>(defparameter matrix (create-mat-nd 3 '(5 5 5 ) +32fc1+))<br><br>but it has only 1 item in it, in c you can access an infinite number because  its an nd matrix<br><br><br><br>(cffi:defcunion cv-mat-nd-data<br>    (ptr :pointer)<br>    (fl :pointer)<br>    (db :pointer)<br>    (i :pointer)<br>    (s
 :pointer))<br><br><br><br><br>(cffi:defcstruct cv-mat-nd-dim<br>    (size :int)<br>    (step :int))<br><br><br><br><br>;; ;(cffi:foreign-type-size '(:struct cv-mat-nd)) = todo - doesn't work cv-mat-nd = 40 opencv's = 288<br>(cffi:defcstruct cv-mat-nd<br>    (type :int)<br>    (dims :int)<br>    (refcount :pointer)<br>    (hdr-refcount :int)<br>    (data (:union cv-mat-nd-data))<br>    (dim (:pointer (:struct cv-mat-nd-dim))))<br><br><br><br><br>;; CvMatND* cvCreateMatND(int dims, const int* sizes, int type)<br>(cffi:defcfun ("cvCreateMatND" %create-mat-nd) (:pointer (:struct cv-mat-nd))<br>  "Creates the header and allocates the data for a multi-dimensional dense array."<br>  (dims :int)<br>  (sizes :pointer)<br>  (type :int))<br><br>(defun create-mat-nd (dims sizes type)<br>  "Return a specific element of
 single-channel nD array."<br>  (%create-mat-nd dims<br>        (cffi:foreign-alloc :int :initial-contents sizes) type))</div></div></body></html>