Ask Your Question
0

How do you create a bounding box on retroreflective tape?

asked 2017-01-14 17:22:37 -0600

Smosher104 gravatar image

updated 2017-01-15 02:19:50 -0600

berak gravatar image

Hello everyone. I am an FRC programmer and I have been trying to track a piece of retro reflective tape with a green led ring shining on it in opencv python. I have gotten to the point where I can create a calibrated hsv lower_green and upper_green numpy array, and black out everything, but the tape. However, I have no idea how to detect the rectangular piece of retroreflective tape and draw a bounding box around. Any help would be deeply appreciated.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-01-15 02:19:06 -0600

berak gravatar image

actually, getting the lower/upper bounds right is the hardest thing here, then it needs a few more steps:

# binarized image:
bin = cv2.inRange(hsv, lower,upper)

# contours:
im2, contours,hierarchy = cv2.findContours(bin,2,1)  # without 'im2' for opencv2.4 !!
if len(contours)>0:
    cnt = contours[0]
    (x,y,w,h) = cv2.boundingRect(cnt)
    cv2.rectangle(img, (x,y), (x+w,y+h), (255,0,0), 1)
edit flag offensive delete link more

Comments

Oh my god! Thank you so much! Notonly does this work perfectly, but it really helped me understand how contours work!

Smosher104 gravatar imageSmosher104 ( 2017-01-15 18:08:00 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-01-14 17:22:37 -0600

Seen: 606 times

Last updated: Jan 15 '17