To implement Opening and Closing using Python and OpenCV.
- Anaconda - Python 3.7
- OpenCV
Import the necessary packages.
Create the Text using cv2.putText.
Create the structuring element.
Use Opening operation.
Use Closing Operation.
Print the output and end the program.
Developed by : Gayathri A
Register Number : 212221230028
import cv2
import numpy as np
import matplotlib.pyplot as plt
text_image = np.zeros((100,500),dtype = 'uint8')
font = cv2.FONT_HERSHEY_SIMPLEX = 3
cv2.putText(text_image,"GAYATHRI RAJ",(5,70),font,2,(255),5,cv2.LINE_AA)
plt.title("Original Image")
plt.imshow(text_image,'magma')
plt.axis('off')
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS,(7,7))
opening_image = cv2.morphologyEx(text_image,cv2.MORPH_OPEN,kernel)
plt.title("Opening")
plt.imshow(opening_image,'magma')
plt.axis('off')
closing_image = cv2.morphologyEx(text_image,cv2.MORPH_CLOSE,kernel)
plt.title("Closing")
plt.imshow(closing_image,'magma')
plt.axis('off')
Thus the Opening and Closing operation is used in the image using python and OpenCV.