zoukankan      html  css  js  c++  java
  • OpenCV (六)绘制图形

    常用的图形绘制代码即结果如下:

    #include<opencv2/opencv.hpp>
    #include<iostream>
    
    using namespace std;
    using namespace cv;
    
    int main(int argc, char** argv) {
    Mat image = imread("D:/OpenCVprj/image/test3.jpg");
    namedWindow("image", CV_WINDOW_AUTOSIZE);
    //line
    Point p1;
    p1.x = image.cols;
    p1.y = image.rows;
    Point p2 = Point(0, 0);
    Scalar color = Scalar(0, 0, 255);
    line(image, p1, p2, color, 1, LINE_8);
    
    //rectangle
    Scalar color1 = Scalar(0, 255, 0);
    Rect rect = Rect(image.cols / 4, image.rows / 4, 2*image.cols / 4, 2*image.rows/4);
    rectangle(image, rect, color1, 3, LINE_8);
    
    //ellipse 椭圆
    Scalar color2 = Scalar(255, 0, 0);
    //90,表示旋转90°, 0,360, 表示画的弧大小, 1表示线粗细
    ellipse(image, Point(image.cols/2, image.rows/2), Size(image.cols/4, image.rows/8), 90, 0, 360, color2, 1, LINE_8);
    
    //circle
    Scalar color3 = Scalar(255, 255, 0);
    circle(image, Point(image.cols/2, image.rows/2), 200, color3, 5, LINE_8);
    
    //fillpoly
    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 color4 = Scalar(255, 0, 255);
    fillPoly(image, ppts, npt, 1,color4, LINE_8);
    
    //text
    Scalar color5 = Scalar(0, 255, 0);
    putText(image, "Hello OpenCV", Point(100, image.rows/2), CV_FONT_HERSHEY_COMPLEX, 2, color5);
    
    imshow("image", image);
    waitKey(0);
    return 0;
    }
    

      

  • 相关阅读:
    排序算法
    chrome
    2017年末思考
    phpstorm修改创建文件时的默认注释
    男人
    Easyui-Tree和Combotree使用注意事项-sunziren
    Easyui-Treegrid使用注意事项-sunziren
    在生产环境中碰见的JSP木马-sunziren
    JS实现粒子拖拽吸附特效-sunziren
    双向链表的简单Java实现-sunziren
  • 原文地址:https://www.cnblogs.com/haiboxiaobai/p/11226186.html
Copyright © 2011-2022 走看看