Hi,
For a test project, i was creating a CFFI interface to the OpenCV library and my limited knowledge of CFFI has left me wondering how to achieve something.
According to the documentation on the OpenCV wiki, in order to start capturing from a webcam one would call the following function:
CvCapture* cvCreateCameraCapture (int index)
The CvCapture is an opaque structure without public interface, so i simply store the pointer returned by the function.
To end the image capturing, one would release the capture through the function:
void cvReleaseCapture(CvCapture** capture)
int main()
{
...
CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
...
cvReleaseCapture( &capture );
...
}
I've defined the foreign functions as:
(cffi:defcfun ("cvCreateCameraCapture" create-camera-capture) :pointer
(index :int))
(cffi:defcfun ("cvReleaseCapture" %release-capture) :void
(capture :pointer))
Then in my program i call 'create-camera-capture and it works, the webcam lights up and starts capturing. I even managed to simulate the &capture behavior by renaming the previous declaration of release-capture to %release-capture and creating a new definition like:
(defun release-capture (capture*)
(cffi:with-foreign-object (capture** :long)
(setf (cffi:mem-ref capture** :long)
(cffi:pointer-address capture*))
(%release-capture capture**)))
It works but it doesn't feel all that nice, is this the best/correct way of achieving the same as the C code?
Cheers,
Alex Paes