Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3442270
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:38:53+00:00 2026-05-18T08:38:53+00:00

Below is some code from a C++ procedure. The original can be found here;

  • 0

Below is some code from a C++ procedure. The original can be found here;
https://code.ros.org/trac/opencv/browser/trunk/opencv/modules/imgproc/src/grabcut.cpp

My perspective is that I am a C# rather than C++ programmer so this code is a bit of a mystery to me even though I ran it through a code converter and it came out unchanged.

My questions are: a). How does ‘coefs’ become an array, and b). how does ‘c’ get populated?

To give a bit more information: ‘coefs’ does not seem to start out as an array and ‘c’ somehow seems to magically get at least 8 items

    // fields in class called MAT:
    // a distance between successive rows in bytes; includes the gap if any 
    size_t step;
    // pointer to the data
    uchar* data;

    // where ptr comes from:
    template<typename _Tp> _Tp* ptr(int y=0);
    template<typename _Tp> inline _Tp* Mat::ptr(int y)
    {
        CV_DbgAssert( (unsigned)y < (unsigned)rows );
        return (_Tp*)(data + step*y);
    }    
    .....

    // original question code:
    static const int componentsCount = 5;
    Mat model;
    float* coefs;
    float* mean;
    float* cov;

    coefs = model.ptr<float>(0);
    mean = coefs + componentsCount;
    cov = mean + 3*componentsCount;

    for( int ci = 0; ci < componentsCount; ci++ )
        if( coefs[ci] > 0 )
            calcInverseCovAndDeterm( ci );

    void GMM::calcInverseCovAndDeterm( int ci )
    {
        if( coefs[ci] > 0 )
        {
            float *c = cov + 9*ci;
            float dtrm =
                covDeterms[ci] = c[0]*(c[4]*c[8]-c[5]*c[7]) - c[1]*(c[3]*c[8]-c[5]*c[6]) + c[2]*(c[3]*c[7]-c[4]*c[6]);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:38:54+00:00Added an answer on May 18, 2026 at 8:38 am

    When you declare an array like this:

    int my_ints[10];
    

    my_ints is an array. But in C++ my_ints can also be evaluated as a pointer to the first item in the array. So code like this:

    int* the_first_int = my_ints;
    

    …is legal and valid, not to mention very common. You can also use the_first_int as if it were also an array, like this:

    int the_third_int = the_first_int[2];
    

    …which makes it practically seamless to go between C-style arrays and pointers and back again.

    In your code you declare a pointer to a float:

    float* coefs;
    

    (by the way, this should be initialized to NULLL, but that’s another story), and then you set it to some value:

    coefs = model.ptr<float>(0);
    

    I don’t know what model.ptr<float>(0) does, but it probably either allocates an array and returns a pointer to that, or returns a pointer to an array that was already set up.

    Now because the coefs is a pointer to float, you can use it like it were an array, which you do in the loop:

    for( int ci = 0; ci < componentsCount; ci++ )
        if( coefs[ci] > 0 )
    

    That’s why this works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some really funky code. As you can see from the code below
I have a function(please see code below) which reads some data from the web.
im trying to extract some files from a jar-file downloaded using java-webstart. below code
I am trying to get some percentage data from a stored procedure using code
So, I inherited some code (below) from someone else and I'm trying to understand
Note The question below was asked in 2008 about some code from 2003. As
I use the bellow code to load the main menu elements from some CMS,
Below is some code I've written that is effective, but makes too many database
Below is some jQuery code the i wrote to make a simple animation. However
Below is some sample code. The window does not resize (python3.2, on a Mac,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.