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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:14:24+00:00 2026-05-29T17:14:24+00:00

I am creating an array of double values,I want to add the created array

  • 0

I am creating an array of double values,I want to add the created array to the CvSeq. I have used cvSeqPush for this purpose.But when I am retrieving this array it only shows the first element of the array and rest is garbage. The code is as follows..

int Ts = 45;
int count = 0;
//Creating a mtrix CL for clusters
CvMat * CL = cvCreateMat(1,newCP->cols,newCP->type);
//Array for storing the clusters
double * arrClust = (double*)malloc(3*sizeof(double));

//Copying 1st row of newCP to arrClust
arrClust[0] = cvmGet(newCP,0,0);
arrClust[1] = cvmGet(newCP,0,1);
arrClust[2] = cvmGet(newCP,0,2);

//array of distances
double * distance = (double*)malloc(1*sizeof(double));

//array of results
double * result = (double*)malloc(1*sizeof(double));

//Creating a seq to store various clusters
CvMemStorage * strgeClust = cvCreateMemStorage(0);
CvSeq * seqClust = cvCreateSeq(0,sizeof(CvSeq),sizeof(double),strgeClust);
CvSeq * s ;
for(int i=2 ; i<newCP->rows ; i++ )
{
    for(int j=0;j<=count;j++)
    {
        double a = arrClust[0] - cvmGet(newCP,i,0); //a = CL0-newCP0
        double b = arrClust[1] - cvmGet(newCP,i,1); //b = CL1-newCP1
        double c = arrClust[2] - cvmGet(newCP,i,2); //c = CL2-newCP2
        double sum = (a*a)+(b*b)+(c*c);             //(a^2 + b^2 + c^2)
        double sqrtSum = sqrt(sum);

        distance[j] = sqrtSum ;

        if(distance[j]<=Ts)
            result[j] = 0;
        else
            result[j] = 1;
    }
    //Checking for zero in result array 
    int isZero = 1;
    for(int k =0;k<=count;k++)
    {
        if(result[k] == 0)
        {
            isZero =0;
            break;
        }
    }
    if(isZero!=0)
    {
        count = count+1;
        cvSeqPush(seqClust,arrClust);
        arrClust = (double*)malloc(3*sizeof(double));
        arrClust[0] = cvmGet(newCP,i,0);
        arrClust[1] = cvmGet(newCP,i,1);
        arrClust[2] = cvmGet(newCP,i,2);

    }
    else
    {
        double minElement = fnSortForMin(distance,count+1); //Getting the minimum value from distance array
        int index = fnSearchIndexOfMin(distance,minElement,count+1); //Getting the index of minElement
        if(index == count)
        {
            arrClust[0] = (arrClust[0]+cvmGet(newCP,i,0))/2;
            arrClust[1] = (arrClust[1]+cvmGet(newCP,i,1))/2;
            arrClust[2] = (arrClust[2]+cvmGet(newCP,i,2))/2;
        }
        else
        {
            s = seqClust;
            for(int i = 1;i<index;i++)
            {
                s = seqClust->h_next; 
            }
            double * arr = CV_GET_SEQ_ELEM(double,s,index);
            arr[0] = (arr[0]+cvmGet(newCP,i,0))/2;
            arr[1] = (arr[1]+cvmGet(newCP,i,1))/2;
            arr[2] = (arr[2]+cvmGet(newCP,i,2))/2;
        }
    }//End of outer If Block        
}//End Of outer For loop

The problem occurs in line where I am using CV_GET_SEQ_ELEM.Can anybody tell me where is the problem??

  • 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-29T17:14:26+00:00Added an answer on May 29, 2026 at 5:14 pm

    Problem is the that CV_GET_SEQ_ELEM only gets one element at a time, and you have only specified the first element by passing in the index of 1.

    You want to call the function cvCvtSeqToArray with arguments like
    cvCvtSeqToArray(s, arr, CV_WHOLE_SEQ);

    Please note that the array arr passed the second paramter to this function will need to be intialised

    E.g. CvPoint* arr = (CvPoint*)malloc( count*sizeof(CvPoint)); where count is the number of elements in the array.

    CvSeq is strictly used to represent growable 1d arrays, as opposed to the 2d array you are trying to use. If you want to continue use multidimensional arrays that aren’t cvMat, you could try CvSeq of CvSeq but I still think you would have the same problem.

    Hence calling CV_GET_SEQ_ELEM only cleanly accesses the single pointer in memory that you give it, which is the first element of the array.

    You could also try std::vector of CvSeq or an array of CvSeq but I haven’t tried that.

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

Sidebar

Related Questions

I'm creating my own JavaScript Array-like object and I have methods that call closures.
I have this code, but I don't see where I went wrong here. It
I have a function which grows an array when trying to add an element
I'm creating this form with checkboxes that I want to populate from a database.
I have several variables of type char (array), int, and double. Is there a
I am creating an array of string objects in PowerShell which needs to be
Why is it that for user defined types when creating an array of objects
When creating a 3D array in C#, which is a better way to create
I'm creating a numpy array which is to be filled with objects of a
If you are creating a 1d array in Python, is there any benefit 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.