http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html
Or you could transform each point in a line and then using an arrangement to find the intersections.
If you want to use a brute-force approach
1 2 3 4 5
|
for(int K=0; K<n; ++K)
for(int L=K+1; L<n; ++L)
for(int M=L+1; M<n; ++M)
for(int J=M+1; J<n; ++J)
test(K,L,M,J, points);
|
just keep in mind that all the lines that you find for the pair (K,L) are the same line.
Edit: using that property you may optimize the algorithm
1 2 3 4 5 6 7 8 9
|
std::map< pair, std::set<int> > line;
for(int K=0; K<n; ++K)
for(int L=K+1; L<n; ++L)
for(int M=L+1; M<n; ++M)
if( aligned(K, L, M) ){
line[K,L].insert(K); //excuse the syntax
line[K,L].insert(L);
line[K,L].insert(M);
}
|
then you've got all the lines that are composed of 3 or more points, and by checking the size of the set you may filter them to 4 or more points.
the issue is that you would have repeated lines. If you have found that (K,L,M) is aligned, then you may have it in the map as (K,L), (K,M) and (L,M). You may find out the equivalences by checking the last two elements of the set.
> and then checks the slope
I'll recommend you to use the cross product instead