import cv2
import numpy as np
img = cv2.imread('image0.jpg',1)
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# newP = gray0-gray1+150 相邻像素值相减为了突出边缘特征 +150是为了增加浮雕灰度等级
dst = np.zeros((height,width,1),np.uint8)
for i in range(0,height):
for j in range(0,width-1): #防止越界
grayP0 = int(gray[i,j])
grayP1 = int(gray[i,j+1]) #后一个像素
newP = grayP0-grayP1+150
if newP > 255: #还要判断
newP = 255
if newP < 0:
newP = 0
dst[i,j] = newP
cv2.imshow('dst',dst)
cv2.waitKey(0)
opecv入门:3.6图片特效-浮雕效果
最新推荐文章于 2024-05-19 11:43:37 发布
