栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

1.6 画图

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

1.6 画图

import numpy as np
import cv2
import matplotlib.pyplot as plt
def show(image):
    plt.imshow(image)  #用以显示图片的函数
    plt.axis('off')   #matplotlib显示函数,默认会显示坐标轴,调用此函数不让其显示坐标轴
    plt.show()
image = np.zeros((300,300,3),dtype='uint8')  #定义一个图片,显示为全黑
show(image)

画线
green = (0,255,0)
cv2.line(image, (0,0), (300,300), green)
show(image)

blue = (0,0,255)
cv2.line(image, (300,0), (150,150), blue, 5)  #5 线的宽度 line函数画线
show(image)

画矩形
red = (255,0,0)
cv2.rectangle(image, (10,10), (60,60), red, 2) #rectangle 矩形函数
show(image)

cv2.rectangle(image, (50,50), (100,100), blue, 5)
show(image)

cv2.rectangle(image, (50,200), (220,280), green, -1) #-1 填充
show(image)

画圆形
image = np.zeros((300,300,3),dtype='uint8')
(cX, cY) = image.shape[1]//2, image.shape[0]//2
white = (255,255,255)
for r in range(0,151,15):  #r代表圆的半径 以中间点为圆心
    cv2.circle(image, (cX,cY), r, white, 2)
show(image)

image = np.zeros((300,300,3),dtype='uint8')
for i in range(10):
    # 半径取值
    radius = np.random.randint(5,200)
    # 颜色取值
    color = np.random.randint(0,255,size=(3,)).tolist()  #tolist变为list
    # 圆心取值
    pt = np.random.randint(0,300,size=(2,))
    # 画图
    cv2.circle(image, tuple(pt), radius, color, -1)
show(image)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/461668.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号