logo
down
shadow

What is the equivalent of "getDecisionFunction" from OpenCV in C# "EmguCV"?


What is the equivalent of "getDecisionFunction" from OpenCV in C# "EmguCV"?

Content Index :

What is the equivalent of "getDecisionFunction" from OpenCV in C# "EmguCV"?
Tag : chash , By : Marcos de Carvalho
Date : November 26 2020, 03:04 PM

I hope this helps you . I think there is no explicit function for getDecisionFunction in EmguCV. I didn't even find a direct way to get the required values of rho, alpha and svidx. The only solution I found - thanks to @deon cagadoes - is to rewrite the function using the open source of OpenCV OpenCV SVM. However, I wasn't able to acquire all data directly, so I had to write the values of SVM to a file then getting all what I need from this file.
private void TrainandLoad()
{   
    double rho;
    Mat sv, alpha, svidx;
    SVM svm;
    svm.Train(train_data, Emgu.CV.ML.MlEnum.DataLayoutType.RowSample, labels);
    svm.Save(TRAINED_SVM);
    sv = svm.GetSupportVectors();
    alpha = new Mat();
    svidx = new Mat();
    rho = GetDecisionFunction(0, alpha, svidx);
}

private double GetDecisionFunction(int i, IOutputArray alpha, IOutputArray svidx)
{
    int j, nl, idf, class_count, sv_total, df_size, df_index_size, count;
    string svmType, rem;
    Mat tmp;
    DecisionFunc df;
    int[] sv_count;
    string[] lines;
    DecisionFunc[] dfs;
    int[][] svind;
    double[][] alph;
    lines = File.ReadAllLines(TRAINED_SVM);
    nl = 0;
    svmType = "";
    while (nl < lines.Length)
    {
        if (lines[nl].IndexOf("svmType") != -1)
        {
            svmType = lines[nl].Substring(lines[nl].IndexOf("svmType") + 9);
            nl++;
            break;
        }
        nl++;
    }
    if (svmType == "C_SVC" || svmType == "NU_SVC")
    {
        class_count = 2;
        while (nl < lines.Length)
        {
            if (lines[nl].IndexOf("class_count") != -1)
            {
                class_count = Convert.ToInt32(lines[nl].Substring(lines[nl].IndexOf("class_count") + 13));
                nl++;
                break;
            }
            nl++;
        }
        df_size = class_count * (class_count - 1) / 2;
    }
    else
    {
        if (svmType == "ONE_CLASS")
            class_count = 1;
        else
            class_count = 0;
        df_size = 1;
    }
    sv_total = 1;
    while (nl < lines.Length)
    {
        if (lines[nl].IndexOf("sv_total") != -1)
        {
            sv_total = Convert.ToInt32(lines[nl].Substring(lines[nl].IndexOf("sv_total") + 10));
            nl++;
            break;
        }
        nl++;
    }
    Debug.Assert(i <= 0 && i < df_size);
    while (nl < lines.Length)
    {
        if (lines[nl].IndexOf("decision_functions") != -1)
        {
            nl++;
            break;
        }
        nl++;
    }
    sv_count = new int[df_size];
    dfs = new DecisionFunc[df_size];
    svind = new int[df_size][];
    alph = new double[df_size][];
    idf = dfs[0].ofs = df_index_size = 0;
    while (nl < lines.Length && idf < df_size)
    {
        if (lines[nl].IndexOf("sv_count") != -1)
            sv_count[idf] = Convert.ToInt32(lines[nl].Substring(lines[nl].IndexOf("sv_count") + 10));
        else if (lines[nl].IndexOf("rho") != -1)
            dfs[idf].rho = Convert.ToDouble(lines[nl].Substring(lines[nl].IndexOf("rho") + 5));
        else if (lines[nl].IndexOf("alpha") != -1)
        {
            alph[idf] = new double[sv_count[idf]];
            rem = lines[nl].Substring(lines[nl].IndexOf("alpha") + 9);
            for (j = 0; j < sv_count[idf]; j++)
            {
                while (rem[0] == ' ')
                    rem = rem.Substring(1);
                alph[idf][j] = Convert.ToDouble(rem.Substring(0, rem.IndexOf(' ')));
                rem = rem.Substring(rem.IndexOf(' '));
            }
            if (idf != 0)
                dfs[idf].ofs = dfs[idf - 1].ofs + sv_count[idf];
            df_index_size += sv_count[idf];
            if (class_count < 2)
                idf++;
        }
        else if (lines[nl].IndexOf("index") != -1)
        {
            svind[idf] = new int[sv_count[idf]];
            rem = lines[nl].Substring(lines[nl].IndexOf("index") + 9);
            for (j = 0; j < sv_count[idf]; j++)
            {
                while (rem[0] == ' ')
                    rem = rem.Substring(1);
                svind[idf][j] = Convert.ToInt32(rem.Substring(0, rem.IndexOf(' ')));
                rem = rem.Substring(rem.IndexOf(' '));
            }
            idf++;
        }
        nl++;
    }
    df = dfs[i];
    //Get SV Count
    count = (i < df_size - 1 ? dfs[i + 1].ofs : df_index_size) - dfs[i].ofs;
    if (class_count < 2)
    {
        svind[0] = new int[sv_total];
        for (j = 0; j < sv_total; j++)
            svind[0][j] = j;
    }
    tmp = new Mat(1, count, DepthType.Cv64F, 1);
    tmp.SetTo<double>(alph[i]);
    tmp.CopyTo(alpha);
    tmp.Dispose();
    tmp = new Mat(1, count, DepthType.Cv32S, 1);
    tmp.SetTo<int>(svind[i]);
    tmp.CopyTo(svidx);
    tmp.Dispose();
    return df.rho;
}

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

