• 寻找轮廓的中点


    主要是回答网友提问,同时回顾主要知识。
     
    #include "stdafx.h"
    #include <opencv2/core/utility.hpp>
    #include "opencv2/imgproc.hpp"
    #include "opencv2/videoio.hpp"
    #include "opencv2/highgui.hpp"
    #include "GOCVHelper.h"
     
    using namespace cv;
    using namespace std;
    using namespace GO;
     
    RNG rng12345(12345);
    int main()
    {
        Mat matSrc = imread("e:/sandbox/shapes_and_colors.jpg",0);
        GaussianBlur(matSrc,matSrc,Size(5,5),0);
        vector<vector<Point> > contours;
        vector<Vec4ihierarchy;
        //阈值
        threshold(matSrc,matSrc,60,255,THRESH_BINARY);
        //寻找轮廓
        findContours(matSrc.clone(),contours,hierarchyRETR_EXTERNAL,CHAIN_APPROX_SIMPLE,Point(0, 0) );
        /// 计算矩
        vector<Momentsmu(contours.size() );
        forint i = 0; i < contours.size(); i++ )
        { mu[i] = momentscontours[i], false ); }
        ///  计算中心矩:
        vector<Point2fmccontours.size() );
        forint i = 0; i < contours.size(); i++ )
        { mc[i] = Point2fmu[i].m10/mu[i].m00 , mu[i].m01/mu[i].m00 ); }
        /// 绘制轮廓
        Mat drawing = Mat::zerosmatSrc.size(), CV_8UC3 );
        forint i = 0; icontours.size(); i++ )
        {
            Scalar color = Scalarrng12345.uniform(0, 255), rng12345.uniform(0,255), rng12345.uniform(0,255) );
            drawContoursdrawingcontoursicolor, 2, 8, hierarchy, 0, Point() );
            circledrawingmc[i], 4, color, -1, 8, 0 );
        }
        waitKey();
        return 0;
     
    };
     
  • 相关阅读:
    串口通信(2)
    串口通信(1)
    extern关键字的使用
    volatile关键字的使用
    Uart串口与RS232串口的区别
    DSP5509的时钟发生器(翻译总结自TI官方文档)
    DSP中的cmd文件
    pragma伪指令
    在C语言中嵌入汇编语言
    another app is currently holding the yum lock;waiting for it to exit...
  • 原文地址:https://www.cnblogs.com/jsxyhelu/p/7967484.html
Copyright © 2020-2023  润新知