Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 240 lines (185 sloc) 8.364 kB
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
1 ;;;; -*- mode: lisp; indent-tabs: nil -*-
2 ;;;; highgui.lisp
3 ;;;; OpenCV bindings for SBCL
4 ;;;; High-level GUI and Media I/O
640f275 @jbromley Imported local cl-opencv.
jbromley authored
5 (in-package :cl-opencv)
6
7
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
8 ;;; Types and structures
640f275 @jbromley Imported local cl-opencv.
jbromley authored
9
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
10 ;; CvCapture
b42adf4 Removed :use :cffi.
J. Bromley authored
11 (cffi:defctype cv-capture :pointer)
640f275 @jbromley Imported local cl-opencv.
jbromley authored
12
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
13 ;; CvVideoWriter
b42adf4 Removed :use :cffi.
J. Bromley authored
14 (cffi:defctype cv-video-writer :pointer)
640f275 @jbromley Imported local cl-opencv.
jbromley authored
15
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
16
17
18 ;;; User Interface
19
20 ;; Operation flags for cvConvertImage
21 (defanonenum
22 (+cvtimg-flip+ 1)
23 (+cvtimg-swap-rb+ 2))
24
25 ;; cvConvertImage(const CvArr *src, CvArr *dst, int flags)
b42adf4 Removed :use :cffi.
J. Bromley authored
26 (cffi:defcfun ("cvConvertImage" %convert-image) :void
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
27 (src ipl-image)
28 (dest ipl-image)
29 (flags :int))
30
31 (defun convert-image (src dest &optional (flags 0))
32 "Converts SRC to DEST with an optional vertical flip and/or red/blue channel
33 switch as determined by FLAGS."
34 (%convert-image src dest flags))
35
36 ;; TODO int cvCreateTrackbar(const char* trackbarName,
37 ;; const char* windowName, int* value, int count,
38 ;; CvTrackbarCallback onChange)
39
40 ;; void cvDestroyAllWindows(void)
b42adf4 Removed :use :cffi.
J. Bromley authored
41 (cffi:defcfun ("cvDestroyAllWindows" destroy-all-windows) :void
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
42 "Destroy all named windows and free their resources.")
43
44 ;; void cvDestroyWindow(const char* name)
b42adf4 Removed :use :cffi.
J. Bromley authored
45 (cffi:defcfun ("cvDestroyWindow" destroy-window) :void
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
46 "Destroy the named window with name NAME and free its resources."
47 (name :string))
48
49 ;; TODO int cvGetTrackbarPos(const char* trackbarName, const char* windowName)
50
51 ;; TODO int cvInitSystem(int argc, char** argv)
52
53 ;; void cvMoveWindow(const char* name, int x, int y)
b42adf4 Removed :use :cffi.
J. Bromley authored
54 (cffi:defcfun ("cvMoveWindow" move-window) :void
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
55 "Sets the position of the window NAME to X, Y."
56 (name :string)
57 (x :int)
58 (y :int))
59
60 ;; int cvNamedWindow(const char* name, int flags)
640f275 @jbromley Imported local cl-opencv.
jbromley authored
61
62 ;; Window constants for cvNamedWindow.
63 (defanonenum
64 +window-normal+
65 +window-autosize+)
66
b42adf4 Removed :use :cffi.
J. Bromley authored
67 (cffi:defcfun ("cvNamedWindow" %named-window) :int
640f275 @jbromley Imported local cl-opencv.
jbromley authored
68 "Internal helper function for NAMED-WINDOW."
69 (name :string)
70 (flags :int))
71
72 (defun named-window (name &optional (flags +window-autosize+))
73 "Create a window named NAME size according to
74 FLAGS. +WINDOW-AUTOSIZE+ sizes the window according to its
75 contents. Note that current OpenCV only supports +WINDOW-AUTOSIZE+."
76 (%named-window name flags))
77
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
78 ;; void cvResizeWindow(const char* name, int width, int height)¶
b42adf4 Removed :use :cffi.
J. Bromley authored
79 (cffi:defcfun ("cvResizeWindow" resize-window) :void
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
80 "Resize the window with name NAME to WIDTH by HEIGHT."
81 (name :string)
82 (width :int)
83 (height :int))
640f275 @jbromley Imported local cl-opencv.
jbromley authored
84
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
85 ;; TODO void cvSetMouseCallback(const char* windowName,
86 ;; CvMouseCallback onMouse, void* param=NULL)
87
88 ;; TODO void cvSetTrackbarPos(const char* trackbarName,
89 ;; const char* windowName, int pos)
90
91 ;; void cvShowImage(const char* name, const CvArr* image)
b42adf4 Removed :use :cffi.
J. Bromley authored
92 (cffi:defcfun ("cvShowImage" show-image) :void
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
93 "Show the picture IMAGE in the named window NAME."
94 (name :string)
95 (image ipl-image))
96
97 ;; int cvWaitKey(int delay=0)
b42adf4 Removed :use :cffi.
J. Bromley authored
98 (cffi:defcfun ("cvWaitKey" %wait-key) :int
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
99 (delay :int))
100
101 (defun wait-key (&optional (delay 0))
102 "Wait up to DELAY milliseconds for a key press. Return the key press
103 if any. If DELAY is zero, this function doesn't return until a key is
104 pressed."
105 (%wait-key delay))
106
107
108
109
110 ;;; Reading and Writing Images and Video
640f275 @jbromley Imported local cl-opencv.
jbromley authored
111
112 ;; Color mode constants for cvLoadImage.
113 (defanonenum
114 (+load-image-unchanged+ -1)
115 +load-image-grayscale+
116 +load-image-color+
117 +load-image-anydepth+
118 (+load-image-anycolor+ 4))
119
b42adf4 Removed :use :cffi.
J. Bromley authored
120 (cffi:defcfun ("cvLoadImage" %load-image) ipl-image
640f275 @jbromley Imported local cl-opencv.
jbromley authored
121 (filename :string)
122 (is-color :int))
123
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
124 ;; IplImage* cvLoadImage(const char* filename, int iscolor=CV_LOAD_IMAGE_COLOR)
125 (defun load-image (filename &optional (is-color +load-image-color+))
126 "Load the image at path FILENAME using color options IS-COLOR."
127 (%load-image filename is-color))
128
b42adf4 Removed :use :cffi.
J. Bromley authored
129 (cffi:defcfun ("cvLoadImageM" %load-image-m) cv-matrix
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
130 (filename :string)
131 (is-color :int))
640f275 @jbromley Imported local cl-opencv.
jbromley authored
132
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
133 ;; CvMat* cvLoadImageM(const char* filename, int iscolor=CV_LOAD_IMAGE_COLOR)
134 (defun load-image-m (filename &optional (is-color +load-image-color+))
135 "Load the image from FILENAME as a CvMat using IS-COLOR color options."
136 (%load-image-m filename is-color))
640f275 @jbromley Imported local cl-opencv.
jbromley authored
137
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
138 ;; int cvSaveImage(const char* filename, const CvArr* image)
b42adf4 Removed :use :cffi.
J. Bromley authored
139 (cffi:defcfun ("cvSaveImage" save-image) :int
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
140 "Save the image in IMAGE into the file FILENAME."
141 (filename :string)
640f275 @jbromley Imported local cl-opencv.
jbromley authored
142 (image ipl-image))
143
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
144 ;; CvCapture* cvCreateCameraCapture(int index)
b42adf4 Removed :use :cffi.
J. Bromley authored
145 (cffi:defcfun ("cvCreateCameraCapture" create-camera-capture) cv-capture
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
146 "Capture a video stream from the camera with index INDEX."
640f275 @jbromley Imported local cl-opencv.
jbromley authored
147 (index :int))
148
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
149 ;; CvCapture* cvCreateFileCapture(const char* filename)
b42adf4 Removed :use :cffi.
J. Bromley authored
150 (cffi:defcfun ("cvCreateFileCapture" create-file-capture) cv-capture
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
151 "Initializes capturing a video from the file FILENAME."
152 (filename :string))
640f275 @jbromley Imported local cl-opencv.
jbromley authored
153
154 ;; Constants for cvSetCaptureProperty and cvGetCaptureProperty.
155 (defanonenum
156 +cap-prop-pos-msec+ ; video position in milliseconds or capture timestamp
157 +cap-prop-pos-frames+ ; 0-based index of frame to be decoded/captures next
158 +cap-prop-pos-avi-ratio+ ; relative position of video file (0 to 1).
159 +cap-prop-frame-width+ ; width of frames in the video stream
160 +cap-prop-frame-height+ ; height of frames in the video stream
161 +cap-prop-fps+ ; frame rate
162 +cap-prop-fourcc+ ; 4-character code of the codec
163 +cap-prop-frame-count+ ; number of frames in video file
164 +cap-prop-format+ ; format of Mat objects returned by retrieve
165 +cap-prop-mode+ ; backend-specific value indicating capture mode
166 +cap-prop-brightness+ ; brightness of the image (only cameras)
167 +cap-prop-contrast+ ; contrast of the image (only cameras)
168 +cap-prop-saturation+ ; saturation of the image (only cameras)
169 +cap-prop-hue+ ; hue of the image (only cameras)
170 +cap-prop-gain+ ; gain of the image (only cameras)
171 +cap-prop-exposure+ ; exposure of the image (only cameras)
172 +cap-prop-convert-rgb+ ; indicates whether images should be converted to RGB
173 +cap-prop-white-balance+ ; currently unsupported
174 +cap-prop-rectification+); ? (only supported by DC1394 v 2.x backend)
175
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
176 ;; double cvGetCaptureProperty(CvCapture* capture, int property_id)
b42adf4 Removed :use :cffi.
J. Bromley authored
177 (cffi:defcfun ("cvGetCaptureProperty" get-capture-property) :double
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
178 "Retrieves that value of property PROPERTY-ID from the capture
179 stream CAPTURE."
180 (capture cv-capture)
181 (property-id :int))
182
183 ;; int cvGrabFrame(CvCapture* capture)
b42adf4 Removed :use :cffi.
J. Bromley authored
184 (cffi:defcfun ("cvGrabFrame" grab-frame) :int
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
185 "Grabs a frame from the video capture stream CAPTURE. The image is
186 stored internally. Use RETRIEVE-FRAME to retrieve the grabbed frame."
187 (capture cv-capture))
188
189 ;; IplImage* cvQueryFrame(CvCapture* capture)
b42adf4 Removed :use :cffi.
J. Bromley authored
190 (cffi:defcfun ("cvQueryFrame" query-frame) ipl-image
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
191 "Grab a frame from a video capture stream CAPTURE, decompress it and
192 return it."
193 (capture cv-capture))
194
b42adf4 Removed :use :cffi.
J. Bromley authored
195 (cffi:defcfun ("cvReleaseCapture" %release-capture) :void
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
196 (capture-ptr :pointer))
197
198 ;; void cvReleaseCapture(CvCapture** capture)
199 (defun release-capture (capture)
200 "Release the resources use by the capture stream CAPTURE."
b42adf4 Removed :use :cffi.
J. Bromley authored
201 (cffi:with-foreign-object (capture-ptr :pointer)
202 (setf (cffi:mem-ref capture-ptr :pointer) capture)
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
203 (%release-capture capture-ptr)))
204
dbe863c @ryepup added a WITH-CAPTURE function to ensure RELEASE-CAPTURE gets called
authored
205 (defmacro with-capture ((capture-var capture) &body body)
206 "ensures RELEASE-CAPTURE gets called on captures."
207 `(let ((,capture-var ,capture))
208 (unwind-protect
209 (progn ,@body)
210 (release-capture ,capture-var))))
211
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
212 ;; IplImage* cvRetrieveFrame(CvCapture* capture)
b42adf4 Removed :use :cffi.
J. Bromley authored
213 (cffi:defcfun ("cvRetrieveFrame" retrieve-frame) ipl-image
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
214 "Returns a pointer to the last image grabbed from CAPTURE-SRC with
215 GRAB-FRAME."
216 (capture cv-capture))
217
b42adf4 Removed :use :cffi.
J. Bromley authored
218 (cffi:defcfun ("cvSetCaptureProperty" %set-capture-property) :int
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
219 (capture cv-capture)
640f275 @jbromley Imported local cl-opencv.
jbromley authored
220 (property-id :int)
221 (value :double))
222
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
223 ;; int cvSetCaptureProperty(CvCapture* capture, int property_id, double value)
224 (defun set-capture-property (capture property-id value)
640f275 @jbromley Imported local cl-opencv.
jbromley authored
225 "Sets the value of the property PROPERTY-ID of the capture source
c423512 @jbromley Restructured code and added some highgui functions.
jbromley authored
226 CAPTURE to the value VALUE."
227 (%set-capture-property capture property-id (coerce value 'double-float)))
228
229 ;; TODO CV_FOURCC
230
231
232 ;; TODO CvVideoWriter* cvCreateVideoWriter(const char* filename, int fourcc,
233 ;; double fps, CvSize frame_size,
234 ;; int is_color=1)
235
236 ;; TODO void cvReleaseVideoWriter(CvVideoWriter** writer)
237
238 ;; TODO int cvWriteFrame(CvVideoWriter* writer, const IplImage* image)
640f275 @jbromley Imported local cl-opencv.
jbromley authored
239
Something went wrong with that request. Please try again.