C# EmguCV/OpenCV "cvThreshold" abnormal behaviour - no expected threshold result


Tag : chash , By : brij
Date : March 29 2020, 07:55 AM
To fix this issue The reason of an appearing of that gray artifacts on saved images after applying of any kind of a threshold is... *.JPG standard saving format of Image! More precisely, a jpeg compression applied by it. So there was no problem with thresholding itself. Just a spoiled output image. It was confusing strongly though. The right way of saving such images (without artifacts) is, for example: Image.Bitmap.Save(your_path, ImageFormat.Bmp)

{"error":{"message":"Services require JSON-RPC","code":0,"origin":2},&


Tag : javascript , By : FuzzyHornet
Date : March 29 2020, 07:55 AM
wish of those help JSON RPC expects the client to send parameters to the server using an HTTP POST command with the procedure parameters in the post data. When you type a URL into the browser it sends an HTTP GET command, which doesn't send any parameters.
RPC is intended for use by application programs, not directly by end users. See http://json-rpc.org/ for more details about it.

C# EmguCV error "OpenCV: u != 0"


Tag : chash , By : Saurabh
Date : March 29 2020, 07:55 AM
To fix the issue you can do That exception seems to indicate that app is taking too much memory. In my case I just seemed to have too good quality for the pictures. Reducing them to half fixed the problem.

What's the javascript equivalent of $("<option>", { value: "thing1", text: "thing2"


Tag : javascript , By : Randoa
Date : March 29 2020, 07:55 AM
will be helpful for those in need Using JavaScript we can create a helper function that assists us in replicating the functionality of the JQuery method.
let create = (tag, opts = {}) => {
  return Object.assign(document.createElement(tag), opts); 
}
let create = (tag, opts = {}) => {
  return Object.assign(document.createElement(tag), opts); 
}

console.log( 
  create("option", { value: "thing1", textContent: "thing2"})  
);

Laravel: [ErrorException] "continue" targeting switch is equivalent to "break". during "compose


Tag : laravel , By : Bin
Date : October 05 2020, 04:00 PM
fixed the issue. Will look into that further This is a new warning introduced in PHP 7.3.
It means you are not allowed to have a continue statement inside of a switch, you should use break instead.
php -d error_reporting=0 composer.phar
Related Posts Related QUESTIONS :
  • How should I translate from screen space coordinates to image space coordinates in a WinForms PictureBox?
  • Setting Objects to Null/Nothing after use in .NET
  • Converting ARBG to RGB with alpha blending
  • Is it better to create Model classes or stick with generic database utility class?
  • Passing enum type to Converter with integer value
  • Pool of objects with objects that are already on the scene in advance
  • StatusBar text fade-out when binding using Caliburn.Micro
  • Queryfilter on ApplicationUser in OnModelCreating in ApplicationDbContext creates StackOverflowException
  • How to get record form a different table based on a value from first table with linq expression?
  • Show data in Grid from returned model
  • Using Attributes to Override Data Model Conventions
  • Basic OOP console calculator, result Error
  • Compositon and Repository pattern
  • Multiple using statements with if condition
  • How do i increase a number by 1 in every line that contain the number 1
  • Add binding to elements that are created in codebehind
  • How to add a column in an existing AspNetUsers table
  • Order a list of elements with another list of doubles
  • How to setup a NuGet package to copy content files to output build directory?
  • In SignalR Core using ChannelWriter: Do I need to call TryComplete twice if there's an exception?
  • C# GetProcessesByName: issue with colon
  • c# wpf | create complex object with user-defined name to Serialize into JSON
  • How can I get a instance of a generic list with reflection?
  • WPF XAML - Design time and visibility of textbox
  • EF Core and MySql query is too slow
  • Getting Registered App Display Name from an App Id
  • How to get all variables from a string
  • Delete entity with all childs connected
  • Azure Build agent cant´t find class library referance
  • Initialize Nested Dictionaries in c#
  • .Net Core Binding
  • Generic event test method, preventing code duplication
  • How do I keep the ellipses in the center when the screen is resized
  • How to require a property using JsonSchema.NET?
  • C# XDocument Element/Elements returns null
  • Autofac keyed service with IEnumerable relationship type
  • Installing EntityFramework via NuGet manager
  • Always Check if there is Internet Connection Xamarin forms
  • WCF OneWay service slows down when aspNetCompatibilityEnabled is set to false
  • Can we use JsonRequestBehavior.AllowGet with [HttpPost] attribute?
  • How to customize the Setup wizard with custom forms in Visual Studio setup project
  • C# ASP.NET - Use method from another class to create labels
  • C# List IList or IEnumerable as argument
  • Parsing File with C# And Replace method
  • Losing special unicode characters in encryption (C#)
  • Getting stored procedure returned value instead of row affected
  • How can I construct HTML using NameValuePair in android?
  • Loading a pop up page in ASP.net through a js file
  • How to pass alert or notification message from controller to View?
  • C# to pause, turn on ssas server, backup cube.... how to?
  • How to execute DataTable.Select() for a column of custom class type for a particular element in that C#
  • how to connect mysql8.0 with C#
  • Passing incorrect values into MultiValueConverter by MultiBinding
  • Can i use IEnumerator as Update func?
  • How to convert API Json response to C# Array?
  • Blazor Textfield Oninput User Typing Delay
  • Performing both layout and render transform results in wrong output
  • uwp beforetextchanged cursor moving in front of text
  • How to keep duplicates from a string[] exclude words from a List and print them out
  • .Net Core Strings.Asc/Mid/Chr/Len missing even after importing Microsoft.VisualBasic
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com