List<MatOfPoint> contours = new ArrayList<>(); 遍历

时间: 2023-08-04 13:11:49 浏览: 52
遍历 `contours` 中的所有元素的代码可以使用 Java 的 for-each 循环实现,示例代码如下: ``` for (MatOfPoint contour : contours) { // 在这里对每个 contour 进行操作 } ``` 这段代码会将 `contours` 中的每个元素都赋值给 `contour` 变量,然后在循环体中对其进行操作。注意,`contour` 的类型是 `MatOfPoint`,即一个由点组成的矩阵。你可以通过 `contour.toArray()` 方法获取矩阵中的所有点,进而对它们进行处理。
相关问题

vector<vector<Point>> contours;

`vector<vector<Point>> contours;`是一个C++中的定义,表示一个双重向量,其中每个元素都是一个由连续的Point点构成的点的集合的向量。这个双重向量被称为`contours`,它保存了多个轮廓,每个轮廓都是一个由连续的Point点构成的点的集合。 范例: ```cpp #include <iostream> #include <vector> #include <opencv2/opencv.hpp> int main() { std::vector<std::vector<cv::Point>> contours; // 添加轮廓数据到contours中 // 输出轮廓数量 std::cout << "轮廓数量:" << contours.size() << std::endl; return 0; } ```

其中的vector<vector<Point>> contours;什么意思

`vector<vector<Point>> contours` 是一个存储轮廓的容器,其中每个轮廓都是一个由 `Point` 类型点组成的向量,因此 `vector<Point>` 表示一个轮廓,而 `vector<vector<Point>>` 表示多个轮廓的集合。在图像处理中,轮廓是图像中一些特定形状的边界线,可以用来做形状识别、物体检测等任务。在使用 OpenCV 进行轮廓检测时,检测结果会以 `vector<vector<Point>>` 的形式返回,其中每个轮廓是一个 `vector<Point>` 类型的向量,每个点表示轮廓上的一个像素点。

相关推荐

