To implement Erosion and Dilation using Python and OpenCV.
- Anaconda - Python 3.7
- OpenCV
Import the necessary libraries (OpenCV and NumPy).
Use cv2.putText to add the text to the img1 image at specific coordinates.
Define two kernels (kernel and kernel1) for morphological operations.
Display the eroded image using cv2.imshow.
Use cv2.waitKey(0) to wait for a key press indefinitely.
DEVELOPED BY: SANJAY G
REG NO: 212222230131
import cv2
import numpy as np
img1=np.zeros((100,400),dtype="uint8")
font=cv2.FONT_HERSHEY_PLAIN
cv2.putText(img1,"JFUJ",(5,70),font,2,(255),5,cv2.LINE_AA)
cv2.imshow("image",img1)
cv2.waitKey(0)
kernel=np.ones((5,5),np.uint8)
kernel1=cv2.getStructuringElement(cv2.MORPH_CROSS,(7,7))
cv2.erode(img1, kernel)
image_erode = cv2.erode(img1,kernel1)
cv2.imshow("SAN",image_erode)
cv2.waitKey(0)
image_dilatel=cv2.dilate(img1,kernel1)
cv2.imshow("SAN",image_dilatel)
cv2.waitKey(0)
Thus the generated text image is eroded and dilated using python and OpenCV.