opencv gui之常用的画图接口示例-01

本文详细介绍了使用Python的OpenCV库进行图像绘制,包括绘制直线、矩形、圆形、椭圆和多边形。通过实例展示了如何创建和修改图像,并利用cv2函数实现各种形状。适合初学者了解图像处理基础和Python编程应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 画图结果

2. 代码

# -*- coding: utf-8 -*-
# @Time    : 2021/1/31 下午4:36
# @Author  : zxq
# @File    : func.py
# @Software: PyCharm

import numpy as np
import cv2 as cv

# Create a black image
img = np.zeros((512, 512, 3), np.uint8)

# line
# Draw a diagonal blue line with thickness of 5 px
cv.line(img, (0, 0), (511, 511), (255, 0, 0), 5)

# rectangle
cv.rectangle(img, pt1=(384, 0), pt2=(510, 128), color=(0, 255, 0), thickness=3)

# circle
cv.circle(img, (447, 63), radius=63, color=(0, 0, 255), thickness=-1)

# ellipse
# angle: rotation angle,
cv.ellipse(img, center=(256, 256), axes=(100, 50), angle=90, startAngle=90, endAngle=180, color=255, thickness=-1)

# Polygon
pts = np.array([[10, 5], [20, 30], [70, 20], [50, 10]], np.int32)
pts = pts.reshape((-1, 1, 2))  # (4, 2)->(4, 1, 2)
cv.polylines(img, pts=[pts, pts+40], isClosed=True, color=(0, 255, 255))

cv.namedWindow('img', 0), cv.imshow('img', img), cv.waitKey()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mr.Q

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值