To implement Erosion and Dilation using Python and OpenCV.
- Anaconda - Python 3.7
- OpenCV
- Step1: Import the necessary packages
- Step2: Insert the text using cv2.putText()
- Step3: The perform the erosion for given text and display the text using imshow()
- Step4: Next,perform dilation for inout text and display the result
DEVELOPED BY: PAVANA.G
REGISTER NUMBER: 212222230105
import cv2
import numpy as np
import matplotlib.pyplot as plt
img1=np.zeros((100,400),dtype='uint8')
font=cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img1,'TheAILearner',(5,70),font,2,(255),5,cv2.LINE_AA)
kernel=np.ones((5,5),np.uint8)
kernel1=cv2.getStructuringElement(cv2.MORPH_CROSS,(7,7))
image_erode1=cv2.erode(img1,kernel1)
plt.imshow(image_erode1)
plt.axis("off")
image_dilate1=cv2.dilate(img1,kernel1)
plt.imshow(image_dilate1)
plt.axis("off")
Thus the generated text image is eroded and dilated using python and OpenCV.