zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    一个接口的性能问题定位和分析过程
    HTTP请求全过程(很全面)
    Linux中查看物理CPU个数、核数、逻辑CPU个数
    linux查看文件大小
    ping不通判断系统是否开机
    ping不通判断系统是否开机
    linux压缩解压文件命令
    python连接redis集群,添加数据
    初学python
    企业级BI为什么这么难做?
  • 原文地址:https://www.cnblogs.com/tony-yang-flutter/p/15381227.html
Copyright © 2011-2022 走看看