
#!/usr/bin/env python |
# encoding: utf-8 |
import cv2 |
import numpy as np |
class picture: |
def __init__(self): |
self.path = 'assets/picture.jpeg' |
def hello(self): |
return self |
def run(self): |
# 读取原始图像 |
src = cv2.imread(self.path) |
# 图像灰度处理 |
gray = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY) |
# 自定义卷积核 |
kernel = np.array([[-1, -1, -1], [-1, 10, -1], [-1, -1, -1]]) |
# kernel = np.array([[0,-1,0],[-1,5,-1],[0,-1,0]]) |
# 图像浮雕效果 |
output = cv2.filter2D(gray, -1, kernel) |
# 显示图像 |
cv2.imshow('Original Image', src) |
cv2.imshow('Emboss_1', output) |
# 等待显示 |
cv2.waitKey() |
cv2.destroyAllWindows() |
if __name__ == '__main__': |
picture().hello().run() |



