Converting a std::vector<float> to mxArray using ocvMxArrayFromVector
이전 댓글 표시
Hello,
I'm currently working with mex matlab and OpenCV libraries. I'm using the results of the computation of HOG features, which is of type std::vector<float>, and need it as an output of the mex function.
I'm therefore trying to use the ocvMxArrayFromVector function, which is supposed to conver a vector of a given type to the required mxArray data type output.
The part of code I'm using is:
vector<float> descriptorValues(outDim);
hog->compute(croppedImg, descriptorValues, Size(0,0), Size(0,0), locations);
plhs[0] = ocvMxArrayFromVector(descriptorValues);
But when compiling it returns the following error:
Error using mexOpenCV (line 122)
/tmp/mex_1394440023880_2588/HOGDescriptorOCV.o: In function `computeHOGFeatures(int, mxArray_tag**, mxArray_tag
const**)':
HOGDescriptorOCV.cpp:(.text+0xb24): undefined reference to `ocvMxArrayFromVector(std::vector<float,
std::allocator<float> > const&)'
collect2: error: ld returned 1 exit status
I'm compiling using g++ on an Ubuntu, matlab version R2016b.
I would be very thankful for your help.
David
답변 (2개)
James Tursa
2016년 9월 28일
I don't know about the ocvMxArrayFromVector routine, or how to advise you to link everything in properly, but here is a short example that takes a C++ vector of floats and copies it into an mxArray for output:
#include <vector>
using namespace std;
#include <string.h>
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
int i, n=5;
vector<float> descriptorValues(n);
// Load up some sample data
for( i=0; i<n; i++ ) {
descriptorValues[i] = (float) (i + 1);
}
// Pretend we don't know the size and get it dynamically
n = descriptorValues.size();
// Create the output mxArray and copy the data
plhs[0] = mxCreateNumericMatrix( 1, n, mxSINGLE_CLASS, mxREAL );
memcpy( mxGetData(plhs[0]), &descriptorValues[0], n*sizeof(float) );
}
댓글 수: 1
David Moreno
2016년 10월 13일
This solved my problem, thank you :)
xingxingcui
2019년 3월 27일
편집: xingxingcui
2019년 3월 27일
0 개 추천
preference here, perhas helps
카테고리
도움말 센터 및 File Exchange에서 OpenCV Support에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!