我发现在图像中的大多数线的交点 [英] I am struck at finding the point of intersection of most lines in an image
问题描述
我使用标准的hough变换来获得使用OpenCV的图像中的直线。现在,我需要找到图像中大多数线的交叉点的x和y坐标。我的想法是将图像分成几个8 * 8像素段(我还没有决定大小),然后搜索该区域的线。但我不知道如何计算线段中的线。我在这一点上打了。所以我无法做的事情(使用openCV)是
1.将图像分为8 * 8像素段(我不知道如果有一个函数,如果不是我做什么)
2.计算每个段中的线数。
I used standard hough transforms to obtain the straight lines in an image using OpenCV. Now, I need to find the x and y coordinates of the point of intersection of most of the lines in the image. My idea was to divide the image into several 8*8 pixel segments( I haven't decided on the size yet) and then search the region for lines. But I am not sure as to how I count the lines in the segments. I am struck at this point. So the things I am unable to do( using openCV) are 1.Divide the image into 8*8 pixel segments( i don't know if there is a function for it and if not what do I do) 2.Count the number of lines in each segment. Any reading material or hints for the code will be of really helpful.
推荐答案
您检测交叉点的方法是完全错了。有一个简单的数学公式。我给你一个例子代码在纯C:
Your way of detecting intersection points is totally wrong. There is a simple mathematical formula for that. I am giving you an example code in plain C. :
// This is a point
typedef struct{
int x,y;
} MYintPOINT;
// This is line
typedef struct {
MYintPOINT pStart;
MYintPOINT pEnd;
} MyLine;
#define PointMinusPoint(P,Q,R) {(P).x = (Q).x - (R).x; (P).y = (Q).y - (R).y;}
#define PointCross(P,Q) (((P).x*(Q).y)-((P).y*(Q).x))
#define SIGN(X) (((X)>=0)? 1:-1 )
#define ABS(a) ((a) >= 0 ? (a) : (-(a)))
#define ROUND(a) ((SIGN(a)) * ( ( int )( ABS(a) + 0.5 ) ) )
// Given 2 line segments, find their intersection point
// rerurns [Px,Py] point in 'res' or FALSE if parallel. Uses vector cross product technique.
int findLinesIntersectionPoint(const MyLine*l1, const MyLine*l2, MYintPOINT *res){
MYintPOINT p = l1->pStart;
MYintPOINT dp;
MYintPOINT q = l2->pStart;
MYintPOINT dq;
MYintPOINT qmp; // q-p
int dpdq_cross; // 2 cross products
int qpdq_cross; // dp with dq, q-p with dq
float a;
PointMinusPoint(dp,l1->pEnd,l1->pStart);
PointMinusPoint(dq,l2->pEnd,l2->pStart);
PointMinusPoint(qmp,q,p);
dpdq_cross = PointCross(dp,dq);
if (!dpdq_cross){
// Perpendicular Lines
return 0;
}
qpdq_cross = PointCross(qmp,dq);
a = (qpdq_cross*1.0f/dpdq_cross);
res->x = ROUND(p.x+a*dp.x);
res->y = ROUND(p.y+a*dp.y);
return 1;
}
这篇关于我发现在图像中的大多数线的交点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!