On , Joeish W <joeish80829@yahoo.com> wrote:

I got the callback working somewhat to illustrate here is my code so far below and again im attempting to convert the lowest function on this page: http://opencv-srf.blogspot.com/2011/11/track-bars.html

(defcallback a :void  ((contrast :int) (img cv-arr) (dest cv-arr))
 (format t "img-1: ~a~%~%" img)
(format t "dest-1: ~a~%~%" dest)
(format t "Trackbar level-1: ~a~%~%" contrast))



(defun create-trackbar-example (&optional (camera-index *camera-index*) (width *default-width*)
                (height *default-height*))
  "Creates a trackbar and attaches it to the specified window.
   Move the slider to adjust the brightess of the camera output"
  (with-capture (capture (create-camera-capture camera-index))
    (let ((window-name "CREATE-TRACKBAR Example")
      (contrast (foreign-alloc :int :initial-contents '(10)))
      (dest (create-image (size width height) +ipl-depth-8u+ 3)))
      (set-capture-property capture +cap-prop-frame-width+ width)
      (set-capture-property capture +cap-prop-frame-height+ height)
      (named-window window-name)
      (move-window window-name 600 175)
      (do* ((img (query-frame capture) (query-frame capture))
            (img (clone-image img))
            (scale 0)
            (n 0))
       ((plusp (wait-key *millis-per-frame*)) nil)
    (create-trackbar "Contrast" window-name contrast 21 (callback a))
    (format t "img-2: ~a~%~%" img)
    (format t "dest-2: ~a~%~%" dest)
    (format t "Trackbar level-2: ~a~%~%" (mem-ref contrast :int))
    (show-image window-name img))
      (release-image dest)
      (destroy-window window-name))))


im testing the callback function and it works, it is called when the trackbar is moved, i know this  because the Trackbar level-2 format output from the callback function prints which it should and the output  of the contrast variable in that format function also changes.....the contrast variable is changed in the create-trackbar-example function and the callback function picks up that variable with the (contrast :int) parameter...  my new question is how do i get the callback function to pick up the img and dest variables from the create-trackbar-example function....when the code runs the output of the format t functions from the call back with the img and dest variables in them are different from the output of the format t functions from the create-trackbar-example  with the img and dest in them which means the callback isnt picking those up but it is picking up the variable contrast...and oddly enough i dont have to mem-ref the contrast variable in the callback function....when i just evaluate the variable contrast it prints a number....I think the parameters of the callback are defined righ,t the img and dest are defined as cv-arr (a defctype :pointer) in my library
...any help is appreciated
On Sunday, October 27, 2013 12:03 AM, "f9cef2aa@yandex.ru" <f9cef2aa@yandex.ru> wrote:
>here is my attempt but i have no idea how to define a function as a pointer and ive tried alot of  variations but is too long to post.  The defun change contrast compiles btw...i tried using make-pointer to make the change-contrast function a pointer but make-pointer wants it to be a real...so cant use foreign-alloc i dont think because the function needs to be converted to a pointer first to use that...any guidance is appreciated
>
>(defun change-contrast (&optional contrast img dest)
>(if (< contrast 10) (scale img dest (/ 1 (coerce (- 11 contrast) 'double-float)))
>    (if (>= contrast 10) (scale img dest (- contrast 9))))
>     (show-image "MyImage" dest))
>
>(defun display (filename)
>  "Open the image FILENAME and show it in a window."
>  (let* ((img (load-image filename 1))
>        (img-size (get-size img))
>       (dest (create-image img-size +ipl-depth-8u+ 3))
>       (contrast (cffi:foreign-alloc :int :initial-contents '(10))
>      (test "not sure what to do here")))
>    (named-window "MyWindow" 1)
>   (create-trackbar "conrast" "MyWindow" contrast 21 test)
> (princ (mem-ref contrast :int))
>  (change-contrast (mem-ref contrast :int) img dest)
>    (loop while (not (= (wait-key 0) 27)))
>    (release-image img)
>    (release-image dest)
>    (destroy-window "MyWindow")))


Have you read defcallback documentation? If no, read it and try to use
defcallback. If yes, what was your problem when using defcallback?