zoukankan      html  css  js  c++  java
  • OpenCV 多边形逼近

    approxPolyDP(contours, Curve, epsilon, true);

     InputArray contours:输入的点集;
    OutputArray Curve:输出的点集,当前点集是能最小包容指定点集的。画出来即是一个多边形;
    double epsilon:指定的精度,也即是原始曲线与近似曲线之间的最大距离;
    bool closed:若为true,则说明近似曲线是闭合的,反之,若为false,则断开。

    #include<opencv2/opencv.hpp>
    #include<iostream>
    
    using namespace std;
    using namespace cv;
    
    void main()
    {
        Mat img = imread("E:/1.jpg",0);
        imshow("img", img);
        Mat img_out(img.size(), CV_8UC3, Scalar::all(0));//纯黑图像
        threshold(img, img, 200, 255,THRESH_OTSU );
        vector<vector<Point>> contours;
        vector<Vec4i> hierarcy;
        findContours(img, contours, hierarcy, 0, CHAIN_APPROX_NONE);
        vector<vector<Point>> contours_poly(contours.size());//用于存放折线点集
        for (int i = 0; i < contours.size(); i++)
        {
            approxPolyDP(Mat(contours[i]), contours_poly[i],2, true);
    
            drawContours(img_out, contours_poly, i, Scalar(0, 255, 255), 2, 8);  //绘制
        }
        imshow("approx", img_out);
        waitKey(0);
    }

  • 相关阅读:
    图算法之广度优先遍历
    图形算法之深度优先遍历
    list下SORT排序方法使用
    Linux使用curl进行接口测试
    Template方法应用
    profile[计算方法耗时模块]用法
    性能测试的实施及总结(二)
    yum源配置
    Dockerfile文件
    Docker的Image与Container
  • 原文地址:https://www.cnblogs.com/hsy1941/p/11282229.html
Copyright © 2011-2022 走看看