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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:22:09+00:00 2026-05-27T14:22:09+00:00

I am porting some code that is using OpenCV just to fit an ellipse.

  • 0

I am porting some code that is using OpenCV just to fit an ellipse. I may rewrite it later but for now I need to use the OpenCV routine.
This code is just a few lines but I had to change almost everything because the profile of cvFitEllipse2() has changed.

My problematic is the following one: convert an array of point (pair of uchar) into something I can feed cvFitEllipse2() with

I did not found a lot of code sample and I find that OpenCV is poorly documented (but since I am new to OpenCV, maybe this feeling is wrong).
Anyway here is what I wrote:

/* centers is the input uchar array */
CvBox2D box;    //output
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* seq = cvCreateSeq(CV_32FC2, sizeof(CvSeq), sizeof(CvPoint2D32f), storage);

for(int h=0; h<mm; ++h) 
{
    CvPoint2D32f p;
    p.x = (float)centers[h].x;
    p.y = (float)centers[h].y;
    cvSeqPush(seq, &p);
}

// Fits ellipse to current contour.
box = cvFitEllipse2(seq);

Problem: this code is damn slow compared to the original one.

  • Is there any way to preallocate the memory required for seq? (using
    the CvMemStorage object)
  • Are there better (simpler? containers than
    CvSeq?
  • Can I replace the cvSeqPush by something faster?

Thanks a lot for your help!

  • 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-27T14:22:10+00:00Added an answer on May 27, 2026 at 2:22 pm

    I assume centers is a vector of points.

    If you are happy to use the C++ interface instead of the old one, your pain is over.

    Depending on the way centers is declared you can:

    vector<cv::Point> centers;
    RotatedRect rect = fitEllipse(centers);
    

    Or the hard-core approach:

    struct {
        uchar x, y
    } myPoint;
    
    vector<myPoint> centers;
    ...
    int sz = centers.size();
    
    // if you have a different type for x and y, modify here to CV_MY_TYPE
    // Here I have taken a pointer to the vector data storage, 
    // and fed it into the Mat.
    // Check Mat documentation on constructors
    Mat pts(1,sz,CV_8UC2, (void*)&centers[0].x); 
    RotatedRect rect = fitEllipse(pts);
    ...
    // take care not to change/ delete your vector 
    // before finishing with the pts Mat.
    

    EDIT

    I have modified types to UCHAR

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

Sidebar

Related Questions

I have some code that I am porting from an SGI system using the
I have code that works on Windows, but now that I am porting to
I'm just porting some code over from .net to Java. I've been using the
I'm working on porting some PHP code to C, that contacts a web API.
I'm porting some open source code so that it can build on another c++
I'm porting some code from BSD sockets to Winsock, and I'm not sure how
I'm porting some code from Python 2 to 3. This is valid code in
I'm porting over some code from one project to another within my company and
I'm porting some C++ code to C#. Does C# have an equivalent to std::nth_element()
I am porting some C# code over to Java. I am having trouble with

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.