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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:01:17+00:00 2026-06-07T19:01:17+00:00

How to identify contours within another contour? I tried to go through many OpenCV

  • 0

How to identify contours within another contour? I tried to go through many OpenCV tutorials but I was unable to identify it. Please can some expert person provide simple code to explain it?

This is my input file

enter image description here

This dark part is the contour that I need to identify.

enter image description here

Please be kind enough to share your experience with me.

  • 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-06-07T19:01:19+00:00Added an answer on June 7, 2026 at 7:01 pm

    Here is a simple approach in Python code. (But as I stated in my comment below, It is not an universal answer applicable everywhere, It is just to show finding contour inside a contour can be done. And if your images are different, then you have to come with some different constraints other than i mentioned below)

    What you are doing after finding Contours is that, you check if area of each contour is less than a specified value ( i gave 10000, just a guess), if not it is bigger contour, avoid it. If less than specified value, it may be our square or rectangle next to it.

    So we find its width and height and check if aspect ratio close to 1. if so, it is our square.

    import cv2
    import numpy as np
    
    img = cv2.imread('sofcnt.jpg')
    gray = cv2.imread('sofcnt.jpg',0)
    
    ret,thresh = cv2.threshold(gray,127,255,1)
    
    cont,hier = cv2.findContours(thresh,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
    
    for cnt in cont:
        approx = cv2.approxPolyDP(cnt,0.02*cv2.arcLength(cnt,True),True)
        if cv2.contourArea(cnt) < 10000:
            x,y,w,h = cv2.boundingRect(cnt)
            if w/float(h) < 2:
                cv2.drawContours(img,[cnt],0,255,-1)
    
    
    cv2.imshow('a',img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    

    Result :

    enter image description here

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

Sidebar

Related Questions

Please can some one explain how to identify square shape of contours which are
I am trying to use the function ROI in OpenCV to identify a contour,
How can a pc identify a device or another pc by upnp (or similar
I can easily identify running processes by looping through the WMI Win32_Process elements. Is
can someone please identify what type of view this is, as i want to
please help me to identify which of these following is more optimized code? for(int
How can I identify the datas that have anything else than a number in
How I can identify what svn branch/tag points my code? I have project that
Can someone identify ONE WEB PAGE where <meta property=og:audio:artist> and <meta property=og:audio:album> are actually
What is can't identify protocol when I run the command /usr/sbin/lsof -p 20085 .

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.