Help wrapping a opencv c struct

Discussion of Common Lisp
Post Reply
joeish80829
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

Help wrapping a opencv c struct

Post by joeish80829 » Tue Oct 15, 2013 1:23 pm

not sure of the wording on this so pls bear with me

in OpenCV when you want to create an image you do this

IplImage* img=cvCreateImage(cvGetSize(imgHSV),IPL_DEPTH_8U, 1); or you can do this

Code: Select all

img=cvCreateImage(cvGetSize(imgHSV),IPL_DEPTH_8U, 1);
if you've already called the below first

Code: Select all

IplImage* img;
my question is...since i already wrapped cvCreateImage

with this successfully

Code: Select all

;; IplImage* cvCreateImage(CvSize size, int depth, int channels)
(cffi:defcfun ("cvCreateImage" %create-image) (:pointer (:struct ipl-image))
  (size :int64)
  (depth :int)
  (channels :int))

(defun create-image (size depth channels)
  "Create an image with dimensions given by SIZE, DEPTH bits per
channel, and CHANNELS number of channels."
  (let ((nsize (size->int64 size)))
    (%create-image nsize depth channels)))
and i use it all the time successfully, converting c opencv code into lisp in many programs...and have never once did this

Code: Select all

IplImage* img;
I always call it in a let like this

Code: Select all

(img (create-image sz +ipl-depth-8u+ 3))
but if i wanted to expose this kind of functionality in lisp where i would call i/e

Code: Select all

(ipl-image img)
first before calling

Code: Select all

 (img (create-image sz +ipl-depth-8u+ 3))
how would i do that

I tried writing a glue wrapper in c

Code: Select all

IplImage* IplImage_glue(int img)
{
    return (IplImage *) img;
}
here is my repl history after that was compiled into a .so(ubuntu raring)

Code: Select all

CL-OPENCV> ;; IplImage* IplImage_glue(IplImage* img);
(cffi:defcfun ("IplImage_glue" ipl-image) (:pointer (:struct ipl-image))
  (img (:pointer (:struct ipl-image))))

IPL-IMAGE
CL-OPENCV> (dp img (cffi:null-pointer))
IMG
CL-OPENCV> (ipl-image img)
#.(SB-SYS:INT-SAP #X00000000)
CL-OPENCV>  (cffi:with-foreign-slots ((n-size)
img (:struct ipl-image))
(format t
"n-size = ~a~%"
 n-size))
every thing runs up until the with-foreign-slots then..

Code: Select all

Unhandled memory fault at #x0.
   [Condition of type SB-SYS:MEMORY-FAULT-ERROR]
..i assume because im not accessing a ipl-image struct pointer but maybe i am.....any help is appreciated

Post Reply