Where to save coordinates of probabilistic Hough?

asked 2015-01-25 13:55:52 -0600

Ztar03 gravatar image

Hi all Yesterday I posted a question which fortunately resolved I'm just now another problem, what is at issue is this ... since I submitted my images to different algorithms ... get a picture with rail lines but are not complete ... I was finding out the equation of each line and solve the system of equations ... and I have a program that gives me the coordinates of the intersection but now my problem is to keep the coordenas delivering HoughP to solving the system of equations and thus finally draw the lines to form a kind of triangle.

Enclose the images obtained

image description

This is what I try to do ...

image description

This is the code of the intersection

 #include <iostream>
 #include <vector>
 #include <stdio.h>
 #include <iomanip>
 #include <iostream>
 #include <math.h>
 #include <algorithm>

 using namespace std;
 int main(){
 float x1 = 406;
 float x2 = 436;
 float x3 = 202;
 float x4 = 206;
 float y1 = 83;
 float y2 = 93;
 float y3 = 7;
 float y4 = 100;

 float d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
// If d is zero, there is no intersection
 if (d == 0) {
    cout << "NO hay interseccion\n";
 }

 // Get the x and y
 float pre = (x1*y2 - y1*x2);
 float post = (x3*y4 - y3*x4);
 float x = ( pre * (x3 - x4) - (x1 - x2) * post ) / d;
 float y = ( pre * (y3 - y4) - (y1 - y2) * post ) / d;

// Check if the x and y coordinates are within both lines
if ( x < min(x1, x2) || x > max(x1, x2) || x < min(x3, x4) || x > max(x3, x4) ){
    cout << "son colineales\n";
} 
if ( y < min(y1, y2) || y > max(y1, y2) || y < min(y3, y4) || y > max(y3, y4) ) {
    cout << "son colineales\n"; 
}

// Return the point of intersection
cout << x << "\n";
cout << y << "\n";
return 0;

}

And this is the part that takes the HoughP and trace the lines

  vector<cv::Vec4i> findLines(cv::Mat& binary) {
       lines.clear();
       cv::HoughLinesP(binary, lines, 1, CV_PI/720, 25, 10, 10 );
      return lines;
  }
  // Draw the detected lines on an image
  void drawDetectedLines(cv::Mat &image, cv::Scalar color=cv::Scalar(255,0,0)) {
         // Draw the lines
          vector<cv::Vec4i>::const_iterator it2= lines.begin();
          while (it2!=lines.end()) {
          float x1=((*it2)[0]);
          float y1=((*it2)[1]+shift);
          float x2=((*it2)[2]);
          float y2=((*it2)[3]+shift);
          cv::Point pt1(x1,y1);        
          cv::Point pt2(x2,y2);
          //Angle lines
          double Angle = atan2(pt2.y - pt1.y,pt2.x - pt1.x) * 180.0 / CV_PI; 
          if(Angle>10){
                cv::line( image, pt1, pt2, color, 6 );
                cout << "Angulo "<< Angle << "\n"; 
           } 

              cout << " HoughP line: ("<< pt1 <<"," << pt2 << ")\n"; 
                      ++it2;
          }

  }
edit retag flag offensive close merge delete