当前位置:网站首页>28. contour discovery
28. contour discovery
2022-06-26 01:36:00 【Nightmare satiety】
#include <opencv2/opencv.hpp>
#include <iostream>
int threshold_value = 100;
int threshold_max = 255;
cv::RNG rng;
cv::Mat src, dst;
void Demo_Contours(int, void*);
int main(int argc, char** argv){
src = cv::imread("../../source/happyfish.png");
if(src.empty()){
std::cout << "could not load image..." << std::endl;
return -1;
}
cv::namedWindow("src");
cv::namedWindow("output");
cv::imshow("src", src);
cv::cvtColor(src, src, cv::COLOR_BGR2GRAY);
const char* trackbar_title = "Threshold Value";
cv::createTrackbar(trackbar_title, "output", &threshold_value, threshold_max, Demo_Contours);
Demo_Contours(0, 0);
cv::waitKey();
}
void Demo_Contours(int, void*){
cv::Mat canny_out;
std::vector<std::vector<cv::Point>> contours;
std::vector<cv::Vec4i> hierachy;
cv::Canny(src, canny_out, threshold_value, threshold_value * 2, 3, false);
cv::findContours(canny_out, contours, hierachy, cv::RETR_TREE, cv::CHAIN_APPROX_SIMPLE, cv::Point(0, 0));
dst = cv::Mat::zeros(src.size(), CV_8UC3);
rng(12345);
for(int i = 0; i < contours.size(); i++){
cv::Scalar color = cv::Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
cv::drawContours(dst, contours, i, color, 2, 8, hierachy, 0);
}
cv::imshow("output", dst);
}
边栏推荐
- 2021-1-15 摸鱼做的笔记Ctrl+c /v来的
- Etcd database source code analysis cluster communication initialization
- RT-Thread 项目工程搭建和配置--(Env Kconfig)
- Digital circuit - adder
- 集合集合!!快来复习--mysql增删改查,内、左右连接 复习笔记
- "Hot post" Statistics
- 数据分析——切片器、数据透视表与数据透视图(职场必备)
- 物联网?快来看 Arduino 上云啦
- containerd客户端比较
- RT thread project engineering construction and configuration - (Env kconfig)
猜你喜欢
Development and monitoring of fusion experiment pulse power supply by LabVIEW
《网络是怎么样连接的》读书笔记 - 集线器、路由器和路由器(三)
Essence and thoughts of 30 lectures on product thinking
STM32GPIO
数组中的第K个最大元素
RT-Thread 项目工程搭建和配置--(Env Kconfig)
“热帖”统计
Etcd database source code analysis cluster communication initialization
New library launched | cnopendata China new house information data
Musk vs. jobs, who is the greatest entrepreneur in the 21st century
随机推荐
Test questions and answers for the 2022 baby sitter (Level 5) examination
计算机网络知识总结(面试)
I2C protocol
MySQL例题一 综合案例(多条件组合查询)
Oracle常用的基础命令
Region of Halcon: generation of multiple regions (4)
新库上线 | CnOpenData农产品批发价格数据
Nacos registry
Idea configuration
FIFO code implemented in C language
Reading notes on how to connect the network - hubs, routers and routers (III)
MySQL example - comprehensive case (multi condition combined query)
如何有效地推广产品
2022安徽省安全员C证考试练习题模拟考试平台操作
From query database performance optimization to redis cache - talk about cache penetration, avalanche and breakdown
《网络是怎么样连接的》读书笔记 - 集线器、路由器和路由器(三)
New library launched | cnopendata wholesale price data of agricultural products
JSON introduction
Set set!! Review quickly -- MySQL addition, deletion, modification and query, internal, left and right connection review notes
100ask seven day IOT training camp learning notes - bare metal program framework design