//显示结果 imshow("轮廓绘制结果", edge); vector<Point2f>point_0; vector<Point2f>point_1; vector<Point2f>point_2; vector<Point2f>point_3; vector<Point2f>point_4; vector<Point2f>point_5; vector<Point2f>point_6; vector<Point2f>point_7; vector<Point2f>point_8; vector<Point2f>point_9; vector<Point2f>point_10; vector<Point2f>point_11; vector<Point2f>point_12; vector<Point2f>point_13; vector<Point2f>point_14; vector<Point2f>point_15; vector<Point2f>point_16; vector<Point2f>point_17; vector<Point2f>point_18; vector<Point2f>point_19;

时间: 2023-06-27 12:06:06 浏览: 38
这段代码是在定义多个vector变量,每个vector变量都存储了图像中的某个轮廓的关键点坐标。这些变量的命名中包含了数字,可能是因为这些关键点所属的轮廓编号。在这段代码中,只是定义了这些vector变量,但是并没有进行赋值操作。同时,代码中还展示了一个名为"轮廓绘制结果"的窗口,将图像中的轮廓绘制出来并显示出来。
相关问题

#include <opencv2/opencv.hpp>#include <iostream>using namespace std;using namespace cv;int main(){ // 读取图像并进行预处理 Mat src = imread("test.jpg"); Mat gray, binary; cvtColor(src, gray, COLOR_BGR2GRAY); threshold(gray, binary, 0, 255, THRESH_BINARY | THRESH_OTSU); imshow("binary", binary); // 计算轮廓 vector<vector<Point> > contours; vector<Vec4i> hierarchy; findContours(binary, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point()); // 计算中心、质心、重心、外接圆圆心 Point2f center, centroid, gravity, minEnclosingCircleCenter; Moments mu = moments(contours[0], false); center = Point2f(mu.m10 / mu.m00, mu.m01 / mu.m00); minEnclosingCircle(contours[0], minEnclosingCircleCenter, radius); centroid = Point2f(mu.m10 / mu.m00, mu.m01 / mu.m00); gravity = Point2f(mu.m10 / mu.m00, mu.m01 / mu.m00 + 50); // 绘制结果 Mat drawing = Mat::zeros(binary.size(), CV_8UC3); circle(drawing, center, 5, Scalar(0, 0, 255), -1); circle(drawing, centroid, 5, Scalar(0, 255, 0), -1); circle(drawing, gravity, 5, Scalar(255, 0, 0), -1); circle(drawing, minEnclosingCircleCenter, 5, Scalar(0, 255, 255), -1); imshow("result", drawing); waitKey(0); return 0;}添加更详细的注释

好的,下面是更详细的注释: ```c++ #include <opencv2/opencv.hpp> #include <iostream> using namespace std; using namespace cv; int main() { // 读取图像并进行预处理 Mat src = imread("test.jpg"); // 读取图像 Mat gray, binary; // 定义灰度图像和二值图像 cvtColor(src, gray, COLOR_BGR2GRAY); // 将图像转换为灰度图像 threshold(gray, binary, 0, 255, THRESH_BINARY | THRESH_OTSU); // 对灰度图像进行二值化 imshow("binary", binary); // 显示二值图像 // 计算轮廓 vector<vector<Point> > contours; // 定义轮廓 vector<Vec4i> hierarchy; // 定义轮廓的层次结构 findContours(binary, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point()); // 提取轮廓 // 计算中心、质心、重心、外接圆圆心 Point2f center, centroid, gravity, minEnclosingCircleCenter; // 定义中心、质心、重心、外接圆圆心 Moments mu = moments(contours[0], false); // 计算轮廓的矩 center = Point2f(mu.m10 / mu.m00, mu.m01 / mu.m00); // 计算中心 float radius; minEnclosingCircle(contours[0], minEnclosingCircleCenter, radius); // 计算外接圆 centroid = Point2f(mu.m10 / mu.m00, mu.m01 / mu.m00); // 计算质心 gravity = Point2f(mu.m10 / mu.m00, mu.m01 / mu.m00 + 50); // 计算重心 // 绘制结果 Mat drawing = Mat::zeros(binary.size(), CV_8UC3); // 创建一个空的彩色图像 circle(drawing, center, 5, Scalar(0, 0, 255), -1); // 绘制中心 circle(drawing, centroid, 5, Scalar(0, 255, 0), -1); // 绘制质心 circle(drawing, gravity, 5, Scalar(255, 0, 0), -1); // 绘制重心 circle(drawing, minEnclosingCircleCenter, 5, Scalar(0, 255, 255), -1); // 绘制外接圆圆心 imshow("result", drawing); // 显示绘制结果 waitKey(0); // 等待按键 return 0; } ``` 注释中对代码的各个部分进行了说明,使得代码更容易理解。

