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

  • Home
  • SEARCH
  • 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 8022523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:17:11+00:00 2026-06-04T22:17:11+00:00

Basically, I have two points of a player position, and I would like to

  • 0

Basically, I have two points of a player position, and I would like to cluster player positions which are coming from a Vec2f.

I tried this sample of code but it doesn’t work, and it gives an exceptin when calling the kmeans function.

float *pointsdata = new float[10];

    for (std::map< unsigned int, Player >::iterator it = players.begin(); it != players.end(); ++it)
    {
       for (int i =0; i< players.size(); i++)
       {
           pointsdata[i] = it->second.m_Position.x; 
           pointsdata[i+1] = it->second.m_Position.y; 

       }
    }

    //float pointsdata[] = { 1,1, 2,2, 6,6, 5,5, 10,10};
    cv::Mat points(10, 2, CV_32F, *pointsdata);
    cv::Mat labels, centers;

    cv::kmeans(points, 3, labels, cv::TermCriteria(CV_TERMCRIT_EPS, 1000, 0), 1000, cv::KMEANS_RANDOM_CENTERS, centers);


    cout << "labels: " << labels << endl;
    cout << "centers " << centers << endl;
  • 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-06-04T22:17:12+00:00Added an answer on June 4, 2026 at 10:17 pm

    You have the cv::Mat API here. The constructor you’re trying to use is the following, right?

    Mat (int _rows, int _cols, int _type, void *_data, size_t _step=AUTO_STEP)
    constructor for matrix headers pointing to user-allocated data 
    

    So you should probably do the following:

    if(players.size() > 10)
    {
        cout << "ERROR, too many players\n";
        // Do some error handling here
        return;
    }
    
    //float pointsdata[10][2]; // use this if it doesnt need to be dynamic
    /* 2D definition, but we need to create it as a 1D array with room for the 2d
    float **pointsdata = new float*[10];
    for(int i = 0; i < 10; ++i)
    {
        pointsdata[i] = new float[2];
    }
    */
    float *pointsdata = new float[10*2];
    
    for (std::map< unsigned int, Player >::iterator it = players.begin();
         it != players.end();
         ++it)
    {
        for (int i =0; i< players.size() && i < 10; i++)
        {
             pointsdata[i] = it->second.m_Position.x; 
             pointsdata[i + 10*i] = it->second.m_Position.y; 
        }
    }
    
    cv::Mat points(10, 2, CV_32F, pointsdata);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I have two 2D points and there is a line between them. A
If I were to select a row from a table I basically have two
I have basically two questions. How do I locate the default Rprofile which is
I have a list of two-dimensional points and I want to obtain which of
I have an image with two points, aligned something like this: |----------------| | |
I have a simple (mass)-spring system wih two points which are connected with a
Basically I have two three styles for a button: normal, hover and active. Once
Basically I have two controllers using CodeIgniter for a simple blog for a project
I have found many people with simliar issues but no soultions...basically I have two
In my Windows Forms Application, basically I have two DataGridView s. I want to

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.