利用 OpenCV 函式 dilate()擴充套件影像


本程式使用 OpenCV 庫中的擴充套件函式,擴充套件影像。擴充套件會在影像中的物件邊界中新增畫素,即影像的各個側面都會擴充套件。

原始影像

演算法

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)

輸出

說明

正如你看到的,影像擴充套件了,即影像中的畫素擴充套件了,所以影像看起來有些變形。

更新日期: 2021 年 3 月 17 日

400 次瀏覽

開啟你的 職業生涯

完成課程,獲得認證

開始
廣告
© . All rights reserved.