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

python 实现彩色图转素描图

zhangsir3年前 (2022-11-21)python268

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版权g4防采集https://mianka.xyz

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

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

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

分享给朋友:

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

python scrapy库安装

(1)安装pip install -i https://pypi.tuna.tsinghua.edu.cn/simple scrapy (2) 报错1: building 'twisted.test.raiser' extension...

如何用python获取一个网页的所有连接

如何用python获取一个网页的所有连接很简单直接上代码:# -*- coding: utf-8 -*- ''' 如何用python获取一个网页的所有连接 author:zhangsir ''' imp...

python之seleniumwire获取network(网络)信息

python之seleniumwire获取请求头参数import time from seleniumwire import webdriver # 创建Chrome驱动程序的新实例 driver = webdriver...

python 爬虫 报错:UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0x8b in position”解决方案

发现报错“UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1:invalid start byte”,方法一:根据报错提示,错误原因有一条是这样的:“'Accept-Encodi...

python selenium 使用代理ip

代码如下:from selenium import webdriver chromeOptions = webdriver.ChromeOptions() chromeOptions.add_argument("--proxy-serv...

Linux系统下使用Python+selenium+谷歌浏览器下载文件

from seleniumwire import webdriver import time ch_options = webdriver.ChromeOptions() ch_options.add_argument("-...