[Python+OpenCV] 灰階、模糊、邊緣檢測

藉由調整模糊參數或邊緣檢測參數來達到想要的結果

import cv2
import numpy as np

image = cv2.imread("./images/coins.png")

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

blurred = cv2.GaussianBlur(gray, (5, 5), 0)

canny = cv2.Canny(blurred, 30, 150)

result = np.hstack([gray, blurred, canny])

cv2.imshow("Result:", result)
cv2.waitKey(0)

import cv2
import numpy as np

image = cv2.imread("./images/coins.png")

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

blurred = cv2.GaussianBlur(gray, (11, 11), 0)

canny = cv2.Canny(blurred, 30, 150)

result = np.hstack([gray, blurred, canny])

cv2.imshow("Result:", result)
cv2.waitKey(0)

import cv2
import numpy as np

image = cv2.imread("./images/coins.png")

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

blurred = cv2.GaussianBlur(gray, (7, 7), 0)

canny = cv2.Canny(blurred, 100, 200)

result = np.hstack([gray, blurred, canny])

cv2.imshow("Result:", result)
cv2.waitKey(0)