'Image segmentation for extracting letters
I am trying to extract the individual letters from the below image
Below is the code which I implemented for the segmentation
img = cv.imread('image10.jpg')
img_gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
ret, thresh2 = cv.threshold(img_gray, 150, 255, cv.THRESH_BINARY_INV)
kernel = cv.getStructuringElement(cv.MORPH_RECT, (1,1))
mask = cv.morphologyEx(thresh2, cv.MORPH_DILATE, kernel)
bboxes = []
bboxes_img = img.copy()
contours = cv.findContours(mask, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
contours = imutils.grab_contours(contours)
contours = sort_contours(contours, method= "left-to-right")[0]
for cntr in contours:
x,y,w,h = cv.boundingRect(cntr)
cv.rectangle(bboxes_img, (x, y), (x+w, y+h), (0,0,255), 1)
bboxes.append((x,y,w,h))
cv.imshow('Image', bboxes_img)
cv.waitKey(0)
Below is the final output
Is there any way to segment the sentence perfectly to get all letters?
Any help or suggestion would be very helpful
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|