Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How do I wrap the OpenCV InputArray class method getMat in C?

Here is my attempt:

my .cpp

#include "opencv_generated.hpp"
using namespace cv;
using namespace std;
using namespace flann;
using namespace cvflann;
extern "C" {

Mat* cv_InputArray_getMat(Mat* self) {
    return new Mat(self->getMat);
}
}

my .hpp

#include <opencv2/opencv.hpp>
#include <vector>
#ifndef __OPENCV_GENERATED_HPP
#define __OPENCV_GENERATED_HPP
using namespace cv;
using namespace std;
using namespace flann;
using namespace cvflann;
extern "C" {
Mat* cv_InputArray_getMat(Mat* self);

}

I compile it with this

 g++ -Wall -shared -fPIC -o libcl-opencv-glue.so cl-opencv-glue.cpp

I get this error:

root@w-VirtualBox:/home/w/opencv-master/glue# 
g++ -Wall -shared -fPIC -o libopencv-glue.so opencv-glue.cpp
opencv-glue.cpp: In function ‘cv::Mat* cv_InputArray_getMat(cv::Mat*)’:
opencv-glue.cpp:9:30: error: ‘class cv::Mat’ has no member named ‘getMat’
         return new Mat(self->getMat);
                              ^
opencv-glue.cpp:10:5: warning: control reaches end of non-void function 
[-Wreturn-type]
     }
     ^

Normally when i wrap c++ opencv functions in c i use a opaque Mat* pointer to stand in for the InputArray function parameters im wrapping. I tried substituting a opaque InputArray* pointer for the Mat* in every different combination but got longer error message list the more InputArray* substitutions I made.....Any advice is much valued

Thank you.