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 question.(5)

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

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/How to Draw Bounding Box On Image Python Cv 2 ?
Next
Answered
Oliver Gelbero
  • 30
Oliver Gelbero
Asked: April 21, 20222022-04-21T07:42:21+00:00 2022-04-21T07:42:21+00:00In: python

How to Draw Bounding Box On Image Python Cv 2 ?

  • 30

. Advertisement .

..3..

. Advertisement .

..4..

I would like to draw a bounding box around each closed contour of an area larger than some threshold, not just the biggest contour. How can I go about doing this?. I suggest if you have specific sample that it is relevant  to the “draw bounding box on image python cv2” for the topic of python , it would be great for me.

♦ Suggestions of ITtutoria Team
Ideas for draw bounding box on image python cv2: Use the draw bounding box on image python cv2 to specify where you want your bounding box drawn. This function will display a black rectangle around the outer edge of an image that you can use for cropping, resizing, and other purposes.

boundingcv 2
  • 2 2 Answers
  • 45 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    Zane Jones
    2022-04-21T07:42:25+00:00Added an answer on April 21, 2022 at 7:42 am

    Keep in mind that your indentation rate is crucial in Python. It’s important to remember that your code does not necessarily draw an area around the largest contour. Instead, it draws an outline around the last part that is drawn by curves. Luckily, the solution is easy. It’s as simple as indenting all calls made in cv2.rectangle() and cv2.putText() to make sure they are evaluated on each loop iteration. You could also remove the call for cv2.boundingRect() by expanding the rect into x, y, w, h. So, DrawingBounding Box On Image Python Cv 2 coule be like this

    ## drawing b.box for given coutour
    ​
    ​
    contours, _ = cv2.findContours(thresh, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
    for c in contours:
        rect = cv2.boundingRect(c)
        if rect[2] < 100 or rect[3] < 100: continue
        print cv2.contourArea(c)
        x,y,w,h = rect
        cv2.rectangle(im,(x,y),(x+w,y+h),(0,255,0),2)
        cv2.putText(im,'Moth Detected',(x+w+10,y+h),0,0.3,(0,255,0))
    cv2.imshow("Show",im)
    cv2.waitKey()  
    cv2.destroyAllWindows()
    ​
    • 12
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Wren Wilson
    2022-04-21T07:42:27+00:00Added an answer on April 21, 2022 at 7:42 am

    An appropriate tip that worked for my side

    # cv2.rectangle(img, pt1, pt2, color, thickness, lineType, shift)
    cv2.rectangle(img, (x1, y1), (x2, y2), (255,0,0), 2)
    ​
    """
    x1,y1 ------
    |          |
    |          |
    |          |
    --------x2,y2
    """
    • 12
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

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.