ORIGINAL IMAGE:
GOAL:
I want to separate texts into individual paragraphs by placing bounding boxes over them (as shown above).
I tried it do this via traditional computer vision approach using opencv.
- I plotted character level bounding box
- Next, I gray-scaled the image, binarized it.
- Applied dilation
- And finally placed bbox over the dilated image.
This is what I get:
> #Morphological Transformation
kernel = np.ones((3,4),np.int8)
dilation = cv2.dilate(im_bw, kernel)
cv2.imwrite('dilated.png', dilation)
Plotting rectangular box
ret,thresh = cv2.threshold(im_bw, 127,255,0)
image, contours,hierarchy = cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE )
for c in contours:
rect = cv2.boundingRect(c)
if rect[2] < 50 or rect[3] < 50 : continue
print (cv2.contourArea(c))
x,y,w,h = rect
cv2.rectangle(im_new,(x,y),(x+w,y+h),(0,255,0),2)
cv2.imwrite('sample_res_inner.jpg',im_new)
Since the image is scanned image plus the line-spaces between them are small I couldn't able to segment them based on paragraphs.
How can I get my desired result?


