I installed the Opencv support package on MATLAB R2015a. I could compile the example files using, e.g.
mexOpenCV matchTemplateOCV.cpp
However, when I try to compile my own *.cpp file, it gives me the following error,
Error using mexOpenCV (line 120)Undefined symbols for architecture x86_64:"cv::imdecode(cv::_InputArray const&, int)", referenced from: _mexFunction in decodeUDPimg.old: symbol(s) not found for architecture x86_64clang: error: linker command failed with exit code 1 (use -v to seeinvocation)
my code is:
#include "opencvmex.hpp"#define _DO_NOT_EXPORT#if defined(_DO_NOT_EXPORT)#define DllExport #else#define DllExport __declspec(dllexport)#endifunsigned char *InputBuffer;int buffLen;using namespace cv;using namespace std;///////////////////////////////////////////////////////////////////////////// Check inputs///////////////////////////////////////////////////////////////////////////void checkInputs(int nrhs, const mxArray *prhs[]){ // Check number of inputs // Expecting 2 inputs: uint8 buffer, and size of buffer if (nrhs != 2) { mexErrMsgTxt("Incorrect number of inputs. Function expects 2 inputs."); } // Check buffer data type if (!mxIsUint8(prhs[0])) { mexErrMsgTxt("Buffer must be UINT8."); } if (prhs[1] == 0) { mexErrMsgTxt("Buffer length should be positive."); } } /////////////////////////////////////////////////////////////////////////// // Main entry point to a MEX function /////////////////////////////////////////////////////////////////////////// void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { // Check inputs to mex function checkInputs(nrhs, prhs); // process image data InputBuffer = (unsigned char *)mxGetData(prhs[0]); buffLen= (int)mxGetScalar(prhs[1]); Mat rawData = Mat(1, buffLen, CV_8UC1, InputBuffer); Mat frame = imdecode(rawData, CV_LOAD_IMAGE_COLOR); if (frame.size().width == 0) { cerr << "decode failure!" << endl; //plhs[0] = mxCreateDoubleScalar(0); //plhs[1] = mxCreateDoubleScalar(1); return; } // Put the data back into the output MATLAB array plhs[0] = ocvMxArrayFromImage_single(frame); return; }
The error appears on
Mat frame = imdecode(rawData, CV_LOAD_IMAGE_COLOR);
If I remove it, the code compiles normally.
Any hints on what could the problem be?
Thanks.
Best Answer