<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10pt"><div style="" class=""><span style="" class="">This is important to figure out so I thought I'd include the contents of my C++ interop.cpp file in a gist <a style="" class="" href="https://gist.github.com/W-Net-AI/11319737">https://gist.github.com/W-Net-AI/11319737</a>  and my rect.cpp  <a style="" class="" href="https://gist.github.com/W-Net-AI/11319776">W-Net-AI/gist:11319776</a>  you have my Lisp vector class wrappers so here is my Lisp rect  wrappers...the rect is a little involved for the purpose of overloading.</span></div><div style="" class=""><br style="" class=""><span style="" class=""></span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent;
 font-style: normal" class=""><br style="" class=""><span style="" class=""></span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal" class=""><span style="" class="">;; Rect_()
<br style="" class="">;; Rect* cv_create_Rect() 
<br style="" class="">(defcfun ("cv_create_Rect" rect0) (:pointer mat) 
<br style="" class="">  "RECT constructor.")
<br style="" class=""> <br style="" class=""> <br style="" class="">;; Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height)
<br style="" class="">;; Rect* cv_create_Rect4(int x, int y, int width, int height) 
<br style="" class="">(defcfun ("cv_create_Rect4" rect4) (:pointer rect) 
<br style="" class="">  "RECT constructor."
<br style="" class="">  (x :int)
<br style="" class="">  (y :int)
<br style="" class="">  (width :int)
<br style="" class="">  (height :int))
<br style="" class=""> <br style="" class="">(defun rect (&optional x y width height)
<br style="" class="">       (cond ((eq (or x y) nil)
<br style="" class="">          (rect0))
<br style="" class="">         ((and x y)
<br style="" class="">          (rect4 x y width height))
<br style="" class="">         (t nil)))</span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal" class=""><span style="" class=""><br style="" class=""></span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal" class=""><span style="" class="">this is the rect-x i have been using:</span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal" class=""><span style="" class=""><br></span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica
 Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal" class=""><span style="" class="">;; _Tp x, y, width, height
