C++ mex使用外部头文件时出错
我在mex文件方面没有什么经验,所以如果这是一个微不足道的问题,请原谅。我已经编写了一个简单的cpp脚本,它使用opencv库加载两个图像并显示它们。我正在尝试mex脚本,从matlab使用它。这是我的剧本C++ mex使用外部头文件时出错,c++,matlab,opencv,mex,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
#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);
}
“mxArr_to_new_CvMat”在名为mc_convert.cpp的文件中声明,该文件是类型转换库的一部分。我已将外部库的所有头文件和cpp文件放在包含chamfer.cpp的同一文件夹中。请帮忙。蒂亚 在
mc\u convert.h
中,只有在定义了预处理器符号(宏)HAS\u OPENCV
时,才会声明mxArr\u to\u new\u CvMat()
。事实上,在doc.htm的“C/C++Matlab转换器”下载中,它说您应该声明这个宏。尝试将-DHAS\u OPENCV
添加到mex命令。谢谢。我添加了宏,看起来这个错误已经修复了。但现在它无法将mc_convert.h中包含的cxtypes.h归档,从而引发了一个致命错误。我在opencv包含目录中找不到cxtypes.h。
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.