Mat imgthreshold; Mat imgsrc = cv::imread("C:/Users/Dell/Pictures/Camera Roll/6.png",0); imshow("imgsrc", imgsrc); threshold(imgsrc, imgthreshold,50, 110, THRESH_BINARY); imshow("imgthreshold", imgthreshold); vector<vector<Point>> contours; findContours(imgthreshold, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE); cv::Mat imgdraw = imgsrc.clone(); drawContours(imgdraw, contours, -1, (0, 0, 255),0); imshow("imgdraw", imgdraw); waitKey(0);为什么这块输出的是白色边框而不是红色

在绘制边框时,你应该传入一个 Scalar 类型的参数作为边框颜色,而不是一个元组或者一个数组。修改 drawContours 函数的第四个参数,将其改为 Scalar(0, 0, 255) 即可绘制红色边框,代码如下: ```c++ Mat imgthreshold; Mat imgsrc = cv::imread("C:/Users/Dell/Pictures/Camera Roll/6.png",0); imshow("imgsrc", imgsrc); threshold(imgsrc, imgthreshold,50, 110, THRESH_BINARY); imshow("imgthreshold", imgthreshold); vector<vector<Point>> contours; findContours(imgthreshold, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE); cv::Mat imgdraw = imgsrc.clone(); drawContours(imgdraw, contours, -1, Scalar(0, 0, 255), 1); // 修改这里 imshow("imgdraw", imgdraw); waitKey(0); ```

相关推荐

将下列代码转换成python代码 #include <opencv2/opencv.hpp> #include <vector> #include <time.h> using namespace cv; using namespace std; // 8邻域 const Point neighbors[8] = { { 0, 1 }, { 1, 1 }, { 1, 0 }, { 1, -1 }, { 0, -1 }, { -1, -1 }, { -1, 0 }, {-1, 1} }; int main() { // 生成随机数 RNG rng(time(0)); Mat src = imread("1.jpg"); Mat gray; cvtColor(src, gray, CV_BGR2GRAY); Mat edges; Canny(gray, edges, 30, 100); vector seeds; vector contour; vector<vector> contours; int i, j, k; for (i = 0; i < edges.rows; i++) for (j = 0; j < edges.cols; j++) { Point c_pt = Point(i, j); //如果当前点为轮廓点 if (edges.at<uchar>(c_pt.x, c_pt.y) == 255) { contour.clear(); // 当前点清零 edges.at<uchar>(c_pt.x, c_pt.y) = 0; // 存入种子点及轮廓 seeds.push_back(c_pt); contour.push_back(c_pt); // 区域生长 while (seeds.size() > 0) { // 遍历8邻域 for (k = 0; k < 8; k++) { // 更新当前点坐标 c_pt.x = seeds[0].x + neighbors[k].x; c_pt.y = seeds[0].y + neighbors[k].y; // 边界界定 if ((c_pt.x >= 0) && (c_pt.x <= edges.rows - 1) && (c_pt.y >= 0) && (c_pt.y <= edges.cols - 1)) { if (edges.at<uchar>(c_pt.x, c_pt.y) == 255) { // 当前点清零 edges.at<uchar>(c_pt.x, c_pt.y) = 0; // 存入种子点及轮廓 seeds.push_back(c_pt); contour.push_back(c_pt); }// end if } } // end for // 删除第一个元素 seeds.erase(seeds.begin()); }// end while contours.push_back(contour); }// end if } // 显示一下 Mat trace_edge = Mat::zeros(edges.rows, edges.cols, CV_8UC1); Mat trace_edge_color; cvtColor(trace_edge, trace_edge_color, CV_GRAY2BGR); for (i = 0; i < contours.size(); i++) { Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)); //cout << edges[i].size() << endl; // 过滤掉较小的边缘 if (contours[i].size() > 5) { for (j = 0; j < contours[i].size(); j++) { trace_edge_color.at<Vec3b>(contours[i][j].x, contours[i][j].y)[0] = color[0]; trace_edge_color.at<Vec3b>(contours[i][j].x, contours[i][j].y)[1] = color[1]; trace_edge_color.at<Vec3b>(contours[i][j].x, contours[i][j].y)[2] = color[2]; } } } imshow("edge", trace_edge_color); waitKey(); return 0; }

