How to determine a region of interest and then crop an image using OpenCV(如何确定感兴趣的区域,然后使用 OpenCV 裁剪图像)
本文介绍了如何确定感兴趣的区域,然后使用 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);/
织梦狗教程
本文标题为:如何确定感兴趣的区域,然后使用 OpenCV 裁剪图像


基础教程推荐
猜你喜欢
- 初始化列表*参数*评估顺序 2021-01-01
- CString 到 char* 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01