To implement Erosion and Dilation using Python and OpenCV.
- Anaconda - Python 3.7
- OpenCV
Import the necessary packages.
Create the Text using cv2.putText.
Create the structuring element.
Erode the image using cv2.erode().
#DEVELOPED BY : M LOKESH KRISHNAA
#REG.NO : 212220230030
import numpy as np
import cv2
import matplotlib.pyplot as plt
img1=np.zeros((100,500),dtype='uint8')
font=cv2.FONT_HERSHEY_COMPLEX_SMALL
# Create the Text using cv2.putText
cv2.putText(img1,'LOKESH KRISHNAA',(5,70),font,2,(255),5,cv2.LINE_AA)
plt.imshow(img1,cmap='gray')
kernel1=cv2.getStructuringElement(cv2.MORPH_CROSS,(7,7))
img_erode=cv2.erode(img1,kernel1)
plt.imshow(img_erode,cmap='gray')
img_dilate=cv2.dilate(img1,kernel1)
plt.imshow(img_dilate,cmap='gray')
Thus the generated text image is eroded and dilated using python and OpenCV.