I have a text in an image, and there's a bounding box around it, like so:
What I'm trying to do is to find the top-left & bottom-right coordinates to calculate the diagonal of the rectangle. I didn't find anything in particular in python libraries. Here's the code of the rectangle:
image = cv2.imread('output.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (9,9), 0)
thresh =
cv2.adaptiveThreshold(blur,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
cv2.THRESH_BINARY_INV,11,30)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (9,9))
dilate = cv2.dilate(thresh, kernel, iterations=4)
cnts = cv2.findContours(dilate, cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
ROI_number = 0
for c in cnts:
area = cv2.contourArea(c)
if area > 10000:
x,y,w,h = cv2.boundingRect(c)
boundbox = cv2.rectangle(image, (x, y), (x + w, y + h),
(36,255,12), 3)
Any ideas? Thank you in advance!