照片换底色

import cv2
import numpy as np
# 读取照片
img=cv2.imread('girl.jpg')

# 图像缩放
img = cv2.resize(img,None,fx=0.5,fy=0.5)
rows,cols,channels = img.shape
print(rows,cols,channels)
cv2.imshow('img',img)

# 图片转换为灰度图
hsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
cv2.imshow('hsv',hsv)

# 图片的二值化处理
lower_blue=np.array([90,70,70])
upper_blue=np.array([110,255,255])
mask = cv2.inRange(hsv, lower_blue, upper_blue)


#腐蚀膨胀
erode=cv2.erode(mask,None,iterations=1)
cv2.imshow('erode',erode)

dilate=cv2.dilate(erode,None,iterations=1)
cv2.imshow('dilate',dilate)


# 窗口等待的命令,0表示无限等待
cv2.waitKey(0)

你可能感兴趣的:(随笔,opencv,python,计算机视觉)