OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Fri, 21 Dec 2018 23:49:56 -0600How to find intersection point and the distance for ray line segment intersection in OpenCV?http://answers.opencv.org/question/205766/how-to-find-intersection-point-and-the-distance-for-ray-line-segment-intersection-in-opencv/I have 4 lines segment, A, B, C and D. Each line is represented as two points. Eg. line A is represented as point A1 and point A2.
![image description](/upfiles/15454576691289607.png)
What I want is
1. point X, which is the point where line A ray intersect with line B
2. distance between X and A1 or A2(either one is fine).
When testing for intersection, line A ray should not
1. intersect with line segment D
2. intersect with line segment C
How do I do this?syaifulnizamyahyaFri, 21 Dec 2018 23:49:56 -0600http://answers.opencv.org/question/205766/Detect crossing lines at a single pointhttp://answers.opencv.org/question/184593/detect-crossing-lines-at-a-single-point/I am currently stuck trying to detect where lines intersect on a grid containing non-straight lines.
My goal is to determine a single point or pixel at the intersection of two lines, for all lines on the "grid", which could then be related to a distance. An example of a grid:
![image description](/upfiles/1518579069589864.png)
I work in Python... Any help or ideas in the right direction would be greatly appreciated. photogrammetry123Tue, 13 Feb 2018 21:31:40 -0600http://answers.opencv.org/question/184593/rectA & rectB not workinghttp://answers.opencv.org/question/120045/recta-rectb-not-working/I am trying to get the intersection of 2 rectangles. What happens if the 2 rectangles do not intersect at all ? Will it give me an error ? Because the output below is what I am getting. The limits are (0,0,1242,375). I don't know the rectangles I am passing in. I just want to keep those that intersect and to retain the intersection.
[1170 x 232 from (72, 0)]
[1242 x 375 from (0, 0)]
[1242 x 375 from (0, 0)]
[967 x 211 from (275, 0)]
[1242 x 375 from (0, 0)]
[1242 x 375 from (0, 0)]
[1242 x 375 from (0, 0)]
[2147449647 x 375 from (2147483647, 0)]
[1242 x 375 from (0, 0)]
I am using this temporary fix after the intersection operator to remove all erroneous rectangles
if (rect.tl().x < 0 || rect.tl().y < 0 || rect.br().x >= image.cols || rect.br().y >= image.rows
|| rect.area() >= image.cols * image.rows || rect.area() == 0)
NbbFri, 23 Dec 2016 01:36:30 -0600http://answers.opencv.org/question/120045/Where to save coordinates of probabilistic Hough?http://answers.opencv.org/question/53779/where-to-save-coordinates-of-probabilistic-hough/ 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](/upfiles/14222147791867654.bmp)
This is what I try to do ...
![image description](/upfiles/14222149033472498.bmp)
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;
}
}
Ztar03Sun, 25 Jan 2015 13:55:52 -0600http://answers.opencv.org/question/53779/