Common lisp 如何定义CFFI外部类型,以便在接受不同外部类型作为参数的函数中使用

Common lisp 如何定义CFFI外部类型,以便在接受不同外部类型作为参数的函数中使用,common-lisp,cffi,Common Lisp,Cffi,我有3个defcfuns,用于封装在C中的OpenCV函数(C++)(包括C和C+++函数定义),前2个、%brisk和surf0都可以用作底部的(自特性检测器)参数,%feat detect。如果前两个的输出和feat detect的self参数仅为:指针,但我需要将它们的所有三个类型定义为与页面底部的类型类似的类型,以便使用终结器。这三个函数的所有终结器和类型都相同,只需在页面底部的四个函数中用brisk和surf替换feature detector,您就会知道每个函数的外观。我是否应该以相

我有3个defcfuns,用于封装在C中的OpenCV函数(C++)(包括C和C+++函数定义),前2个、
%brisk
surf0
都可以用作底部的
(自特性检测器)
参数,
%feat detect
。如果前两个的输出和
feat detect
self
参数仅为:指针,但我需要将它们的所有三个类型定义为与页面底部的类型类似的类型,以便使用终结器。这三个函数的所有终结器和类型都相同,只需在页面底部的四个函数中用
brisk
surf
替换
feature detector
,您就会知道每个函数的外观。我是否应该以相同的名称调用
brisk
surf
的输出类型以及
feat detect detect
的输入类型,并使它们都使用页面底部相同的4函数类型/终结器组合,或者有更好的方法吗

    ;; 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))
;;轻快:轻快(整数阈值=30,整数倍频程=3,浮点模式刻度=1.0f)
;; 轻快*cv_创建_轻快(整数阈值、整数倍频程、浮点模式比例)
(defcfun(“cv_create_BRISK”%BRISK)BRISK
(阈值:int)
(八度音阶:int)
(图案比例:浮动)
;; SURF::SURF()
;; 冲浪*cv_创建_冲浪()
(defcfun(“cv_创建_冲浪”surf0)冲浪)
;; 空洞特征检测器::检测(常数矩阵和图像、向量和关键点、常数矩阵和掩码=矩阵())常数
;; void cv_FeatureDetector_detect3(FeatureDetector*自身、Mat*图像、矢量_关键点*关键点、Mat*遮罩)
(defcfun(“cv_特性检测器检测3”%feat检测器检测):无效
(自特征检测器)
(图像垫)
(关键点(:指针向量关键点))
(面罩垫)
(定义外来类型特征检测器()
((垃圾收集:读卡器垃圾收集:initform nil:initarg)
:垃圾收集)
(:实际类型:指针)
(:简单解析器特征检测器))
(defclass cv特征检测器()
((c-pointer:reader c-pointer:initarg:c-pointer)))
(defmethod转换为外来((lisp值cv特征检测器)(c型特征检测器))
(c指针lisp值)
(从外部翻译的方法(c指针(c型特征检测器))
(let((特征检测器(生成实例的cv特征检测器:c指针c指针)))
(何时(垃圾收集c型)
(tg:最终确定特征检测器(lambda()(del特征检测器c指针)))
特征检测器)
两幅图像中关键点的匹配。”
(%绘制匹配img1关键点1 img2关键点2匹配1TO2输出匹配颜色单点颜色匹配掩码标志))