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 ...
Could explain a bit better what you want to do? HoughLinesP gives you the end-points of the lines, so that you can simply get the length as the euclidean distance between these points.
from the codes, I had received a lot of expected straight lines. The prob is, I want to have only the longest straight lines from it. From the Euclidean distance, I had get the value.. (it is in pixel saiz right?) . And based on the lines that I had received, how can I manage to filter and select only the longest line?
TQ
If you measure it in the image you have, then for sure you shall measure it in pixels. I am not sure, but I suppose that the points coordinate in the vec4i (x1,y1,x2,y2) are the two limit points of the detected segment, so, you can apply Euclidean distance
Hi, OK, here is the code that I worked on the Euclidean Distance and it returns me a lot of straight lines. Would I able to filter only the longest one?
}
Then you shall create the function that I have posted in the answer and apply it on your lies for filtering them.