Tuesday, 1 October 2013

How do i wrap structs that contain struct pointers in CFFI?

How do i wrap structs that contain struct pointers in CFFI?

in the IplImage struct documentation here
http://docs.opencv.org/modules/core/doc/old_basic_structures.html?highlight=iplimage#iplimage
it describes the IplROI* roi slot and it seems to be a pointer to the
IplROI struct defined here in the core types_c.h header file:
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;
but it also describes the IplImage* maskROI slot and in the core types_c.h
file there is no typedef struct for that...
if some one could help me find it i would appreciate it but i did grep the
entire opencv download and found nothing.....Im attempting to wrap the
IplImage struct with lisp and i wrapped it with swig and got this
(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))
i changed it a bit here
(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))
so when i ran the below code in emacs(shown with output) all the slot
values would match the opencv output from the exact same code, which they
do and so i could access the ipl-roi struct with the ipl-image struct
using this line
(roi (:pointer (:struct ipl-roi))) ;;
because my gut tells me its the right way
; 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>
but for the IplImage* maskROI slot there is no struct to wrap so i was
hoping some one could give me a quick lesson on how to wrap structs that
contain struct pointers in CFFI and if i'm right in thinking this line
(roi (:pointer (:struct ipl-roi)))
is the right thing to do and how to use it
I would really apreciate any help on this

No comments:

Post a Comment