OpenCV - C++ - cv::circle

OpenCV - C++ - cv::circle

https://docs.opencv.org/4.2.0/d6/d6e/group__imgproc__draw.html

1. cv::circle

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]]])

#include <opencv2/imgproc.hpp>

Draws a circle.
画一个圆。

The function cv::circle draws a simple or filled circle with a given center and radius.
函数 cv::circle 绘制具有给定中心和半径的空心或实心圆。

2. Parameters

img - Image where the circle is drawn.
center - Center of the circle cv::Point (x, y).
radius - Radius of the circle.
color - Circle color cv::Scalar (B, G, R).
thickness - Thickness of the circle outline, if positive. Negative values, like FILLED, mean that a filled circle is to be drawn. (圆形轮廓的粗细 (如果为正)。负值 (如 FILLED) 表示要绘制实心圆。)
lineType - Type of the circle boundary. See LineTypes (圆边界的类型。)
shift - Number of fractional bits in the coordinates of the center and in the radius value. (中心坐标和半径值中的小数位数。)

3. Example

//============================================================================
// Name        : cv::circle
// Author      : Yongqiang Cheng
// Version     : Feb 22, 2020
// Copyright   : Copyright (c) 2019 Yongqiang Cheng
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>

int main(int argc, char** argv)
{
	// First create a black image.
	cv::Mat image(500, 500, CV_8UC3, cv::Scalar(0, 0, 0));

	// Check if the image is created successfully.
	if (!image.data)
	{
		std::cout << "Could not open or find the image" << std::endl;
		exit(EXIT_FAILURE);
	}

	// unfilled circle - draws a circle.
	cv::Point centerCircle1(250, 250);
	int radiusCircle = 30;
	cv::Scalar colorCircle1(0, 0, 255); // (B, G, R)
	int thicknessCircle1 = 2;

	cv::circle(image, centerCircle1, radiusCircle, colorCircle1, thicknessCircle1);

	// filled circle - draws a circle.
	cv::Point centerCircle2(400, 100);
	cv::Scalar colorCircle2(0, 255, 0); // (B, G, R)

	// FILLED = -1
	cv::circle(image, centerCircle2, radiusCircle, colorCircle2, cv::FILLED);

	cv::namedWindow("Display window", cv::WINDOW_AUTOSIZE);
	cv::imshow("Display window", image);

	cv::waitKey(0);

	return 0;
}

在这里插入图片描述

  • 8
    点赞
  • 37
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
OpenCV是一个开源计算机视觉库,用于图像和视频处理。C++OpenCV的主要编程语言,但也可以使用C进行开发。以下是使用C语言编写的一些OpenCV代码示例: 示例1:读取视频文件 ``` #include <opencv2/opencv.hpp> #include <stdio.h> int main() { CvCapture* capture; IplImage* frame; capture = cvCaptureFromFile("test_video.mp4"); cvNamedWindow("Video", CV_WINDOW_AUTOSIZE); while (1) { frame = cvQueryFrame(capture); if (!frame) break; cvShowImage("Video", frame); char c = cvWaitKey(33); if (c == 27) break; } cvReleaseCapture(&capture); cvDestroyWindow("Video"); return 0; } ``` 这段代码使用了CvCapture和IplImage结构,通过cvCaptureFromFile函数从视频文件中读取帧,并使用cvShowImage函数显示每一帧。 示例2:读取摄像头 ``` #include <opencv2/opencv.hpp> #include <stdio.h> int main() { CvCapture* capture; IplImage* frame; capture = cvCaptureFromCAM(0); cvNamedWindow("Video", CV_WINDOW_AUTOSIZE); while (1) { frame = cvQueryFrame(capture); cvShowImage("Video", frame); char c = cvWaitKey(33); if (c == 27) break; } cvReleaseCapture(&capture); cvDestroyWindow("Video"); return 0; } ``` 这段代码使用了cvCaptureFromCAM函数从摄像头中读取帧,并显示每一帧。 示例3:图像处理 - 绘制圆形 ``` #include <opencv2/opencv.hpp> #include <stdio.h> int main() { cv::Mat image = cv::Mat::zeros(300, 600, CV_8UC3); cv::circle(image, cv::Point(300, 200), 100, cv::Scalar(25, 110, 288), -100); cv::circle(image, cv::Point(400, 200), 100, cv::Scalar(255, 123, 127), -100); cv::imshow("Image", image); cv::waitKey(0); return 0; } ``` 这段代码创建了一个黑色的图像,并使用cv::circle函数在图像上绘制了两个圆形。 示例4:对象检测 ``` #include <opencv2/opencv.hpp> #include <stdio.h> int main() { cv::Mat img = cv::imread("test.png"); cv::CascadeClassifier faceCascade; faceCascade.load("haarcascade_frontalface_default.xml"); std::vector<cv::Rect> faces; faceCascade.detectMultiScale(img, faces, 1.1, 10); for (int i = 0; i < faces.size(); i++) { cv::rectangle(img, faces[i].tl(), faces[i].br(), cv::Scalar(255, 0, 255), 3); } cv::imshow("Image", img); cv::waitKey(0); return 0; } ``` 这段代码使用cv::CascadeClassifier类加载了一个面部识别的级联分类器,并在输入图像中检测到的面部周围绘制了矩形框。 希望这些示例代码对您有所帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [OpenCV入门【C++版】](https://blog.csdn.net/Star_ID/article/details/122656593)[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^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* [OpenCV安装及其开发环境配置(C++)](https://blog.csdn.net/m0_61897853/article/details/122609454)[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^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Yongqiang Cheng

梦想不是浮躁,而是沉淀和积累。

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

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

打赏作者

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

抵扣说明:

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

余额充值