如何确定感兴趣的区域,然后使用 OpenCV 裁剪图像

2023-01-21C/C++开发问题
12

本文介绍了如何确定感兴趣的区域,然后使用 OpenCV 裁剪图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在操作.

在那之后,Mat 上进行简单的迭代来寻找角落像素 是微不足道的,我在 回答.

#include #include int main(int argc, char* argv[]){cv::Mat img = cv::imread(argv[1]);std::cout <<原始图像尺寸:" <积分;cv::Mat_::iterator it = gray.begin();cv::Mat_::iterator end = gray.end();for (; it != end; it++){如果它)points.push_back(it.pos());}//从这些点,算出ROI的大小int 左、右、上、下;for (int i = 0; i  右)右 = 点 [i].x;if (points[i].y < top)顶部 = 点 [i].y;如果(点 [i].y > 底部)底部 = 点 [i].y;}std::vectorbox_points;box_points.push_back(cv::Point(left, top));box_points.push_back(cv::Point(left, bottom));box_points.push_back(cv::Point(right, bottom));box_points.push_back(cv::Point(right, top));//计算 ROI 的最小边界框//注意:由于某些未知原因,框的宽度/高度发生了切换.cv::RotatedRect box = cv::minAreaRect(cv::Mat(box_points));std::cout <<框 w:"<<box.size.width <<" h:" <<box.size.height <<std::endl;//在原始图像中绘制边界框(调试目的)//cv::Point2f 顶点[4];//box.points(vertices);//for (int i = 0; i <4; ++i)//{//cv::line(img, vertices[i], vertices[(i + 1) % 4], cv::Scalar(0, 255, 0), 1, CV_AA);/
The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&amp;()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6