Python 用 OpenCV 画点和圆 (2)

18 篇文章 5 订阅
17 篇文章 3 订阅

利用 opencv 里自带的 circle() 函数可以绘制以一个点为圆心特定半径的圆,其函数的声明如下:

cv2.circle(img, center, radius, color[, thickness[, lineType[, shift]]])

函数参数含义如下:

  • img:要画的圆所在的矩形或图像
  • center:圆心坐标,如 (100, 100)
  • radius:半径,如 10
  • color:圆边框颜色,如 (0, 0, 255) 红色,BGR
  • thickness:正值表示圆边框宽度. 负值表示画一个填充圆形
  • lineType:圆边框线型,可为 0,4,8
  • shift:圆心坐标和半径的小数点位数

画点实际上就是画半径很小的实心圆,画点和画圆的完整代码如下:

#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
@Time    : 2018-11-09 21:39
@Author  : jianjun.wang
@Email   : alanwang6584@gmail.com
"""

import numpy as np
import cv2 as cv
 
img = np.zeros((320, 320, 3), np.uint8) #生成一个空灰度图像
print img.shape # 输出:(480, 480, 3)

point_size = 1
point_color = (0, 0, 255) # BGR
thickness = 4 # 可以为 0 、4、8

# 要画的点的坐标
points_list = [(160, 160), (136, 160), (150, 200), (200, 180), (120, 150), (145, 180)]

for point in points_list:
	cv.circle(img, point, point_size, point_color, thickness)

# 画圆,圆心为:(160, 160),半径为:60,颜色为:point_color,实心线
cv.circle(img, (160, 160), 60, point_color, 0)

cv.namedWindow("image")
cv.imshow('image', img)
cv.waitKey (10000) # 显示 10000 ms 即 10s 后消失
cv.destroyAllWindows()

运行后效果如下:
在这里插入图片描述

原文英文文档
本文地址

Python 安装 OpenCV 及显示图像 (1)

Python 用 OpenCV 画点和圆 (2)

Python 用 OpenCV 画直线 (3)

Python 用 OpenCV 画矩形 (4)

Python 用 OpenCV 画椭圆 (5)

Python 用 OpenCV 显示文字 (6)

  • 28
    点赞
  • 131
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值