Question

I was also wondering about the possibility of wrapping OpenCV's C++ interface in C and then wrapping that in Lisp so I could add all the C++ functionality as well to my cl-opencv wrapper because I would like to make it complete.... Also wondered if I do that, can I use the C++ wrapper with the C wrapper in lisp ....if it is possible if you could show me a quick example program, like an open window and show a picture function, only in c and c++ together ....like using cv::namedWindow instead of cvNamedWindow and all the other parts being c .....here is my attempt the program below runs when i use cv::namedWindow only but fails with

 shape.cpp:37:32: error: invalid initialization of 
 reference of type ‘cv::InputArray {aka const cv::_InputArray&}’
  from expression of type ‘IplImage* {aka _IplImage*}’In file included from 
 /usr/local/include/opencv/highgui.h:48:0,

                   from shape.cpp:4:
 /usr/local/include/opencv2/highgui/highgui.hpp:78:19: error: 
 in passing argument 2 of ‘void cv::imshow(const string&, cv::InputArray)’
 Compilation exited abnormally with code 1 at Thu Sep 26 21:18:00

when i add cv::imshow

  #include <cv.h>
  #include <highgui.h>
  using namespace std;


  int main(){
        CvCapture* capture =0;       

        capture = cvCaptureFromCAM(0);
        if(!capture){
  printf("Capture failure\n");
  return -1;
        }

        IplImage* frame=0;


        cv::namedWindow("Video");



   // cout << "colorModel = " << endl << " " << size << endl << endl;


   while(true){

              frame = cvQueryFrame(capture);           
              if(!frame) break;

              frame=cvCloneImage(frame);




          cv::imshow("Video", frame );


              cvReleaseImage(&frame);

              //Wait 50mS
              int c = cvWaitKey(10);
              //If 'ESC' is pressed, break the loop
              if((char)c==27 ) break;      
        }

        cvDestroyAllWindows() ;
        cvReleaseCapture(&capture);     

        return 0;
  }

I'd like to know if it would be doable...like be 100% sure before i start, that i could at least wrap every c++ function in c and wrap that with lisp..or if u think id run into snags in some places or even impossibilities.....and also would wrapping it twice make it slow? and id the c interface better/worse than the c++..or can i accomlish everything in the c interface that i can in c++

i ask this because in the swig and cffi documentation it says the c++ support is not complete.

oh yeah and i also tried running the above code with all these headers

#include <cv.h>
#include <highgui.h>
#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;

and still get above error

Was it helpful?

Solution

From the OpenCV documentation, InputArray is

a class that can be constructed from Mat, Mat_, Matx, std::vector, std::vector > or std::vector. It can also be constructed from a matrix expression.

You are trying to pass an IplImage where an InputArray is required and this is not allowed. You could use

cvShowImage("Video", frame);

Or convert your IplImage to a Mat and pass that to imshow():

IplImage* frame;
// write to frame
...
// convert to cv::Mat and show the converted image
cv::Mat mat_frame(frame);
cv::imshow("Video", mat_frame)

Even better would be to not use IplImage at all, it is part of the legacy API. Mat is preferred.

cv::VideoCapture capture;
capture.open(0);
cv::Mat frame;
cv::namedWindow("Video");

if (capture.isOpened()) {
   while (true) {
       capture >> frame;
       if (!frame.empty()) {
           cv::imshow("Video", frame);

           int c = cv::waitKey(10);
           if ((char) c == 27) {
               break;
           }
       }
    }
}

In theory you could write wrappers for everything to allow calling from Lisp CFFI, but it is probably not worth the time and pain. I would code the OpenCV part of your application in C++ and then use C/CFFI to call that from Lisp.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top