System.Runtime.InteropServices.COMException (0x80040013): Ex

本文关键字:Ex 0x80040013 Runtime InteropServices COMException System | 更新日期: 2023-09-27 18:08:00

我想在asp.net的帮助下使用R编程找到一个图像的熵。我已经下载并安装了statconnDCOM到默认位置。我使用以下程序集

使用STATCONNECTORCLNTLib;

使用StatConnectorCommonLib;

使用STATCONNECTORSRVLib;

我的c#代码是
    static StatConnector rconn;
    static void Main(string[] args)
    {
        try
        {
            //Calculate Statistics in R
            rconn.Init("R");
            rconn.Evaluate("require(indicoio)");
            rconn.Evaluate("require(jpeg)");
            rconn.Evaluate("imgPath<-C:/Users/Sunil/Desktop/apple2.jpg");
            //Read the image into a raster array
            rconn.Evaluate("img<-readJPEG(imgPath, native = FALSE)");
            //convert the array to a data.frame or matrix
            rconn.Evaluate("mystring<-as.data.frame(img)");
            rconn.Evaluate("myfreqs <- mystring / sum(mystring)");
            //vectorize
            rconn.Evaluate("myvec <- as.data.frame(myfreqs)[,2]");
            // H in bit
            double average = (double)rconn.GetSymbol(rconn.Evaluate("-sum(myvec * log2(myvec))"));
            Console.WriteLine("Entropy is: " + average);
            Console.ReadLine();           

        }
        catch(Exception ex)
        {
            Console.WriteLine("Error: " + ex);
            Console.ReadLine();
        }

System.Runtime.InteropServices.COMException (0x80040013): Ex

您的rconn对象没有实例化。在Main函数开头添加:

rconn = new StatConnector();