当前位置:首页 > python > 正文内容

python 实现彩色图转素描图

zhangsir3年前 (2022-11-21)python441

python可以把彩色图片转化为铅笔素描草图,对人像、景色都有很好的效果。


而且只需几行代码就可以一键生成,适合批量操作,非常的快捷。


需要的第三方库:


Opencv - 计算机视觉工具,可以实现多元化的图像视频处理,有Python接口


""" Photo Sketching Using Python """
  import cv2
  img = cv2.imread("elon.jpg")
  ## Image to Gray Image
  gray_image = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
  ## Gray Image to Inverted Gray Image
  inverted_gray_image = 255-gray_image
  ## Blurring The Inverted Gray Image
  blurred_inverted_gray_image = cv2.GaussianBlur(inverted_gray_image, (19,19),0)
  ## Inverting the blurred image
  inverted_blurred_image = 255-blurred_inverted_gray_image
  ### Preparing Photo sketching
  sketck = cv2.divide(gray_image, inverted_blurred_image,scale= 256.0)
  cv2.imshow("Original Image",img)
  cv2.imshow("Pencil Sketch", sketck)
  cv2.waitKey(0)


zhangsir版权f8防采集https://mianka.xyz

扫描二维码推送至手机访问。

版权声明:本文由zhangsir or zhangmaam发布,如需转载请注明出处。

本文链接:http://mianka.xyz/post/67.html

分享给朋友:

“python 实现彩色图转素描图” 的相关文章

Python三方库ddddocr实现验证码识别

Python三方库ddddocr实现验证码识别环境要求python >= 3.8安装三方库pip install ddddocr -i https://pypi.tuna.tsinghua.edu.cn/simple参数说明:参数名参数类型默认值说明us...

权大师商标查询api

''' data:2022-10-15 autor:zhangsir 权大师商标查询api ''' import requests import json import time import h...

怎么用python连接websocket

要使用 Python 连接 WebSocket,可以使用 websocket 模块或 websocket-client 库。以下是使用 websocket-client 库连接 WebSocket 的基本步骤:安装 websocket-client 库。可以使用 pip 进行安装:pip ...

用python写个selenium上传文件的程序

当您使用 Selenium 来自动化测试时,上传文件是一个非常常见的需求。下面是一个使用 Python 和 Selenium WebDriver 来上传文件的示例代码:from selenium import webdriver from selenium....

用python写个selenium上传文件的程序,非input标签的上传

非input标签的上传通常是通过模拟点击“上传”按钮打开系统的文件选择框,然后在文件选择框中选择文件并点击“确定”按钮实现的。在Selenium中,我们可以使用AutoIT或pywinauto等工具来模拟操作系统的窗口,实现非input标签的上传。下面是一个使用pywinauto模块实现非input...