Opencv circle函数 画圆两种方式的不同效果

 cv2.LINE_AA 反走样线可以有效消除锯齿现象

import cv2
import matplotlib.pyplot as plt
import numpy as np
from queue import PriorityQueue


def main():
    img = np.zeros((400, 400), np.uint8)
    img2 = np.zeros((400, 400), np.uint8)
    img3 = np.zeros((400, 400), np.uint8)
    cv2.circle(img, (150, 150), 100, 255, -1)
    cv2.circle(img2, (150, 150), 50, 255, 100)
    cv2.circle(img3, (150, 150), 50, 255, 100, cv2.LINE_AA)
    cv2.imshow("circle", img)
    cv2.imshow("circle2", img2)
    cv2.imshow("circle3", img3)
    cv2.waitKey(0)


if __name__ == "__main__":
    main()

函数解释:

C++ :

void cv::circle     (     InputOutputArray      img,
        Point      center,
        int      radius,
        const Scalar &      color,
        int      thickness = 1,
        int      lineType = LINE_8,
        int      shift = 0
    )         
Python:
    img    =    cv.circle(    img, center, radius, color[, thickness[, lineType[, shift]]]    )

Draws a circle.

The function cv::circle draws a simple or filled circle with a given center and radius.

Parameters

imgImage where the circle is drawn.
centerCenter of the circle.
radiusRadius of the circle.
colorCircle color.
thicknessThickness of the circle outline, if positive. Negative values, like FILLED, mean that a filled circle is to be drawn.
lineTypeType of the circle boundary. See LineTypes
shiftNumber of fractional bits in the coordinates of the center and in the radius value.

效果图:

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
OpenCV中,circle函数用于在图像上绘制圆形。它的函数模板如下: circle(cv::InputOutputArray img, cv::Point center, int radius, const cv::Scalar& color, int thickness = 1, int lineType = 8, int shift = 0) 其中,参数解释如下: - img:输入输出图像,即要在其上绘制圆形的图像。 - center:圆心坐标,使用cv::Point表示。 - radius:圆的半径。 - color:圆的颜色,使用cv::Scalar表示。 - thickness:圆形边界的粗细,默认为1。 - lineType:线条的类型,默认为8。 - shift:圆心坐标和半径的小数位数,默认为0。 要使用circle函数绘制圆形,首先需要导入必要的头文件,如以下示例所示: ``` #include <opencv2/opencv.hpp> ``` 然后,可以创建一个cv::Mat对象来存储图像,并使用circle函数绘制圆形,如下所示: ``` cv::Mat img = cv::imread("path/to/image.jpg"); cv::circle(img, cv::Point(x, y), radius, cv::Scalar(0, 255, 0), thickness, lineType, shift); cv::imshow("circle", img); cv::waitKey(0); ``` 以上代码中,img是输入图像,cv::Point(x, y)是圆心坐标,radius是圆的半径,cv::Scalar(0, 255, 0)是圆的颜色(BGR格式),thickness是圆形边界的粗细,lineType是线条的类型,shift是圆心坐标和半径的小数位数。最后使用cv::imshow方法显示图像,并使用cv::waitKey方法等待用户按下任意键结束程序。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [利用opencv画圆](https://blog.csdn.net/qq_51785785/article/details/129553581)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [opencv c++ circle()函数 、putText()函数小结](https://blog.csdn.net/weixin_45842951/article/details/122201959)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值