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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:03:07+00:00 2026-05-26T00:03:07+00:00

I am working on a project using OpenCV. I need to precisely crop out

  • 0

I am working on a project using OpenCV. I need to precisely crop out some objects from HD photos.
I’m using a quad tree to cut my photos in pieces and then I calculate the homogeneity of each quad to determine if a piece of the object is in the quad.
I apply some filters as Canny with different thresholds depending on the homogeneity of the quad.
I hope this description is understandable.

This algorithm works for certain kinds of objects but I’m stuck with some others.
Here some example of my problems: I would like a way to flatten my contours.
The first screenshot is a after using the canny filter and a floodfill. The second is the final mask result.

http://pastebin.com/91Pgrd2D


To achieve this result, I use cvFindContours() so I have the contours but I can’t find a way to handle them like I want.

  • 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-26T00:03:08+00:00Added an answer on May 26, 2026 at 12:03 am

    Maybe you could use some kind of an average filter to approximate the curve and then use AproxPoly with a small gradient to smooth it.
    Here is a similar method:

    void AverageFilter(CvSeq * contour, int buff_length)
    {
        int n = contour->total, i, j;
        if (n > buff_length)
        {
            CvPoint2D32f* pnt;
            float* sampleX = new float[buff_length];
            float* sampleY = new float[buff_length];
    
            pnt = (CvPoint2D32f*)cvGetSeqElem(contour, 0);
            for (i = 0; i < buff_length; i++)
            {
                if (i >= buff_length / 2)
                {
                    pnt = (CvPoint2D32f*)cvGetSeqElem(contour, i + 1 - buff_length / 2 );
                }
                sampleX[i] = pnt->x;
                sampleY[i] = pnt->y;
            }
    
            float sumX = 0, sumY = 0;
    
            for (i = 1; i < n; i++)
            {
                pnt = (CvPoint2D32f*)cvGetSeqElem(contour, i);
                for (j = 0; j < buff_length; j++)
                {
                    sumX += sampleX[j];
                    sumY += sampleY[j];
                }
                pnt->x = sumX / buff_length;
                pnt->y = sumY / buff_length;
                for (j = 0; j < buff_length - 1; j++)
                    {
                        sampleX[j] = sampleX[j+1];
                        sampleY[j] = sampleY[j+1];
                    }
                if (i <= (n - buff_length / 2))
                {
                    pnt = (CvPoint2D32f*)cvGetSeqElem(contour, i + buff_length / 2 + 1);
                    sampleX[buff_length - 1] = pnt->x;
                    sampleY[buff_length - 1] = pnt->y;
                }
                sumX = 0;
                sumY = 0;
            }
            delete[] sampleX;
            delete[] sampleY;
        }
    } 
    

    You give it the contour and the size of the buffer of points that you want to do the average on.
    If you think the contour is too thick because some of the averaged points are bundled together too close, then that’s where Aproxpoly comes in because it reduces the number of points.
    But choose an appropriate gradient so you don’t make it too edgy.

    srcSeq = cvApproxPoly(srcSeq,sizeof(CvContour),storage, CV_POLY_APPROX_DP, x, 1);
    

    Play around with ‘x’ to see how you get better results.

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

Sidebar

Related Questions

I'm working on a project using Windows 2008, .NET 3.5 and WCF for some
I'm working on a project using OpenCV on template matching, and I want to
I've been working on a project using OpenCV for a while, and am ready
I have been working on a project using OpenCV and have made a face
I'm working on a project using an Arduino and as such, I'm reading from
I'm working on a project using Visual C++ 6.0, and I need to be
I am working in a project using openframeworks and I've been having some problems
I am working on a project using rails 2.1.1. With the new release of
I am working on a project using Castle Active Record. I stumbled across the
I'm working on a project using C++, Boost, and Qt. I understand how 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.