<br style="" class="">;; int cv_Rect_getX(Rect* self) 
<br style="" class="">(defcfun ("cv_Rect_getX" rect-x) :int
<br style="" class="">  (self (:pointer rect))) </span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal" class=""><br><span style="" class=""></span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal" class=""><br><span style="" class=""></span></div><div style="color: rgb(0, 0, 0); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal" class=""><span style="" class=""><br style="" class=""></span></div><div style="width:450px; font-family: 'Georgia', 'Times', 'Times New Roman', 'serif'" id="enhancrCard_1" class="" contenteditable="false"><table class=""
 style="width:450px; height:170px; display: block" cellpadding="0" cellspacing="0"><tbody style="" class=""><tr style="" class=""><td colspan="6" class="" style="height: 1px; background-color: #e5e5e5"><div class="" style="height: 1px; background-color: #e5e5e5"></div></td></tr><tr style="" class=""><td rowspan="2" class="" style="width: 1px; background-color: #e5e5e5"><div class="" style="width: 1px; background-color: #e5e5e5"></div></td><td class="" rowspan="2" style="vertical-align: middle; width: 168px; height: 168px; background-color: #000000"><div class="" style="width: 168px" align="center"><a href="https://gist.github.com/W-Net-AI/11319776" class="" style="text-decoration: none !important; color: #000000 !important"><img alt="image" src="https://avatars2.githubusercontent.com/u/4182421?s=140" class="" style="display: block; margin: auto" height="168" width="168"></a></div></td><td rowspan="2" class="" style="width: 1px; background-color:
 #e5e5e5"><div class="" style="width: 1px; background-color: #e5e5e5"></div></td><td class="" colspan="2" style="width: 100%; vertical-align: middle; font-family: 'Georgia', 'Times', 'Times New Roman', 'serif'"><div class="" style="line-height:16.5px; background-color: #ffffff; height: 130px; width: 279px"><div class="" style="word-wrap: break-word; padding: 7px 20px 0px 14px"><span style="" class=""></span><span style="" class=""></span><a href="https://gist.github.com/W-Net-AI/11319776" class="" style="text-decoration: none !important; color: #000000 !important"><span class="" style="margin: 0; font-weight: normal; font-size: 18px; line-height: 21px; max-height: 43px; color: #000000; overflow: hidden !important; display: inline-block">W-Net-AI/gist:11319776</span></a><div style="font-size: 13px; line-height: 20px; color: #999999; max-height: 81px; font-family: 'Georgia', 'Times', 'Times New Roman', 'serif';overflow: hidden" class="">- Gist is a simple
 way to share snippets of text and code with others.</div></div></div></td><td class="" rowspan="2" style="width: 1px; background-color: #e5e5e5"><div class="" style="width: 1px; background-color: #e5e5e5"></div></td></tr><tr style="" class=""><td class="" style="width: 100%; vertical-align: middle; font-family: 'Arial', 'Helvetica Neue', 'Helvetica', 'sans-serif'"><div class="" style="font-size: 0pt; padding: 7px 20px 9px 15px"><a href="https://gist.github.com/W-Net-AI/11319776" class="" style="color: black; text-decoration: none !important;cursor:pointer !important" target="_blank"><span class="" style="display: inline-block; line-height: 11px; max-width: 179px; min-width: 119px; overflow: hidden; max-height: 13px; word-break: break-all"><span class="" style="vertical-align:middle; font-size: 9px; line-height: 11px; color: #999999; -moz-text-size-adjust: none; -ms-text-size-adjust: none; -webkit-text-size-adjust:none; text-size-adjust:none">View on
 <span style="font-weight: bold" class="">gist.github.com</span></span></span></a></div></td><td class="" style="vertical-align: middle; width: 100px; font-family: 'Arial', 'Helvetica Neue', 'Helvetica', 'sans-serif'"><div class="" style="padding: 9px 20px 12px 0px; max-width: 100px; min-width: 80px; overflow: hidden; text-align: right; line-height: 11px; max-height: 13px; font-size: 0pt"><span class="" style="vertical-align:middle; font-size: 9px; line-height: 11px; color: #999999; -moz-text-size-adjust: none; -ms-text-size-adjust: none; -webkit-text-size-adjust:none; text-size-adjust:none">Preview by Yahoo</span></div></td></tr><tr style="" class=""><td class="" colspan="6" style="height: 1px; background-color: #e5e5e5"><div class="" style="height: 1px; background-color: #e5e5e5"></div></td></tr></tbody></table></div><div style="" class="">  </div><div style="display: block;" class="yahoo_quoted"> <div class="" style="font-family: HelveticaNeue,
 Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 10pt"> <div class="" style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 12pt"> <div style="" class="" dir="ltr"> <font style="" class="" face="Arial" size="2"> On Saturday, April 26, 2014 6:06 AM, Willem Rein Oudshoorn <woudshoo@xs4all.nl> wrote:<br style="" class=""> </font> </div> <blockquote class="" style="">  <div style="" class="">Joeish W <<a style="" class="" ymailto="mailto:joeish80829@yahoo.com" href="mailto:joeish80829@yahoo.com">joeish80829@yahoo.com</a>> writes:<br style="" class=""><br style="" class="">> Thank you very much for all the help recently,   actually the Rect is<br style="" class="">> a OpenCv C class here:<br style="" class="">> <a style="" class="" href="http://docs.opencv.org/trunk/modules/core/doc/basic_structures.html?highlight=rect#Rect_...does"
 target="_blank">http://docs.opencv.org/trunk/modules/core/doc/basic_structures.html?highlight=rect#Rect_...does</a><br style="" class="">> your advice on making a defcstruct for it stand..<br style="" class=""><br style="" class="">Hm, maybe not.  But I do not know exactly what you need to do.<br style="" class=""><br style="" class="">> Remember, the same<br style="" class="">> code works evaluating the same way at the REPL creating a<br style="" class="">> vector<Rectt> like this:<br style="" class="">><br style="" class="">><br style="" class="">> Functions:<br style="" class="">><br style="" class="">> ;; template < class T, class Alloc = allocator<T> > class vector<br style="" class="">> ;; vector_##t * carray_to_std_vector##tn( t * a, size_t len )<br style="" class="">> (defcfun ("carray_to_std_vectorr" %c-arr-to-vector-rect) (:pointer vector-rect)<br style="" class="">>   (a
 :pointer)<br style="" class="">>   (len :unsigned-int))<br style="" class=""><br style="" class="">It helps if you include or points to the C-functions<br style="" class="">carray_to_std_vectorr and std_vectorr_to_carray, because now I have to<br style="" class="">guess what they do.<br style="" class=""><br style="" class="">[Some code omitted]<br style="" class=""><br style="" class="">> (%c-arr-to-vector-rect<br style="" class="">>          (foreign-alloc :pointer :initial-contents <br style="" class="">>                 (list (rect 1 2 3 4) <br style="" class="">>                       (rect 5 6 7 8))) 2)<br style="" class="">><br style="" class=""><br style="" class="">I am assuming `rect` is a function which calls a defcfun wrapper to<br style=""
 class="">create a Rect.<br style="" class=""><br style="" class=""><br style="" class="">> VECTOR-RECT-SIZE just gets the size of the vector<br style="" class="">><br style="" class="">><br style="" class="">> (dotimes (ic (%vector-rect-size faces))<br style="" class="">> (setf n (%vector-rect-to-c-array faces))<br style="" class="">> (format t "~a~%" (rect-x (mem-aref n :pointer ic))))<br style="" class="">> ; <br style="" class="">> ; caught WARNING:<br style="" class="">> ;   undefined variable: N<br style="" class="">> ; <br style="" class="">> ; compilation unit finished<br style="" class="">> ;   Undefined variable:<br style="" class="">> ;     N<br style="" class="">> ;   caught 1 WARNING condition<br style="" class="">> 1 <-- both x values<br style="" class="">> 5<br style="" class=""><br style="" class="">Yes, this works. However most likely not
 in the way you think it does.<br style="" class="">I think the following is happening:<br style="" class=""><br style="" class="">1. The call to %c-arr-to-vector-rect gets two arguments:<br style="" class="">   a. A pointer to a block of memory containging two pointers to<br style="" class="">      instances of Rect.<br style="" class=""><br style="" class="">      Argument 1: ---->   [pointer a |  pointer b ]  --> [RECT: 5 6 7 8]<br style="" class="">                            |<br style="" class="">                            v<br style="" class="">                       [RECT: 1 2 3 4]<br style="" class=""><br style="" class="">      Argument 2:  2<br style="" class=""><br style=""
 class="">2. The function `carray_to_std_vectorr` takes these two arguments to do<br style="" class="">   the following:<br style="" class=""><br style="" class="">   a. Create an array of 2 rectangles like this:<br style="" class=""><br style="" class="">          [ [RECT: * * * *] | [RECT: * * * *] ]<br style="" class=""><br style="" class="">   b. Copies the content of Argument 1 into this array:<br style="" class=""><br style="" class="">          [ [RECT: pointer a pointer b * *] | [RECT: * * * *]]<br style="" class=""><br style="" class="">   c. Returns the pointer to a vector wrapping the array constructed above.<br style="" class=""><br style="" class="">Now you can see that the constructed vector<Rect> is garbage.  <br style="" class="">But when you retrieve in lisp the values of this array you assume that<br style="" class="">the array is an array of
 pointers.  And as such it ignores it should be<br style="" class="">RECTs and just sees two pointers, pointer a and pointer b.<br style="" class=""><br style="" class="">Now your `rect-x` expects pointers and therefore it works.<br style="" class=""><br style="" class="">So it does work, but only because both mistakes (when creating the<br style="" class="">vector and when reading the vector) cancel each other out.<br style="" class="">If you use the array of rectangles in the OpenCV API, the OpenCV code<br style="" class="">will see garbage.<br style="" class=""><br style="" class="">(Note I cannot see all the code, because you give snippets without the<br style="" class="">underlying C-code and data structures, so I cannot be absolutely sure<br style="" class="">but I am pretty confident that this is what is going on.)<br style="" class=""><br style="" class="">Wim Oudshoorn.<br style="" class=""><br style="" class=""><br style=""
 class="">_______________________________________________<br style="" class="">Cffi-devel mailing list<br style="" class=""><a style="" class="" ymailto="mailto:Cffi-devel@common-lisp.net" href="mailto:Cffi-devel@common-lisp.net">Cffi-devel@common-lisp.net</a><br style="" class=""><a style="" class="" href="http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel" target="_blank">http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel</a><br style="" class=""><br style="" class=""><br style="" class=""></div> </blockquote>  </div> </div>   </div> </div></body></html>