opencv31联通阈分析
来源:互联网 发布:数据恢复精灵收费吗 编辑:程序博客网 时间:2024/05/05 09:36
此程序为opencv自带例程
#include <opencv2/core/utility.hpp>#include "opencv2/imgproc.hpp"#include "opencv2/imgcodecs.hpp"#include "opencv2/highgui.hpp"#include <iostream>using namespace cv;using namespace std;Mat img;int threshval = 100;static void on_trackbar(int, void*){Mat bw = threshval < 128 ? (img < threshval) : (img > threshval);Mat labelImage(img.size(), CV_32S);int nLabels = connectedComponents(bw, labelImage, 8);std::vector<Vec3b> colors(nLabels);colors[0] = Vec3b(0, 0, 0);//backgroundfor (int label = 1; label < nLabels; ++label) {colors[label] = Vec3b((rand() & 255), (rand() & 255), (rand() & 255));}Mat dst(img.size(), CV_8UC3);for (int r = 0; r < dst.rows; ++r) {for (int c = 0; c < dst.cols; ++c) {int label = labelImage.at<int>(r, c);Vec3b &pixel = dst.at<Vec3b>(r, c);pixel = colors[label];}}imshow("Connected Components", dst);}static void help(){cout << "\n This program demonstrates connected components and use of the trackbar\n""Usage: \n"" ./connected_components <image(../data/stuff.jpg as default)>\n""The image is converted to grayscale and displayed, another image has a trackbar\n""that controls thresholding and thereby the extracted contours which are drawn in color\n";}const char* keys ={"{help h||}{@image|../data/stuff.jpg|image for converting to a grayscale}"};int main(int argc, const char** argv){CommandLineParser parser(argc, argv, keys);if (parser.has("help")){help();return 0;}string inputImage = parser.get<string>(0);//img = imread(inputImage.c_str(), 0);img = imread("G:\\opencv31\\opencv\\sources\\samples\\data\\pic1.png", 0);if (img.empty()){cout << "Could not read input image file: " << inputImage << endl;return -1;}namedWindow("Image", 1);imshow("Image", img);namedWindow("Connected Components", 1);createTrackbar("Threshold", "Connected Components", &threshval, 255, on_trackbar);on_trackbar(threshval, 0);waitKey(0);return 0;}
效果如下。代码慢慢看吧。
0 0
- opencv31联通阈分析
- 联通、移动、电信分析
- 联通
- 联通手机营业厅AndroidV4_0_1分析(一)
- 联通手机营业厅AndroidV4_0_1分析(二)
- 记事本保存“联通”的原理分析
- 中国移动真正比联通强的原因【原理分析】
- 分析师:联通可能已达成iPhone独家协议
- 【协议分析】移动联通电信CMwap地址和端口
- 记一次联通路由器劫持的分析过程
- 基于opencv31 下的KCF 跟踪在windows 下的测试
- 联通手机卡
- 联通入网
- 联通3G
- 二级联通
- 双联通
- 联通数据业务
- ip 联通
- 高性能网络编程7--tcp连接的内存使用
- MySQL 导入、导出备份 mysqldump工具用法
- 微信公众号开发前期基本配置-ngrok映射
- windows核心编程-CreateProcess创建进程
- ffmpeg学习一:启动篇(学习计划与环境搭建)
- opencv31联通阈分析
- hdu2087剪花布条
- 新人零基础学习HTML5五步走
- 色阶变换做的一个颜色渐变效果
- 把自己的可执行文件push到adb下system/bin/下
- 百度url 参数详解全
- Active Directory的脱机碎片整理,Active Directory系列之七
- Fast RCNN训练自己的数据集 (2修改读写接口)
- C#软件注册和注册(参考)