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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:01:30+00:00 2026-06-14T03:01:30+00:00

So my problem is a relatively simple one, but still quite hard for a

  • 0

So my problem is a relatively simple one, but still quite hard for a Python rookie like me.
So I essentially have a number of shapes in an input image like a bunch of small triangles in a square or so. I need to extract the outer square and each triangle from within the image. I’ve developed a simple template matching code to do this… but it does not seem to work!

while ( len(numpy.where( b <150 )[0])!=xx):
xx=len(numpy.where( b <150 )[0])
for v in range(len(b)-len(a)):
    for w in range(len(b[0])-len(a[0])):
        c=b[v:v+len(a[0]),w:w+len(a)]
        c.flags.writeable=False
        #c=b.reshape(len(a),len(a))
        vv=sum(sum(c-a))
        #print v, w
        if(vv<minval):
            minval=vv
            xcor=v
            ycor=w

print xcor, ycor, minval
print len(numpy.where( b <150 )[0])
print b[xcor:xcor+len(a),ycor:ycor+len(a[0])]
for p in range(xcor,xcor+len(a)):
    for q in range(ycor,ycor+len(a[0])):
        b.setflags(write=True)
        b[p][q]=251;
#print b[xcor:xcor+len(a),ycor:ycor+len(a[0])]
xcorr=0
ycorr=0
minval=99999

The problem is that I need to extract only a simple set of figures, but my code goes on and on… Also, I do not know how to handle the TRIANGLES IN A BOX problem. Can someone please help me out?

By extract, I mean only find out just where the object is placed… if it is placed at all!

  • 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-14T03:01:32+00:00Added an answer on June 14, 2026 at 3:01 am

    If you decide to use opencv, this should get you started:

    import cv2
    
    def show_image_and_wait_for_key( image, name="Image" ):
        print "showing",name,"(waiting for input)"
        cv2.imshow('norm',image)
        cv2.waitKey(0)
    
    def draw_segments( image , segments, color=(255,0,0), line_width=1):
            '''draws segments on image'''
            for segment in segments:
                x,y,w,h= segment
                cv2.rectangle(image,(x,y),(x+w,y+h),color,line_width)
    
    original= cv2.imread("ravens.jpg")
    image=original
    image= cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
    image= cv2.GaussianBlur(image,(3,3),0)
    _, image= cv2.threshold( image, 140, 255, cv2.THRESH_BINARY )
    contours,hierarchy = cv2.findContours(image.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
    segments= [cv2.boundingRect(c) for c in contours] 
    draw_segments( original, segments )
    show_image_and_wait_for_key( original )
    

    After this, you can filter by rectangle area, position, aspect ratio, etc.
    You can extract a region from the image using this function:

    def region_from_segment( image, segment ):
        '''given a segment (rectangle) and an image, returns it's corresponding subimage'''
        x,y,w,h= segment
        return image[y:y+h,x:x+w]
    

    All images are also numpy ndarray, so you should be comfortable with the cv2 interface

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

Sidebar

Related Questions

I am relatively newbie. The problem I have is a simple one I think,
So, my problem is relatively simple. I have one spider crawling multiple sites, and
I have a computational geometry problem that I feel should have a relatively simple
I have a number of relatively simple (auto-generated) graphs in graphviz dot format. These
I have converted a relatively simple algorithm that performs a large number of calculations
I have a problem with a relatively simple query and the execution plan Access
I feel my problem is relatively simple. I'm new to the Zend framework and
I believe I'm having a relatively simple problem with a video player implementation in
My problem is relative simple, but I'm not getting much luck with searches for
I hope this is a relatively easy problem although I have spent hours websearching

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.