<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10pt"><div><span>I do thank you for your input ,,,what you suggested worked great...Now however i got stopped on the very next step...I do like to keep these short so any info you need pls ask and will send asap</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;"><br></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;">here is my code and im attempting to emulate the while loop in the link i posted for the c version of this code</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;">it is the first item in the loop that i could use help with, the <br></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;"><br></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;"><span style="line-height: 22px;"><b><span class="Apple-tab-span" style="white-space: pre;"> </span>result = cvApproxPoly(contours, <span style="color: blue;">sizeof</span>(CvContour), storage, CV_POLY_APPROX_DP, cvContourPerimeter(contours)*0.02, 0);</b></span></div><div style="color: blue; font-size: 13.3333px; font-family: HelveticaNeue,Helvetica
Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal; font-weight: bold;"><br></div><div style="color: blue; font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal; font-weight: bold;">Im getting a "Bad argument (Input array is not a valid matrix) in cvPointSeqFromMat" error and the c code runs fine in emacs so i assume its the conversion. It might however be my CvSeq defcstruct....swig wrapped it but the c CvSeq struct looks different from other c structs(i can post the code if needed) and the accessing of the cv-seq defcstructs foreign-slots is acting differently than in c..<br><span style="line-height: 22px;"></span></div><div style="color: rgb(0, 0, 255); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style:
normal; font-weight: bold;"><span style="line-height: 22px;"><b>im positive i have the function (approx-poly) wrapped right and chris showed me how to cast so i was hoping you could look at my code and see if im doing things right as far as converting the c code i posted to help me debug it..thanks again for all your extremely helpful advice on this matter<br></b></span></div><div style="color: rgb(0, 0, 255); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal; font-weight: bold;"><span style="line-height: 22px;"><b><br></b></span></div><div style="color: rgb(0, 0, 255); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal; font-weight: bold;"><span style="line-height: 22px;"></span><span style="line-height: 22px;"><b>Note:.i use (< n
100) in the while loop because the contour-ptr is always a pointer so (pointerp contour-ptr) causes unreachable code errors... <br></b></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;"><br><span></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;"><span>(defun find-contours-example (&optional (width *default-width*)<br> (height *default-height*))<br> (let* ((window-name-1 "Original IMG - FIND-CONTOURS Example")<br> (window-name-2 "Tracked IMG - FIND-CONTOURS Example")<br> (img (load-image
"/home/w/quicklisp/dists/quicklisp/software/cl-opencv-master/images/FindingContours.png" 1))<br> (img-grayscale (create-image (get-size img) +ipl-depth-8u+ 1))<br> (storage (create-mem-storage 0))<br> (n 0))<br> (named-window window-name-1 +window-normal+)<br> (named-window window-name-2 +window-autosize+)<br> (move-window window-name-1 518 185)<br> (move-window window-name-2 969 185)<br> (cvt-color img img-grayscale +bgr2gray+)<br> (threshold img-grayscale img-grayscale 128 255 +thresh-binary+)<br> (with-foreign-object (contour-ptr '(:pointer (:struct cv-seq)))<br> (with-foreign-object (result-ptr '(:pointer (:struct cv-seq)))<br> (find-contours img-grayscale storage
contour-ptr<br> (size-of cv-contour) +retr-list+ <br> +chain-approx-simple+ (point 0 0))<br> (loop <br> while (< n 100)<br> do ;(setf (mem-ref result-ptr `(:pointer (:struct cv-seq))) (approx-poly contour-ptr (size-of cv-contour) storage +poly-approx-dp+ (* (contour-perimeter contour-ptr) 0.02) 0))<br> (incf n))))<br>(show-image window-name-1 img)<br>(show-image window-name-2 img-grayscale)<br>(loop while (not (= (wait-key 0) 27)))<br>(destroy-all-windows)<br>(release-mem-storage storage)<br>(release-image img)<br>(release-image img-grayscale)))<br><br><br></span></div><div style="display: block;" class="yahoo_quoted"> <br> <br> <div style="font-family: HelveticaNeue, Helvetica
Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 10pt;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 12pt;"> <div dir="ltr"> <font face="Arial" size="2"> On Friday, October 25, 2013 4:16 AM, Martin Simmons <martin@lispworks.com> wrote:<br> </font> </div> <blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; margin-top: 5px; padding-left: 5px;"> <div class="y_msg_container">[ please post back to the list, not private email ]<br clear="none"><br clear="none">It looks like you are confused about the difference in CFFI between a pointer<br clear="none">to a struct and a pointer to a pointer to a struct. Unfortunately, CFFI<br clear="none">pointers are untyped so you don't get errors by doing the wrong thing.<br clear="none"><br clear="none">To call cvFindContours as in the example, you need a pointer to a pointer to a<br clear="none">struct
(&contour in the C code). Whenever you want to translate C code that<br clear="none">uses &variable, you need to allocate a pointer to hold the value and then<br clear="none">dereference it after calling the function.<br clear="none"><br clear="none">E.g. something like this (untested):<br clear="none"><br clear="none">(cffi:with-foreign-object (contour-ptr (:pointer (:struct cv-seq)))<br clear="none"> ;; contour-ptr has foreign type (:pointer (:pointer (:struct cv-seq)))<br clear="none"> (cv-find-contours ... contour-ptr ...)<br clear="none"> (mem-ref contour-ptr '(:pointer (:struct cv-seq))))<br clear="none"><br clear="none">__Martin<br clear="none"><br clear="none"><div class="yqt8359039752" id="yqtfd27305"><br clear="none">>>>>> On Wed, 23 Oct 2013 17:04:07 -0700 (PDT), Joeish W said:<br clear="none">> <br clear="none">> well I'm trying to learn about Sequences in opencv. So this was practice at
making the code at this link <br clear="none">> <br clear="none">> <a shape="rect" href="http://opencv-srf.blogspot.com/2011/09/object-detection-tracking-using-contours.html" target="_blank">http://opencv-srf.blogspot.com/2011/09/object-detection-tracking-using-contours.html</a><br clear="none">> <br clear="none">> under the <br clear="none">> <br clear="none">> Shape Detection & Tracking using Contours <br clear="none">> heading . in that code there is this line CvSeq* contours; since i dont know how to initialize a struct pointer in lisp as it is done there ive been using CvSeq* contours = cvCreateSeq(0, sizeof(CvSeq),sizeof(CvPoint),storage); which also initializes a CvSeq* and works in that example. if you could advise me initializing structs I would be most grateful.....Basically I'm starting off by mastering the CvSeq parts of the code.<br clear="none">> .<br clear="none">> <br clear="none">> <br
clear="none">> <br clear="none">> On Wednesday, October 23, 2013 3:23 AM, Martin Simmons <<a shape="rect" ymailto="mailto:martin@lispworks.com" href="mailto:martin@lispworks.com">martin@lispworks.com</a>> wrote:<br clear="none">> <br clear="none">>>>>> On Tue, 22 Oct 2013 15:48:50 -0700 (PDT), Joeish W said:<br clear="none">> ><br clear="none">> >> <br clear="none">> >> take this for instance <br clear="none">> >> <br clear="none">> >> CvPoint points[2];<br clear="none">> >> <br clear="none">> >> <br clear="none">> >> id like to be able to cast points[2] to the CvPoint struct more info here <a shape="rect" href="http://docs.opencv.org/modules/core/doc/old_basic_structures.html?highlight=cvpoint#CvPoint" target="_blank">http://docs.opencv.org/modules/core/doc/old_basic_structures.html?highlight=cvpoint#CvPoint</a><br clear="none">>
>> <br clear="none">> >> <br clear="none">> >> here is my struct which works for other things<br clear="none">> >> <br clear="none">> >> <br clear="none">> >> <br clear="none">> >> ;; (cffi:foreign-type-size '(:struct cv-point)) = 8 <br clear="none">> >> (cffi:defcstruct cv-point <br clear="none">> >> (x :int) <br clear="none">> >> (y :int)) <br clear="none">> >> <br clear="none">> >> <br clear="none">> >> put in a defparameter you cant just go <br clear="none">> >> <br clear="none">> >> (defparameter points (cffi:foreign-alloc :int :count 2))<br clear="none">> >> <br clear="none">> >> (defparameter a ((:struct cv-point) points))<br clear="none">> >> <br clear="none">> >> <br clear="none">> >> you get an illegal function call error...any help is appreciated<br clear="none">>
><br clear="none">> >Your example is inconsistent -- in C, your points variable is an array of two<br clear="none">> >CvPoints, but in Lisp it is an array of two ints.<br clear="none">> ><br clear="none">> >What are you really trying to do?<br clear="none">> ><br clear="none">> >I suggest you post the C code that you are trying to convert. The opencv doc<br clear="none">> >for CvPoint doesn't use casting or arrays of ints.<br clear="none">> ><br clear="none">> >__Martin<br clear="none">> ><br clear="none">> ><br clear="none">> ><br clear="none">> ><br clear="none">> ><br clear="none">> <br clear="none"><br clear="none"></div><br><br></div> </blockquote> </div> </div> </div> </div></body></html>