I have a text detector which outputs polygon coordinates of detected text:
I am using below loop to show how the detected text looks like with bounding boxes:
for i in range(0, num_box):
pts = np.array(boxes[0][i],np.int32)
pts = pts.reshape((-1,1,2))
print(pts)
print('\n')
img2 = cv2.polylines(img,[pts],True,(0,255,0),2)
return img2
Each pts stores all coordinates of a polygon, for one text box detection:
pts =
[[[509 457]]
[[555 457]]
[[555 475]]
[[509 475]]]
I would like to convert the area inside the bounding box described by pts to grayscale using:
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
However I am not sure how should I provide the image argument in above gray_image as I want to convert only the area described by pts to grayscale and not the entire image (img2). I want the rest of the image to be white.


