Question

I'm working with the Arjun Comar version of OpenCV 3.0 here https://github.com/arjuncomar/opencv ...Arjun Comar updated this version of OpenCV to auto generate C wrappers for all OpenCV functions so languages without a good c++ FFI could still create wrappers for OpenCV. The C wrapper for C++ is located in the files opencv_generated.cpp (must be built from the Arjun Comar OpenCV version linked above but I pasted my current version here http://www.heypasteit.com/clip/17SI and mat.cpp rect.cpp point.cpp and size.cpp located here https://github.com/arjuncomar/opencv/tree/master/modules/c/src

In that version he uses a Scalar pointer ('Scalar*') to stand in for all the function that require 'cv::Scalar(val1 val2 val3 val4)'. The only thing is he didn't make a create Scalar function or any alternate to create a Scalar*. my attempt is below and its not compiling

cpp

 Scalar* cv_create_Scalar(double val0, double val1, double val2, double val3)
 {
      //also tried cv:;Scalar - same error
     return Scalar(val0, val1, val2, val3);

 }

hpp

'Scalar* cv_create_Scalar(double val0, double val1, double val2, double val3);'

compile with this in cpp directory on Ubuntu Trusty

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

But I'm getting this error

 opencv-glue.cpp: In function ‘cv::Scalar* cv_create_Scalar
 (double, double, double, double)’:
 opencv-glue.cpp:28:41: error: cannot convert 
 ‘cv::Scalar’ to ‘cv::Scalar* {aka cv::Scalar_<double>*}’ in return
      return Scalar(val0, val1, val2, val3);
                                     ^
 opencv-glue.cpp:30:1: warning: control reaches end of 
 non-void function [-Wreturn-type]
  }

I know its not the compile function...its well tested but I need a Scalar* to pass to a function like this I created (which compiled right)

 Mat* cv_create_Mat_S(Size* size, int type, Scalar* s) {
      return new Mat(*size, type, *s);
  }

So I'll have a scalar to pass to the 'absdiff' function c wrapper Arjun Comar created here:

  void cv_absdiff(Mat* src1, Mat* src2, Mat* dst) {
        cv::absdiff(*src1, *src2, *dst);
  }

Any help is MUCH Appreciated=)

Was it helpful?

Solution

Obviously, it can't compile due to conversion, but can't you just create new Scalar dynamically? You're only have to remember that this memory has to be freed by delete.

 Scalar* cv_create_Scalar(double val0, double val1, double val2, double val3)
 {
      //also tried cv:;Scalar - same error
     return new Scalar(val0, val1, val2, val3);
 }

If you want to return a pointer to this object, is has to be done this way. You cannot return new object by creating a copy, you will have to change the method signature.

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