[Cffi-devel] How do I define a CFFI foreign-type so it can be used in a function that accepts a different foreign type as a parameter

Joeish W joeish80829 at yahoo.com
Tue Apr 29 11:34:42 UTC 2014


I have thes 3 defcfuns, for OpenCV functions (C++) which have been wrapped in C(C and C+++ function definitions have been included), 
the top 2, %brisk and surf0 can both can be used as the (self feature-detector) param in the bottom one, %feat-detect-detect If the output of the top two and the self param of feat-detect-detect are just :pointer, But I need to have all three of their types defined 
similiarly to the ones on the bottom of the page so I can use 
finalizers. All of the finalizers and types for the three are the same, 
just substitute in brisk and surf for feature-detector in the four functions at the bottom of the page and you will know what 
each looks like. Should I just call the types for the output of brisk and surf and the input type offeat-detect-detect by the same name, and make them all use the same 4 function 
type/finalizer combo at the bottom of the page, or is there a better 
way.
;; BRISK::BRISK(int thresh=30, int octaves=3, float patternScale=1.0f);; BRISK* cv_create_BRISK(int thresh, int octaves, float patternScale)(defcfun ("cv_create_BRISK"%brisk)brisk (thresh :int)(octaves :int)(pattern-scale :float));; SURF::SURF();; SURF* cv_create_SURF() (defcfun ("cv_create_SURF"surf0)surf);; void FeatureDetector::detect(const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;; void cv_FeatureDetector_detect3(FeatureDetector* self, Mat* image, vector_KeyPoint* keypoints, Mat* mask)(defcfun ("cv_FeatureDetector_detect3"%feat-detector-detect):void (self feature-detector)(image mat)(keypoints (:pointer vector-keypoint))(mask mat))(define-foreign-type feature-detector ()((garbage-collect :reader garbage-collect :initform nil:initarg :garbage-collect))(:actual-type :pointer)(:simple-parser feature-detector))(defclass cv-feature-detector ()((c-pointer :reader c-pointer :initarg :c-pointer)))(defmethod translate-to-foreign
 ((lisp-value cv-feature-detector)(c-type feature-detector))(c-pointer lisp-value))(defmethod translate-from-foreign (c-pointer (c-type feature-detector))(let((feature-detector (make-instance 'cv-feature-detector:c-pointer c-pointer)))(when (garbage-collect c-type)(tg:finalize feature-detector (lambda()(del-feature-detector c-pointer))))feature-detector))ound matches of keypoints from two images." (%draw-matches img1 keypoints1 img2 keypoints2 matches1to2 outimg match-color single-point-color matches-mask flags))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20140429/d38ce0ae/attachment.html>


More information about the cffi-devel mailing list