<div dir="ltr"><div><div><div>Joeish,<br><br></div>I am not really in the position to install OpenCV and play with this, but since it looks like your aren't getting many responses, I thought I would respond.  I have a suggestion:<br>


<br>Since you have a working C implementation/example, why don't you see what CFFI is doing and figure out how the C is working differently?  To do this, build a new C library with a single function that takes the same arguments as cvCreatMatND (or whatever) does, have it print out every bit of information about its arguments you think is relevant.  Then call it from Lisp and verify that the same thing data is delivered from the Lisp call as the C version sends to the real cvCreateMatND (it must be different or we are truly lost).  Once you get to this point, you can fiddle with the arguments on the Lisp side and see what the effect is on the C side.  The end result will be you learning something more about how CFFI works, whether it be idiosyncrasy, intricacy, or bug.</div>

</div>
<div><br>Now, I'm not a CFFI developer, but as someone who reads the mailing list and uses CFFI (and done what I describe above several times), I would rather read something like "hey, if I pass an nested structure to a C function this weird thing happens and it isn't what I expected; here is a minimal example." rather than "here is my code; it doesn't work and I have no clue why."  The first helps me understand things I have never encountered (or allows me to quickly see the issue if I have encountered it) as well as opens the discussion of how we can make this simpler/easier, while the other makes me just want to skip the post.<br>


<br></div>Best,<br>Zach KS<br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Oct 9, 2013 at 7:07 AM, Joeish W <span dir="ltr"><<a href="mailto:joeish80829@yahoo.com" target="_blank">joeish80829@yahoo.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif"><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></div></blockquote></div><br></div>