drawing a rectangle around a color as shown?
I want to detect the color, which I have done with the following code:
import cv2 as cv
import numpy as np
cap = cv.VideoCapture(0)
while(1):
_, frame = cap.read()
# Convert BGR to HSV
hsv = cv.cvtColor(frame, cv.COLOR_BGR2HSV)
# define range of blue color in HSV
lower_blue = np.array([100,55,55])
upper_blue = np.array([105,255,255])
# Threshold the HSV image to get only blue colors
mask = cv.inRange (hsv, lower_blue, upper_blue)
# Bitwise-AND mask and original image
res = cv.bitwise_and(frame,frame, mask= mask)
cv.imshow('frame',frame)
cv.imshow('mask',mask)
cv.imshow('res',res)
k = cv.waitKey(5) & 0xFF
if k == 27:
break
cv.destroyAllWindows()
but want to know how to draw a rectangle around it?
somewhat better, than your last question. however, please spare us duplicate ones to the same topic, thank. you !
and what you really need, is a tour through the tutorials
Esp this one
"...Contours can be explained simply as a curve joining all the continuous points (along the boundary), having same color or intensity..."
Sound good to me. Should work.
I just noticed you already extracted the bbox(ignore comment above) - maybe all you asking for is how to draw rectangles at all? For drawing functions look here