我正在尝试使用mexCallMATLAB()
来读取图像。以下是代码:
#include "mex.h"
#include <matrix.h>
#include <string.h>
#include <stdio.h>
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mxChar *string, *img;
int dims[2] = {1, 100};
char *str = "D:\\Acads\\NUS\\CBIS\\TEST\\SampleImages\\set1139R0stack1000Color0St0.tiff.tif"; // Path of the image file
string = mxCreateCharArray(2, (const int *)dims);
memcpy(mxGetPr(string), str, sizeof(char) * (strlen(str) + 1));
mexCallMATLAB(1, img, 1, &string, "imread");
}
该代码编译没有错误,但在执行时会引发以下错误消息:
??? Error using ==> imread at 315
File "%^&*$#@! (Some special character string)" does not exist.
当我打印 variable 的值时string
,我得到了正确的路径,但我不明白调用 MATLAB 函数时发生了什么。