1 | initial version |
So you have the lengths of the detected segments. Now you need to filter them. For example you can create a function that for an input vector<vec4i>
it returns another vector<vec4i>
that has just the lines longer than a parameter:
std::vector<cv::vec4i> filterLinesByLen(const std::vector<cv::vec4i>& lines, double minLen)
{
std::vector<cv::vec4i> longLines;
for (cv::vec4i line : lines)
{ if (euclidDist(line) >= minLen) { longLines.push_back(line); } }
return longLines;
}
2 | No.2 Revision |
So you have the lengths of the detected segments. Now you need to filter them. For example you can create a function that for an input vector<vec4i>
it returns another vector<vec4i>
that has just the lines longer than a parameter:
std::vector<cv::vec4i> std::vector<cv::Vec4i> filterLinesByLen(const std::vector<cv::vec4i>& std::vector<cv::Vec4i>& lines, double minLen)
{
std::vector<cv::vec4i> longLines;
for (cv::vec4i (cv::Vec4i line : lines)
{ if (euclidDist(line) >= minLen) { longLines.push_back(line); } }
return longLines;
}
the eucldian distance shoud be something like:
double euclidDist(const cv::Vec4i& line)
{
return std::sqtr(static_cast<double>((line[0] - line[2]) * (line[0] - line[2]) + (line[1] - line[3]) * (line[1] - line[3])));
}
3 | No.3 Revision |
So you have the lengths of the detected segments. Now you need to filter them. For example you can create a function that for an input vector<vec4i>
it returns another vector<vec4i>
that has just the lines longer than a parameter:
std::vector<cv::Vec4i> filterLinesByLen(const std::vector<cv::Vec4i>& lines, double minLen)
{
std::vector<cv::vec4i> longLines;
for (cv::Vec4i line : lines)
{ if (euclidDist(line) >= minLen) { longLines.push_back(line); } }
return longLines;
}
the eucldian distance shoud be something like:
double euclidDist(const cv::Vec4i& line)
{
return std::sqtr(static_cast<double>((line[0] - line[2]) * (line[0] - line[2]) + (line[1] - line[3]) * (line[1] - line[3])));
}
In your code you shall do something like this
std::vector<cv::Vec4i> longLines = filterLinesByLen(lines, 80); // you can replace 80 by a value that you think is good, or create a function that returns the mean of the lenghts ...