class SR_net { public: SR_net(string path, vector<int> input_size, bool fp32, bool cuda = true); private: vector<int64_t> Gdims; int Gfp32; Env env = Env(ORT_LOGGING_LEVEL_ERROR, "RRDB"); SessionOptions session_options = SessionOptions(); Session* Gsession = nullptr; vector<const char*> Ginput_names; vector<const char*> Goutput_names; vector<int> Ginput_size = {}; }; SR_net::SR_net(string path, vector<int> input_size, bool fp32, bool cuda) { this->Ginput_size = input_size; this->Gfp32 = fp32; clock_t startTime_, endTime_; startTime_ = clock(); session_options.SetIntraOpNumThreads(6); if (cuda) { OrtCUDAProviderOptions cuda_option; cuda_option.device_id = 0; cuda_option.arena_extend_strategy = 0; cuda_option.cudnn_conv_algo_search = OrtCudnnConvAlgoSearchExhaustive; cuda_option.gpu_mem_limit = SIZE_MAX; cuda_option.do_copy_in_default_stream = 1; session_options.AppendExecutionProvider_CUDA(cuda_option); } wstring widestr = wstring(path.begin(), path.end()); this->Gsession = new Session(env, widestr.c_str(), this->session_options); this->session_options.SetGraphOptimizationLevel(GraphOptimizationLevel::ORT_ENABLE_ALL); AllocatorWithDefaultOptions allocator; this->Ginput_names = { "input" }; this->Goutput_names = { "output" }; endTime_ = clock(); cout << " The model loading time is:" << (double)(endTime_ - startTime_) / CLOCKS_PER_SEC << "s" << endl; } int main() { vector<int> input_shape = {}; SR_net net("E:/prj/SR_C/onnx_file/rrdb_full.onnx", input_shape, true, true); vector<String> files; glob("E:/prj/超分样本/1", files, true); size_t num = files.size(); bool Moos = true; cout << "共读取了" << num << "张图片" << endl; cout << "--------------------------------" << endl; for (int i = 0; i < num; i++) { Mat srcimg = imread(files[i]); Mat SR_image = net.Detect(srcimg, Moos); imshow("input", srcimg); imshow("result", SR_image); imwrite("./output/" + to_string(i + 1) + ".png", SR_image); waitKey(0); } },在这段代码中,我如何把SR_net net("E:/prj/SR_C/onnx_file/rrdb_full.onnx", input_shape, true, true);这一行写到主函数的外面?

最新推荐

recommend-type

解决python中显示图片的plt.imshow plt.show()内存泄漏问题

主要介绍了解决python中显示图片的plt.imshow plt.show()内存泄漏问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
recommend-type

新建文本文档.txt

新建文本文档
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

HSV转为RGB的计算公式

HSV (Hue, Saturation, Value) 和 RGB (Red, Green, Blue) 是两种表示颜色的方式。下面是将 HSV 转换为 RGB 的计算公式: 1. 将 HSV 中的 S 和 V 值除以 100,得到范围在 0~1 之间的值。 2. 计算色相 H 在 RGB 中的值。如果 H 的范围在 0~60 或者 300~360 之间,则 R = V,G = (H/60)×V,B = 0。如果 H 的范围在 60~120 之间,则 R = ((120-H)/60)×V,G = V,B = 0。如果 H 的范围在 120~180 之间,则 R = 0,G = V,B =
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

MATLAB柱状图在数据分析中的作用:从可视化到洞察

![MATLAB柱状图在数据分析中的作用:从可视化到洞察](https://img-blog.csdnimg.cn/img_convert/1a36558cefc0339f7836cca7680c0aef.png) # 1. MATLAB柱状图概述** 柱状图是一种广泛用于数据可视化的图表类型,它使用垂直条形来表示数据中不同类别或组别的值。在MATLAB中,柱状图通过`bar`函数创建,该函数接受数据向量或矩阵作为输入,并生成相应的高度条形。 柱状图的优点在于其简单性和易于理解性。它们可以快速有效地传达数据分布和组别之间的比较。此外,MATLAB提供了广泛的定制选项,允许用户调整条形颜色、
recommend-type

已知自动控制原理中通过更高的频率特征来评估切割频率和库存——相位稳定。确定封闭系统的稳定性。求Wcp 和ψ已知W(p)=30•(0.1p+1)•(12.5p+1)/p•(10p+1)•(0.2p+1)•(p+1)

根据相位稳定的定义,我们需要找到一个频率 Wcp,使得相位满足 -ψ = -180°,即 ψ = 180°。此时系统的相位裕度为 0°,系统处于边缘稳定状态。 首先,我们需要将 W(p) 表示成极点和零点的形式。将分母和分子分别因式分解,得到: W(p) = 30 • (0.1p+1) • (12.5p+1) / [p • (10p+1) • (0.2p+1) • (p+1)] = 375p/(p+1) - 3750/(10p+1) + 750p/(0.2p+1) - 3750p/(10p+1) + 150p/(p+1) + 30 因此,系统的极点为 -1、-0.1、-0.2、