安装命令:
pip install opencv-python
其实上安装失败。
再试一下:
pip install opencv-contrib-python
可是,安装失败了。
只能登陆PyPI网站直接下载。
Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows PS C:windowssystem32> cd PS C:> pip install "opencv_python-4.5.5.64-cp36-abi3-win_amd64.whl" Processing c:opencv_python-4.5.5.64-cp36-abi3-win_amd64.whl Requirement already satisfied: numpy>=1.14.5 in c:usersa-xiaobodouappdatalocalprogramspythonpython310libsite-packages (from opencv-python==4.5.5.64) (1.22.3) Installing collected packages: opencv-python Successfully installed opencv-python-4.5.5.64 PS C:>
彩色照片转换素描像:
import cv2
# 读取图片
img = cv2.imread("20220526104833.jpg")
# 灰度
grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
invert = cv2.bitwise_not(grey)
# 高斯滤波
blur_img = cv2.GaussianBlur(invert, (7, 7), 0)
inverse_blur = cv2.bitwise_not(blur_img)
sketch_img = cv2.divide(grey, inverse_blur, scale=256.0)
# 保存
cv2.imwrite('sketch.jpg', sketch_img)
cv2.waitKey(0)
cv2.destroyAllWindows()



