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 6250699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:28:31+00:00 2026-05-24T13:28:31+00:00

I am trying to create a clustered image from data being returned from the

  • 0

I am trying to create a clustered image from data being returned from the kmeans function. I try to pull out the data in a similar fashion from the OpenCV example but that seems to crash on me. After some further research I saw that someone had pulled data out by using the centers, but did nothing with that data so my trail ended there.

I have included a snippet of my code and what I am doing below. Any help would be greatly appreciated.

EDIT
I’ve reverted my code back to it’s original state without any test variables. Still the above error persists. I have also added some debugging information about my image below:

Image information:

  • Dimensions: 2
  • Image data:
  • Size 0: 256
  • Size 1: 256
  • Elemsize 1: 12
  • Elemsize 2: 4

While data is NULL I am still able to view the data if I call cv::imshow on it.

// mImage is a cv::Mat that was created from a 256 x 256 image with the depth of
// CV_32F and 3 channels
// labels is a cv::Mat that was created by converting the image into a 256 x 256
// CV_8UC1 IplImage
kmeans(mImage, 6, labels, termcrit, 3, cv::KMEANS_PP_CENTERS, centers);
float* c = new float[6];
memcpy(c, centers.ptr<float>(0), sizeof(float)*6);

// Block of code that crashes when I do "mImage.at<cv::Point2f>(i)" with the error:
/* OpenCV Error: Assertion failed (dims <= 2 && data && (size.p[0] == 1 || 
       size.p[1] == 1) && (unsigned)i0 < (unsigned)(size.p[0] + size.p[1] - 1) && 
       elemSize() == (((((DataType<_Tp>::type) & ((512 - 1) << 3)) >> 3) + 1) << 
       ((((sizeof(size_t)/ 4+1)*16384|0x3a50) >> ((DataType<_Tp>::type) & 
       ((1 << 3) - 1))*2) & 3))) in unknown function, file 
       c:\opencv-2.3.0\modules\core\include\opencv2\core\mat.hpp, line 583 */

for(int i = 0; i < list.rows; i++)
{
    int clusterIdx = list.at<int>(i);
    cv::Point ipt = mImage.at<cv::Point2f>(i);
    circle( miplImage, ipt, 2, colorTab[clusterIdx], CV_FILLED, CV_AA );
}
  • 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-24T13:28:32+00:00Added an answer on May 24, 2026 at 1:28 pm

    You are getting the assertion error at the call to mRegion.at(). Where is mRegion defined?

    Here’s the equivalent snippet from the kmeans.cpp sample code:

        kmeans(points, clusterCount, labels, 
               TermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 10, 1.0),
               3, KMEANS_PP_CENTERS, centers);
    
        img = Scalar::all(0);
    
        for( i = 0; i < sampleCount; i++ )
        {
            int clusterIdx = labels.at<int>(i);
            Point ipt = points.at<Point2f>(i);
            circle( img, ipt, 2, colorTab[clusterIdx], CV_FILLED, CV_AA );
        }
    

    It uses the same variable points for both the first argument to kmeans and as the source for ipt in the for loop. I think you probably want to use mImage in the for loop, not mRegion.

    Edit So now that you’ve changed the code to use mImage in the for loop, you need to see why you are getting the assertion error. The assertion message is very cluttered by the template code so here it is from mat.hpp:

    dims <= 2 && data && (size.p[0] == 1 || size.p[1] == 1) &&
                 (unsigned)i0 < (unsigned)(size.p[0] + size.p[1] - 1) &&
                 elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type)
    

    One or more of those tests fails. If you are using an empty mImage, that would be a failure because data would be nil. You can’t call at on an empty matrix. In any case, examine the properties of mImage to see which is causing the assertion error.

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

Sidebar

Related Questions

Trying to create a list to return some JSON data to a view. Following
I'm trying to create a view out of quite a complex select query and
I am having a hard time trying to figure out which data type I
Is it possible to create a clustered index from a create table statement in
I am trying create a WCF service that leverages the WPF MediaPlayer on the
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying create a delegate representation of constructor by emitting a Dynamic Method,
Ok so I am trying create a login script, here I am using PHP5
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation
Trying to create a user account in a test. But getting a Object reference

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.