【发布时间】:2015-05-24 10:51:23
【问题描述】:
我对 mex 文件几乎没有经验,如果这是一个微不足道的问题,请原谅我。我编写了一个简单的 cpp 脚本,它使用 opencv 库加载两个图像并显示它们。我正在尝试混合脚本,以便从 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 的同一文件夹中。请帮忙。蒂亚!
【问题讨论】: