<commit_before>(require :cffi)

(defpackage :opencv-test
    (:use :common-lisp :cffi))
   
(in-package :opencv-test)


 
(define-foreign-library libcv
  (:unix (:or "libcv.so"))
  (t (error "not implemented")))
(use-foreign-library libcv)

(define-foreign-library libhighgui
  (:unix (:or "libhighgui.so"))
  (t (error "not implemented")))
(use-foreign-library libhighgui)

(defctype cv-capture :pointer)
(defctype ipl-image :pointer)

(defcfun "cvInitSystem" :int
  (argv :int)
  (argc :pointer))

(defcfun "cvCreateCameraCapture" cv-capture (index :int))

(defcfun "cvNamedWindow" :int
  (name :string)
  (flags :int))

(defcfun "cvDestroyWindow" :void
  (name :string))

(defcfun "cvQueryFrame" ipl-image
  (capture cv-capture))

(defcfun "cvShowImage" :void
  (window :string)
  (frame ipl-image))

(defcfun "cvReleaseCapture" :void
  (capture cv-capture))

(defun cam-passthrough (&optional (n 1000))
  (let ((c (cvcreatecameracapture 0))
	(name "test"))
    (if (null-pointer-p c)
	"no cam"
	(progn
	  (cvnamedwindow name 1)
	(dotimes (i n)
	  (cvshowimage name
		       (cvqueryframe c))
	  )
	(cvdestroywindow name)
	(cvreleasecapture (pointer-address c)))))
  )
#|
  CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
  if( !capture ) {
    fprintf( stderr, "ERROR: capture is NULL \n" );
    getchar();
    return -1;
  }

  // Create a window in which the captured images will be presented
  cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );

  // Show the image captured from the camera in the window and repeat
  while( 1 ) {
    // Get one frame
    IplImage* frame = cvQueryFrame( capture );
    if( !frame ) {
      fprintf( stderr, "ERROR: frame is null...\n" );
      getchar();
      break;
    }

    cvShowImage( "mywindow", frame );
    // Do not release the frame!

    //If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
    //remove higher bits using AND operator
    if( (cvWaitKey(10) & 255) == 27 ) break;
  }

  // Release the capture device housekeeping
  cvReleaseCapture( &capture );
  cvDestroyWindow( "mywindow" );
|#
<commit_msg>Copied in bits of highgui.h and figured out how to pass a CvCapture** after reading up on WTF a foo** means exactly.  Still doesn't work, best guess is a problem with creating the CvNamedWindow or CvShowImage<commit_after>(require :cffi)

(defpackage :opencv-test
    (:use :common-lisp :cffi))
   
(in-package :opencv-test)


#| 
(define-foreign-library libcv
  (:unix (:or "libcv.so"))
  (t (error "not implemented")))
(use-foreign-library libcv)
|#

(define-foreign-library libhighgui
  (:unix (:or "libhighgui.so"))
  (t (error "not implemented")))
(use-foreign-library libhighgui)

(defctype cv-capture :pointer)
(defctype ipl-image :pointer)


;; start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*)
;;CVAPI(CvCapture*) cvCreateCameraCapture( int index );
(defcfun "cvCreateCameraCapture" cv-capture (index :int))

;; create window
;;CVAPI(int) cvNamedWindow( const char* name, int flags CV_DEFAULT(CV_WINDOW_AUTOSIZE) );
(defcfun "cvNamedWindow" :int
  (name :string)
  (flags :int))

;; destroy window and all the trackers associated with it
;;CVAPI(void) cvDestroyWindow( const char* name );
(defcfun "cvDestroyWindow" :void
  (name :string))

;; Just a combination of cvGrabFrame and cvRetrieveFrame
;;   !!!DO NOT RELEASE or MODIFY the retrieved frame!!!
;;CVAPI(IplImage*) cvQueryFrame( CvCapture* capture );
(defcfun "cvQueryFrame" :pointer
  (capture cv-capture))

;; display image within window (highgui windows remember their content)
;;CVAPI(void) cvShowImage( const char* name, const CvArr* image );
(defcfun "cvShowImage" :void
  (window :string)
  (frame :pointer))

;; stop capturing/reading and free resources
;;CVAPI(void) cvReleaseCapture( CvCapture** capture );
(defcfun "cvReleaseCapture" :void
  (capture cv-capture))

(defun call-with-window (window-name body-fn)
  (unwind-protect
       (progn (cvnamedwindow window-name 1)
	      (funcall body-fn))
    (cvdestroywindow window-name)))

(defmacro with-window ((window-name) &body body)
  `(call-with-window ,window-name
		     #'(lambda () ,@body)))

(defvar *capture*)

(defun cam-passthrough (&optional (n 10))
  (with-window ("test")
    (setf *capture* (cvcreatecameracapture 0))
    (dotimes (i n)
      (let ((frame (cvqueryframe *capture*)))
	(break "~a" frame)
	(cvshowimage "test" frame )))
    (with-foreign-pointer (cap 1)
      (setf (mem-ref cap :pointer) *capture*)
      (cvreleasecapture cap))))
#|
  CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
  // Create a window in which the captured images will be presented
  cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
  // Show the image captured from the camera in the window and repeat
  while( 1 ) {
    // Get one frame
    IplImage* frame = cvQueryFrame( capture );

    cvShowImage( "mywindow", frame );
    // Do not release the frame!

    //If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
    //remove higher bits using AND operator
    if( (cvWaitKey(10) & 255) == 27 ) break;
  }

  // Release the capture device housekeeping
  cvReleaseCapture( &capture );
  cvDestroyWindow( "mywindow" );
|#

{'fraction_non_alphanumeric': 0.13523405894817955, 'fraction_numerical': 0.008861491042188403, 'mean_word_length': 3.987512007684918, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5234285', 'n_tokens_mistral': 1844, 'n_tokens_neox': 1762, 'n_words': 530}