我在操作.
在那之后,在 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);/