zoukankan      html  css  js  c++  java
  • opencvconnectedComponents连通区域标识

    1.png图片

        cv::Mat roiImg = cv::imread("D:/bb/tu1/1.png");
            
        cv::Mat thrImg;
        cvtColor(roiImg, thrImg, cv::COLOR_BGR2GRAY);
        
        cv::threshold(thrImg, thrImg, 0, 255, cv::THRESH_OTSU);
        
        cv::namedWindow("roiImg1", cv::WINDOW_NORMAL);
        cv::imshow("roiImg1", thrImg);
    
        cv::Mat out;
        int number = cv::connectedComponents(thrImg, out, 8, CV_16U);  //连通区域标识
        //作用:二值图中不同连通域用不同数值来表示,0是背景区域
        //参数1:输入图像--必须二值图
        //参数2:输出图像
        //参数3:连通区域计算方式(4连通 or 8连通)
        //参数4:图像类型(CV_16U or CV_32S)
        //返回值:目标矩阵中有几种数据
    
    
    
        std::cerr << thrImg << std::endl;
        std::cerr << out << std::endl;
        std::cerr << "number=" << number << std::endl;
    
        cv::waitKey();

     

  • 相关阅读:
    Go视频教程
    Mysql常用
    同步Redux
    React跨组件通讯
    React组件通讯
    React
    git生成公钥和私钥
    常用经典算法---希尔排序
    string和c_str()使用时的坑
    腾讯云python网站开发环境搭建
  • 原文地址:https://www.cnblogs.com/liming19680104/p/15449293.html
Copyright © 2011-2022 走看看