代码解释:public static Vector<Mat> findPlateByContours(Mat src, Mat inMat, Vector<Mat> dst, Boolean debug, String tempPath) { // 灰度图 Mat gray = new Mat(); ImageUtil.gray(inMat, gray, debug, tempPath); Imgcodecs.imwrite(tempPath + Constant.TEMP_GRAY, gray); // 高斯模糊 Mat gsMat = new Mat(); ImageUtil.gaussianBlur(gray, gsMat, debug, tempPath); Imgcodecs.imwrite(tempPath + Constant.TEMP_GAUSSIAN, gsMat); // Sobel 运算,得到图像的一阶水平方向导数 Mat sobel = new Mat(); ImageUtil.sobel(gsMat, sobel, debug, tempPath); Imgcodecs.imwrite(tempPath + Constant.TEMP_SOBEL, sobel); // 图像进行二值化 Mat threshold = new Mat(); ImageUtil.threshold(sobel, threshold, debug, tempPath); Imgcodecs.imwrite(tempPath + Constant.TEMP_THRESHOLD, threshold); // 使用闭操作 同时处理一些干扰元素 Mat morphology = threshold.clone(); ImageUtil.morphologyClose(threshold, morphology, debug, tempPath); // 闭操作 Imgcodecs.imwrite(tempPath + Constant.TEMP_CLOSE, morphology); // 边缘腐蚀,边缘膨胀,可以多执行两次 morphology = ImageUtil.erode(morphology, debug, tempPath, 4, 4); Imgcodecs.imwrite(tempPath + Constant.TEMP_ERODE, morphology); morphology = ImageUtil.dilate(morphology, debug, tempPath, 4, 4, true); Imgcodecs.imwrite(tempPath + Constant.TEMP_DILATE, morphology); // 保存结果到目标文件 // 将二值图像,resize到原图的尺寸; 如果使用缩小后的图片提取图块,可能会出现变形,影响后续识别结果 ImageUtil.enlarge(morphology, morphology, src.size(), debug, tempPath); Imgcodecs.imwrite(tempPath + Constant.TEMP_RESIZE, morphology); // 获取图中所有的轮廓 List<MatOfPoint> contours = ImageUtil.contours(src, morphology, debug, tempPath); Imgcodecs.imwrite(tempPath + Constant.TEMP_CONTOUR, morphology); // 根据轮廓, 筛选出可能是车牌的图块 Vector<Mat> blockMat = ImageUtil.screenBlock(src, contours, false, debug, tempPath); // 找出可能是车牌的图块,存到dst中, 返回结果 hasPlate(blockMat, dst, debug, tempPath + "contour/"); return dst; }

代码解释:public static String charsSegment(Mat inMat, PlateColor color, Boolean debug, String tempPath) { int charCount = 7; // 车牌字符个数 if (color.equals(PlateColor.GREEN)) { charCount = 8; } // 切换到灰度图 Mat gray = new Mat(); Imgproc.cvtColor(inMat, gray, Imgproc.COLOR_BGR2GRAY); ImageUtil.gaussianBlur(gray, gray, debug, tempPath); Imgcodecs.imwrite(tempPath + Constant.TEMP_CHAR_PLATE_PREDICT, gray); // 图像进行二值化 Mat threshold = new Mat(); switch (color) { case BLUE: Imgproc.threshold(gray, threshold, 10, 255, Imgproc.THRESH_OTSU + Imgproc.THRESH_BINARY); break; default: // GREEN YELLOW Imgproc.threshold(gray, threshold, 10, 255, Imgproc.THRESH_OTSU + Imgproc.THRESH_BINARY_INV); break; } ImageUtil.debugImg(debug, tempPath, "plateThreshold", threshold); // 输出二值图 Imgcodecs.imwrite(tempPath + Constant.TEMP_CHAR_PLATE_PREDICT, threshold); // 边缘腐蚀 threshold = ImageUtil.erode(threshold, debug, tempPath, 2, 2); Imgcodecs.imwrite(tempPath + Constant.TEMP_CHAR_ERODE, threshold); // 垂直方向投影,错切校正 // 理论上,还可以用于分割字符 Integer px = getShearPx(threshold); ImageUtil.shearCorrection(threshold, threshold, px, debug, tempPath); // 前面已经结果错切校正了,可以按照垂直、水平方向投影进行精确定位 // 垂直投影 + 垂直分割线,分割字符 // 水平投影,去掉上下边框、铆钉干扰 threshold = sepAndClear(threshold, px, charCount, debug, tempPath); Imgcodecs.imwrite(tempPath + Constant.TEMP_CHAR_SEP_AND_CLEAR, threshold); // 边缘膨胀 // 还原腐蚀操作产生的影响 // 会影响中文字符的精确度 threshold = ImageUtil.dilate(threshold, debug, tempPath, 2, 2, true); Imgcodecs.imwrite(tempPath + Constant.TEMP_CHAR_DILATE, threshold); // 提取外部轮廓 List<MatOfPoint> contours = Lists.newArrayList(); Imgproc.findContours(threshold, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_NONE); Vector<Rect> charRect = new Vector<Rect>(); // 字符轮廓集合 Mat dst; dst = inMat.clone(); Imgproc.cvtColor(threshold, dst, Imgproc.COLOR_GRAY2BGR); if (debug) {

最新推荐

recommend-type

###对华为OD分布式操作系统的详细介绍

华为OD
recommend-type

2110220116吴骏博.py

2110220116吴骏博.py
recommend-type

基于Java的ApplicationPower快速项目生成脚手架设计源码

ApplicationPower项目生成脚手架设计源码:该项目基于Java开发,包含284个文件,主要使用Java和Shell语言。ApplicationPower是一个快速的项目生成脚手架,旨在帮助开发者快速搭建项目框架,包括创建项目结构、配置文件、开发环境等,提高开发效率。
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用遗传算法改进粒子群GA-PSO算法

![MATLAB智能算法合集](https://static.fuxi.netease.com/fuxi-official/web/20221101/83f465753fd49c41536a5640367d4340.jpg) # 2.1 遗传算法的原理和实现 遗传算法(GA)是一种受生物进化过程启发的优化算法。它通过模拟自然选择和遗传机制来搜索最优解。 **2.1.1 遗传算法的编码和解码** 编码是将问题空间中的解表示为二进制字符串或其他数据结构的过程。解码是将编码的解转换为问题空间中的实际解的过程。常见的编码方法包括二进制编码、实数编码和树形编码。 **2.1.2 遗传算法的交叉和
recommend-type

openstack的20种接口有哪些

以下是OpenStack的20种API接口: 1. Identity (Keystone) API 2. Compute (Nova) API 3. Networking (Neutron) API 4. Block Storage (Cinder) API 5. Object Storage (Swift) API 6. Image (Glance) API 7. Telemetry (Ceilometer) API 8. Orchestration (Heat) API 9. Database (Trove) API 10. Bare Metal (Ironic) API 11. DNS
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

【实战演练】时间序列预测用于个体家庭功率预测_ARIMA, xgboost, RNN

![【实战演练】时间序列预测用于个体家庭功率预测_ARIMA, xgboost, RNN](https://img-blog.csdnimg.cn/img_convert/5587b4ec6abfc40c76db14fbef6280db.jpeg) # 1. 时间序列预测简介** 时间序列预测是一种预测未来值的技术,其基于历史数据中的时间依赖关系。它广泛应用于各种领域,例如经济、金融、能源和医疗保健。时间序列预测模型旨在捕捉数据中的模式和趋势,并使用这些信息来预测未来的值。 # 2. 时间序列预测方法 时间序列预测方法是利用历史数据来预测未来趋势或值的统计技术。在时间序列预测中,有许多不