Converting a std::vector<float> to mxArray using ocvMxArrayFromVector
10 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (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) );
}
xingxingcui
2019 年 3 月 27 日
編集済み: xingxingcui
2019 年 3 月 27 日
preference here, perhas helps
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!