Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将MATLAB代码转换为C_C#_Matlab_Image Processing_Converter_Image Recognition - Fatal编程技术网

C# 如何将MATLAB代码转换为C

C# 如何将MATLAB代码转换为C,c#,matlab,image-processing,converter,image-recognition,C#,Matlab,Image Processing,Converter,Image Recognition,我有一个MATLAB代码,通过首先将图像转换为灰度图像并将图像分配给一维数组,对图像进行面部识别 我需要把这段代码转换成C 此函数用于读取图像: 函数T=CreateDatabaseTrainDatabasePath %%%%%%%%%%%%%%%%%%%%%%%%文件管理 TrainFiles=dirTrainDatabasePath; 列车号=0; 对于i=1:sizeTrainFiles,1 如果不是strcptranfilesi.name,'.'.'strcptranfilesi.nam

我有一个MATLAB代码,通过首先将图像转换为灰度图像并将图像分配给一维数组,对图像进行面部识别 我需要把这段代码转换成C

此函数用于读取图像: 函数T=CreateDatabaseTrainDatabasePath %%%%%%%%%%%%%%%%%%%%%%%%文件管理 TrainFiles=dirTrainDatabasePath; 列车号=0; 对于i=1:sizeTrainFiles,1 如果不是strcptranfilesi.name,'.'.'strcptranfilesi.name,'.'.'strcptranfilesi.name,'Thumbs.db' 列车号=列车号+1;%培训数据库中所有图像的数量 终止 终止 %%%%%%%%%%%%%%%%%%%%%%%%由一维图像矢量构造二维矩阵 T=[]; i=1时:列车号 %我选择了数据库中每个图像的名称作为对应的名称 %号码。但是,这不是强制性的! str=int2stri; str=strcat'\',str'.jpg'; str=strcatTrainDatabasePath,str; img=imreadstr; img=rgb2灰度img; [irow icol]=sizeimg; 温度=1;%将二维图像重塑为一维图像向量 T=[T温度];%'每转一圈后,T都会增长 结束你可以

在文件夹c:\temp\example中创建一个MATLAB函数myfunc

在Microsoft®Visual Studio®中,将对C项目的引用添加到 MATLAB COM对象。从“项目”菜单中,选择“添加参考”

在“添加引用”对话框中选择“COM”选项卡

选择MATLAB应用程序

的答案是有帮助的,但在您执行他建议的操作之前,您需要将*.m文件转换为一个DLL,您的C应用程序可以添加对该DLL的引用。首先打开Matlab,然后在命令窗口中键入libraryCompiler:

然后提供详细信息并单击绿色软件包复选框:

请注意,这将创建一个可以从C调用的DLL,它比直接将matlab代码转换为C具有更少的限制请参见

详情如下:


你可以试试.NETBuilderforMatlab,不是吗?如果结果是一个矩阵,如何将结果转换成C矩阵?
function [x,y] = myfunc(a,b,c) 
x = a + b; 
y = sprintf('Hello %s',c);
using System; 
using System.Collections.Generic; 
using System.Text; 

namespace ConsoleApplication2 
{ 
    class Program 
    { 
        static void Main(string[] args) 
        { 
            // Create the MATLAB instance 
            MLApp.MLApp matlab = new MLApp.MLApp(); 

            // Change to the directory where the function is located 
            matlab.Execute(@"cd c:\temp\example"); 

            // Define the output 
            object result = null; 

            // Call the MATLAB function myfunc
            matlab.Feval("myfunc", 2, out result, 3.14, 42.0, "world"); 

            // Display result 
            object[] res = result as object[]; 

            Console.WriteLine(res[0]); 
            Console.WriteLine(res[1]); 
            Console.ReadLine(); 
        } 
    } 
}