OpenCV绘制线、圆、椭圆、矩形
作者:互联网
一、概述
案例:使用opencv在一张图片上绘制线、圆、椭圆、矩形
二、示例图片
三、示例代码
#include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace std; int main(int argc, char const *argv[]) { /* 绘制线、圆、椭圆、矩形 */ Mat src = imread("girl.jpg"); if(!src.data){ cout << "can't not found image"<<endl; return -1; } //绘制线 Point p1 = Point(20,30); Point p2; p2.x = 400; p2.y = 400; Scalar color(0,0,255); line(src,p1,p2,color,LINE_8); //绘制矩形 Rect rect = Rect(200,100,300,300); Scalar color2 = Scalar(255,0,0); rectangle(src,rect,color,2,LINE_8); //绘制椭圆 Scalar color3 = Scalar(0, 255, 0); ellipse(src, Point(src.cols / 2, src.rows / 2), Size(src.cols / 4, src.rows / 8), 90, 0, 360, color3, 2, LINE_8); //绘制圆 Scalar color4 = Scalar(0, 255, 255); Point center = Point(src.cols / 2, src.rows / 2); circle(src, center, 150, color4, 2, 8); //填充一个矩形 Point pts[1][5]; pts[0][0] = Point(100, 100); pts[0][1] = Point(100, 200); pts[0][2] = Point(200, 200); pts[0][3] = Point(200, 100); pts[0][4] = Point(100, 100); const Point* ppts[] = { pts[0] }; int npt[] = { 5 }; Scalar color5 = Scalar(255, 12, 255); fillPoly(src, ppts, npt, 1, color5, 8); //展示图片 imshow("src",src); waitKey(0); return 0; }
标签:椭圆,示例,int,namespace,OpenCV,矩形,绘制 来源: https://www.cnblogs.com/tony-yang-flutter/p/15381227.html