Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

第 20 章 图形开发

目录

20.1. SVG 图形库
20.1.1. 安装
20.1.2. 绘制多边形
20.1.3. SVG 事件
20.2. 二维码
20.2.1. qrcode
20.2.2. MyQR
20.2.3. 从图片识别二维码
20.2.4. 从摄像头识别二维码
20.3. graphviz
20.3.1. 安装 graphviz 环境
20.3.2. 例子
20.4. Pyro - Pyro is short for PYthon Remote Objects
20.5. Python Imaging Library
20.6. OpenCV
20.6.1. 安装 OpenCV
20.6.2. 显示图片
20.6.3. 将BGR图像转为RGB
20.6.4. uint8 格式
20.6.5. 应用Canny边缘检测
20.6.6. 摄像头捕捉图像
20.6.7. imread()
20.7. PIL(Python Imaging Library)Python 图像处理库
20.7.1. 安装
20.7.2. 缩放图像与尺寸修改
20.7.3. 叠加图像
20.7.4. 图像旋转
20.7.5. 获取图片信息
20.7.6. 创建空图像
20.7.7. 裁剪
20.7.8. 彩色转灰度
20.7.9. RGB 通道操作
20.7.10. 像素操作
20.7.11. 图像上加文字
20.7.12. 明暗调整
20.7.13. PIL 与 Numpy 相互转换
20.7.14. 比较两张图片

20.1. SVG 图形库

20.1.1. 安装

		
pip3 install drawsvg -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install cairosvg -i https://pypi.tuna.tsinghua.edu.cn/simple
		
		

20.1.2. 绘制多边形

		
lines = draw.Lines(
    # 坐标
    5, 5,
    # 横线 
    200, 5,
    # 竖线 
    200, 40, 
    # 斜线
    200 - 10, 20,
    # 横线2
    5 + 10, 20,
    # 斜线
    5, 40,
    # 闭合竖线
    5,5,
    fill='none', stroke='black')		
		
		

20.1.3. SVG 事件

		
<!DOCTYPE html>  
<html>  
<body>  
<svg width="500" height="150">  

<rect x="10" y="10" width="100" height="40"  
   style="stroke: black; fill: silver; fill-opacity: .4;"  
   onmouseover="this.style.stroke = 'blue'; this.style['stroke-width'] = 5;"  
   onmouseout="this.style.stroke = 'green'; this.style['stroke-width'] = 1;"
   onclick="this.style['width'] = 300;" />  

</svg>  
</body>  
</html>		
		
		
		
<!DOCTYPE html>
<html>

<body>
   <input id="aa" type="text" value="200" onclick="svg.style['width']=this.value;" />
   <svg width="500" height="150">


      <rect id='svg' x="10" y="10" width="100" height="40" style="stroke: black; fill: silver; fill-opacity: .4;"
         onmouseover="this.style.stroke = 'blue'; this.style['stroke-width'] = 5;"
         onmouseout="this.style.stroke = 'green'; this.style['stroke-width'] = 1;"
         onclick="this.style['width'] = 300; aa.value='300'" />

   </svg>
</body>

</html>