mex使用外部头文件时出错

时间:2015-05-24 10:51:24

标签: c++ matlab opencv mex

我对mex文件没什么经验,所以请原谅我这是一个微不足道的问题。我编写了一个简单的cpp脚本,它使用opencv库加载两个图像并显示它们。我试图mex脚本,从matlab使用它。这是我的剧本

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"
#include <map>
#include <math.h>
#include <iostream>

#include <mex.h>
#include "mc_convert.h"

using namespace cv;
using namespace std;

int run(Mat source, Mat target)
{
Mat cimg;

vector<Point> target_samples;
vector<Point> source_samples_chamfered;
vector<Point> source_samples_actual;
// Mat source = imread(argv[1], 0);
// Mat target = imread(argv[2], 0);

double centroid_x_actual, centroid_y_actual;
double centroid_x_chamfered, centroid_y_chamfered;

// Threshold both template and reference image
threshold( target, target, 10, 255, 0 );
cvtColor(target, cimg, COLOR_GRAY2BGR);
threshold( source, source, 10, 255, 0 );

imshow("target", target);
imshow("source", source);

return 0;
}

void mexFunction(int nlhs, mxArray *plhs[], int nrhs,
             const mxArray *prhs[])
{
  CvMat* source = mxArr_to_new_CvMat (prhs[0]);
  CvMat* target = mxArr_to_new_CvMat (prhs[1]);

  run(source, target);

  // plhs[0] = CvMat_to_new_mxArr (psrc);
  cvReleaseMat (&source);
  cvReleaseMat (&target);

}

为了在CvMat和MxArray之间转换类型,我正在使用this链接。当我尝试使用mex编译脚本时,我收到以下错误。

mex -cxx -largeArrayDims -I "./" -I/usr/local/include/opencv2 -I/usr/local/include chamfer.cpp -L/usr/local/lib/  -lopencv_calib3d  -lopencv_contrib  -lopencv_core  -lopencv_features2d  -lopencv_flann  -lopencv_gpu  -lopencv_highgui  -lopencv_imgproc  -lopencv_legacy  -lopencv_ml  -lopencv_nonfree  -lopencv_objdetect  -lopencv_ocl  -lopencv_photo  -lopencv_stitching  -lopencv_superres  -lopencv_ts  -lopencv_video  -lopencv_videostab

chamfer.cpp: In function ‘void mexFunction(int, mxArray**, int, const mxArray**)’:
chamfer.cpp:162:46: error: ‘mxArr_to_new_CvMat’ was not declared in this scope

mex: compile of ' "chamfer.cpp"' failed.

“mxArr_to_new_CvMat”在名为mc_convert.cpp的文件中声明,该文件是类型转换库的一部分。我已将外部库的所有头文件和cpp文件放在包含chamfer.cpp的同一文件夹中。请帮忙。 TIA!

1 个答案:

答案 0 :(得分:0)

mc_convert.h中,mxArr_to_new_CvMat()仅在定义了预处理程序符号(宏)HAS_OPENCV时才会声明。事实上,在&#34; C / C ++ Matlab转换器&#34;中的doc.htm中。下载它说你应该声明这个宏。尝试将-DHAS_OPENCV添加到您的mex命令。