C++ 求一个区域中最长的垂直向量
我有一个轮廓,我需要找到它的长度和高度,定义为:C++ 求一个区域中最长的垂直向量,c++,opencv,C++,Opencv,我有一个轮廓,我需要找到它的长度和高度,定义为: 宽度是轮廓中最长的向量 高度是与宽度垂直的最长矢量 查找宽度实际上非常简单: std::vector<std::vector<cv::Point>> contours; cv::findContours(mask_in_rect, contours, cv::RETR_TREE, cv::CHAIN_APPROX_NONE); for (auto point1 : contours[0]) for (auto
- 宽度是轮廓中最长的向量
- 高度是与宽度垂直的最长矢量
std::vector<std::vector<cv::Point>> contours;
cv::findContours(mask_in_rect, contours, cv::RETR_TREE, cv::CHAIN_APPROX_NONE);
for (auto point1 : contours[0])
for (auto point2 : contours[0])
{
if (Wlongest.length() < Vector(point1, point2).length())
{
Wlongest = Vector(point1, point2);
}
}
但我不知道如何继续。所以基本上只需要找到定向边界框。。。cv::rotatedRect(您的_点)
auto M = cv::getRotationMatrix2D({mask_in_rect.cols / 2.0f, mask_in_rect.rows / 2.0f}, -Wlongest.angle(), 1.0f);
auto Minv = cv::getRotationMatrix2D({mask_in_rect.cols / 2.0f, mask_in_rect.rows / 2.0f}, Wlongest.angle(), 1.0f);