error while using mexOpenCV

9 ビュー (過去 30 日間)
Mohamed Abdelkader Zahana
Mohamed Abdelkader Zahana 2016 年 5 月 21 日
コメント済み: JAI PRAKASH 2019 年 1 月 13 日
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.

採用された回答

Mohamed Abdelkader Zahana
Mohamed Abdelkader Zahana 2016 年 5 月 24 日
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 件のコメント
JAI PRAKASH
JAI PRAKASH 2019 年 1 月 13 日
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

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by