error while using mexOpenCV

5 vues (au cours des 30 derniers jours)
Mohamed Abdelkader Zahana
Mohamed Abdelkader Zahana le 21 Mai 2016
Commenté : JAI PRAKASH le 13 Jan 2019
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.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
my code is:
#include "opencvmex.hpp"
#define _DO_NOT_EXPORT
#if defined(_DO_NOT_EXPORT)
#define DllExport
#else
#define DllExport __declspec(dllexport)
#endif
unsigned 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.

Réponse acceptée

Mohamed Abdelkader Zahana
Mohamed Abdelkader Zahana le 24 Mai 2016
My problem is solved.
The problem was that the library that contains the
cv::imdecode()
function was not included by default. It has to be manually added in the
'mexOpenCV.m'
file. Namely, by adding 'highgui' to the libs variable.
libs = {'core', 'features2d', 'imgproc', 'ml', 'legacy', 'nonfree', ...
'objdetect', 'photo', 'calib3d', 'video', 'flann', 'contrib','highgui'};
  1 commentaire
JAI PRAKASH
JAI PRAKASH le 13 Jan 2019
Apart of adding 'highgui' keyword, some lib file also need to be added in Matlab?
I am also looking for a mex of imdecode function. Target is first on CPU then on GPU.
Mohamed can you help on this..
Thank you
-Jai

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by