Python OpenCV如何使用cv2.circle()?解析和示例

2021年3月17日14:07:05 发表评论 4,360 次浏览

本文概述

OpenCV如何使用cv2.circle()?本文为你介绍cv2.circle()的详细用法,并有相应的代码示例,供你快速查看和使用circle()函数。

OpenCV是旨在解决计算机视觉问题的Python绑定库。 cv2.circle()方法用于在任何图像绘制圆

语法:

cv2.circle(图像, 中心坐标, 半径, 颜色, 厚度)

参数:

图像:这是要在其上绘制圆的图像。

中心坐标:是圆的中心坐标。坐标表示为两个值的元组, 即(X坐标值, Y坐标值)。

半径:是圆的半径。

颜色:是要绘制的圆的边界线的颜色。对于BGR, 我们传递一个元组。例如:(255, 0, 0)为蓝色。

厚度:这是圆形边界线的粗细(以像素为单位)。 -1 px的厚度将按指定的颜色填充圆形。返回值:返回图像。

下面所有示例都适用的图像:

Python OpenCV如何使用cv2.circle()?解析和示例

示例1:cv2.circle()绘制蓝色空心圆

# Python program to explain cv2.circle() method
   
# importing cv2
import cv2
   
# path
path = r 'C:\Users\Rajnish\Desktop\lsbin\geeks.png'
   
# Reading an image in default mode
image = cv2.imread(path)
   
# Window name in which image is displayed
window_name = 'Image'
  
# Center coordinates
center_coordinates = ( 120 , 50 )
 
# Radius of circle
radius = 20
  
# Blue color in BGR
color = ( 255 , 0 , 0 )
  
# Line thickness of 2 px
thickness = 2
  
# Using cv2.circle() method
# Draw a circle with blue line borders of thickness of 2 px
image = cv2.circle(image, center_coordinates, radius, color, thickness)
  
# Displaying the image
cv2.imshow(window_name, image)

输出如下:

Python OpenCV如何使用cv2.circle()?解析和示例

示例2:cv2.circle()绘制红色实心圆

# Python program to explain cv2.circle() method
   
# importing cv2
import cv2
   
# path
path = r 'C:\Users\Rajnish\Desktop\lsbin\geeks.png'
   
# Reading an image in default mode
image = cv2.imread(path)
   
# Window name in which image is displayed
window_name = 'Image'
  
# Center coordinates
center_coordinates = ( 120 , 100 )
 
# Radius of circle
radius = 30
  
# Red color in BGR
color = ( 0 , 0 , 255 )
  
# Line thickness of -1 px
thickness = - 1
  
# Using cv2.circle() method
# Draw a circle of red color of thickness -1 px
image = cv2.circle(image, center_coordinates, radius, color, thickness)
  
# Displaying the image
cv2.imshow(window_name, image)

输出如下:

Python OpenCV如何使用cv2.circle()?解析和示例

注意怪胎!巩固你的基础Python编程基础课程和学习基础知识。

Python怎么使用cv2.circle()?由以上的介绍,我们使用Python OpenCV的cv2.circle()方法来绘制圆,上面的例子介绍了该方法的用法说明,并示例使用cv2.circle()绘制了一个蓝色空心圆和一个红色实心圆,希望本文可以帮到你。


木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: