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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:03:36+00:00 2026-05-30T02:03:36+00:00

I have a working connected components analysis code working in C. It’s actually a

  • 0

I have a working connected components analysis code working in C. It’s actually a copy from the book “Learning Opencv”.

Now I am rewriting all that code to Python and I cannot find some of that function in the Python API, like cvStartFindContours.

I am wondering is somebody has a basic connected components analysis function implemented in Python. I know there are some libraries, but I am searching for something simpler, just a function or a piece of code.

I don’t need anything “big” because I have a plain black image with 2 or 3 white circles, and I want to find the number of circles and its center.

I know I can probably code on myself but I prefer to use somebody’s function or simple library.

EDIT: I solved it the following way.

def find_connected_components(img):
    """Find the connected components in img being a binary image.
    it approximates by rectangles and returns its centers
    """

    storage = cv.CreateMemStorage(0)
    contour = cv.FindContours(img, storage, cv.CV_RETR_CCOMP, cv.CV_CHAIN_APPROX_SIMPLE)
    centers = []

    while contour:
        # Approximates rectangles
        bound_rect = cv.BoundingRect(list(contour))

        centers.append(bound_rect[0] + bound_rect[2] / 2, bound_rect[1] + bound_rect[3] / 2)

        contour = contour.h_next()
  • 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-30T02:03:36+00:00Added an answer on May 30, 2026 at 2:03 am

    You should take a look at the documentation. As of OpenCV 2.2 there is a complete new interface for Python which covers all C/C++ functions 🙂

    cv.FindContours should work for you 🙂

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

Sidebar

Related Questions

I have been working with a string[] array in C# that gets returned from
I have been working on some legacy C++ code that uses variable length structures
I have a working copy of my project, checked out using Subversion 1.5.1. When
i am working on VC#.net i have connected my combox with my database when
I am working on Connected Components labeling, and my matrix is: 1 1 0
I have been working on creating an application that sends a string from an
Hello I have been working for a while with PHP and MySQL. Now I
I have been working with the following code published on msdn: http://msdn.microsoft.com/en-us/library/fx6588te.aspx I understand
I'm working on a project that has components, components have features, features have bugs.
I have a working code which creates a window with a text area. The

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.