ในโปรแกรมนี้ เราจะขยายรูปภาพโดยใช้ฟังก์ชัน dilate ในไลบรารี OpenCV Dilation เพิ่มพิกเซลให้กับขอบเขตของวัตถุในภาพ กล่าวคือ มันขยายภาพทุกด้าน
ภาพต้นฉบับ

อัลกอริทึม
Step 1: Import cv2 and numpy. Step 2: Read the image using opencv.imread(). Step 3: Define the kernel using np.ones() function. Step 4: Pass the image and kernel to the dilate() function. Step 5: Display the image
โค้ดตัวอย่าง
import cv2
import numpy as np
image = cv2.imread('testimage.jpg')
kernel = np.ones((3,3), np.uint8)
image = cv2.dilate(image, kernel)
cv2.imshow('Dilated Image', image) ผลลัพธ์

คำอธิบาย
อย่างที่คุณเห็น รูปภาพถูกขยาย กล่าวคือ พิกเซลของรูปภาพถูกขยาย ดังนั้น รูปภาพจึงดูบิดเบี้ยวเล็กน้อย