1

IplImage结构文档描述了该IplROI* roi插槽,它似乎是指向IplROI struct核心types_c.h头文件中定义的指针:

 typedef struct _IplROI
     {
         int  coi; /* 0 - no COI (all channels are selected)
                    , 1 - 0th channel is selected ...*/
         int  xOffset;
         int  yOffset;
         int  width;
         int  height;
      }IplROI;

但它也描述了IplImage* maskROI插槽,并且在核心types_c.h文件中没有 typedef 结构......

如果有人可以帮助我找到它,我将不胜感激,但我确实 grep 了整个 opencv 下载,但一无所获.....我试图用 lisp 包装 IplImage 结构,我用 swig 包装它并得到了这个

(cffi:defcstruct ipl-image
    (n-size :int)
    (id :int)
    (n-channels :int)
    (alpha-channel :int)
    (depth :int)
    (color-model :pointer) 
    (channel-seq :pointer) 
    (data-order :int)
    (origin :int)
    (align :int)
    (width :int)
    (height :int)
    (roi (:pointer (:struct ipl-roi)))
    (mask-roi :pointer)
    (image-id :pointer)
    (tile-info :pointer)
    (image-size :int)
    (image-data :string)
    (width-step :int)
    (border-mode :pointer)
    (border-const :pointer)
    (image-data-origin :string))

我在这里改变了一点

   (cffi:defcstruct ipl-image
       (n-size :int)
       (id :int)
       (n-channels :int)
       (alpha-channel :int)
       (depth :int)
       (color-model :int) ;;Ignored by OpenCV - was :pointer, 
                              changed to :int so the struct values 
                              would match OpenCV's
       (channel-seq :int) ;;Ignored by OpenCV - was :pointer, 
                              changed to :int so the struct values 
                              would match OpenCV's
       (data-order :int)
       (origin :int)
       (align :int)
       (width :int)
       (height :int)
       (roi (:pointer (:struct ipl-roi))) ;; changed so i could access (:struct ipl-roi)
       (mask-roi :pointer)
       (image-id :pointer)
       (tile-info :pointer)
       (image-size :int)
       (image-data :string)
       (width-step :int)
       (border-mode :pointer)
       (border-const :pointer)
       (image-data-origin :string))

因此,当我在 emacs 中运行以下代码(显示输出)时,所有插槽值都将与来自完全相同代码的 opencv 输出匹配,它们会这样做,因此我可以使用 ipl-image 结构访问 ipl-roi 结构线

(roi (:pointer (:struct ipl-roi))) ;; 

因为我的直觉告诉我这是正确的方式

                        ; SLIME 2012-05-25
CL-OPENCV> (size-of '(:struct ipl-image))
128
CL-OPENCV> (defparameter img-size (make-size :width 640 :height 480))
(defparameter img (create-image img-size +ipl-depth-8u+ 3))

IMG
CL-OPENCV> (cffi:with-foreign-slots ((n-size id n-channels 
                         alpha-channel depth color-model 
                         channel-seq data-order origin  
                         align width height roi 
                         mask-roi image-id tile-info 
                         image-size image-data width-step 
                         border-mode border-const image-data-origin) 

                     img (:struct ipl-image))
         (format t "n-size = ~a~%id = ~a~%n-channels = 
                                ~a~%alpha-channel = ~a~%depth = ~a~%color-model = 
                                ~a~%channel-seq = ~a~%data-order = ~a~%origin = ~
                                a~%align = ~a~%width = ~a~%height = ~a~%roi = ~a~
                                %mask-roi = ~a~%image-id = ~a~%tile-info = ~a~%
                                image-size = ~a~%image-data = ~a~%width-step = 
                                ~a~%border-mode = ~a~%border-const = ~a~%image-
                                data-origin = ~a~%" 
             n-size id n-channels 
             alpha-channel depth color-model 
             channel-seq data-order origin  
             align width height roi 
             mask-rOI image-id tile-info 
             image-size image-data width-step 
             border-mode border-const image-data-origin))
n-size = 144
id = 0
n-channels = 3
alpha-channel = 0
depth = 8
color-model = 4343634
channel-seq = 5392194
data-order = 0
origin = 0
align = 4
width = 640
height = 480
roi = #.(SB-SYS:INT-SAP #X00000000)
mask-roi = #.(SB-SYS:INT-SAP #X00000000)
image-id = #.(SB-SYS:INT-SAP #X00000000)
tile-info = #.(SB-SYS:INT-SAP #X00000000)
image-size = 921600
image-data = 
width-step = 1920
border-mode = #.(SB-SYS:INT-SAP #X00000000)
border-const = #.(SB-SYS:INT-SAP #X00000000)
image-data-origin = NIL
NIL
CL-OPENCV> 

但是对于 IplImage* maskROI 插槽,没有要包装的结构,所以我希望有人能给我一个关于如何包装包含 CFFI 中的结构指针的结构的快速课程,如果我认为这一行是正确的

(roi (:pointer (:struct ipl-roi))) 

是正确的做法以及如何使用它

我真的很感激这方面的任何帮助

编辑

4

1 回答 1

0

天哪,这个问题太长了!

无论如何,cffi 这个领域的官方文档非常糟糕。我建议查看此文件以获取具有不同内容的不同类型结构的大量示例

例如:

(cffi:defcstruct ai-node-anim  ;; this is a definition of a c struct
  (m-node-name (:struct ai-string))
  (m-num-position-keys :unsigned-int)
  (m-position-keys (:pointer (:struct ai-vector-key))) ;; here is a pointer to a struct
  (m-num-rotation-keys :unsigned-int)
  (m-rotation-keys (:pointer (:struct ai-quat-key))) ;; here is a pointer to a struct
  (m-num-scaling-keys :unsigned-int)
  (m-scaling-keys (:pointer (:struct ai-vector-key))) ;; here is a pointer to a struct
  (m-pre-state ai-anim-behaviour)
  (m-post-state ai-anim-behaviour))

希望能帮助到你!

于 2013-10-02T16:14:28.057 回答