在opencv求得直线段的时候,我们总想给线段长短排序,判断线段之间的夹角,求两直线的交点,求两直线的距离,求点线距离,求垂线,求平行线。
下面粘贴出我用的直线相关的函数。
一般情况下,x1,y1,x2,y2表示线段1,x3,y3,x4,y4表示线段2
Vec4f 类型的 line1也可以表示一个线段,其中line1[0],line1[1]表示一个线段断点的x,y
line1[2],line1[3]表示另一个端点。
LineFunction.h文件
#include <opencv2/opencv.hpp>
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include "opencv2/core/core.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <time.h>
#include<algorithm>
using namespace cv;
using namespace cv::ml;
using namespace std;
extern double Pointdistance(double x1, double y1, double x2, double y2);
extern double lineslope(Vec4f line);
extern double lineslope(double x1, double y1, double x2, double y2);
extern double linelen(Vec4f line);
extern double PointToSegDist(double x, double y, double x1, double y1, double x2, double y2);
extern double PointToSegDist(double x, double y, Vec4f line);
extern Point2f lineIntersection(Vec4f line1, Vec4f line2, int& result);
extern Point2f lineVertical(Vec4f line, Point2f p);
extern Point2f linePara(Vec4f line, Point2f p);
extern double lineAngle(Vec4f line1, Vec4f line2);
extern double lineDist(Vec4f line1, Vec4f line2);
struct LenOrder
{
int order;
double len;
};
extern void lineSort(vector<Vec4f> line, vector<LenOrder>&order);
extern void ContoursLine(vector<Vec4f>& lineall, vector<Point> contours, double distepsilon = 20);
extern void lineMerge(vector<Vec4f>& lineall, double alfa = 8, double cita = 20);
extern bool ContoursRect(vector<Vec4f>& lineall, vector<Point> contours, vector<Vec4f>& lineRect, double LineDistTh = 500, double LineLenTh = 400, double LineAngleTh = 8);
cpp文件
#include "LineFunction.h"
#include <opencv2/opencv.hpp>
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include "opencv2/core/core.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <time.h>
#include<algorithm>
using namespace cv;
using namespace cv::ml;
using namespace std;
double Pointdistance(double x1, double y1, double x2, double y2)
{//返回点点距离
return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
double lineslope(Vec4f line)
{//斜率 返回弧度
double dsx = line[0] - line[2];
double dsy = line[1] - line[3] + DBL_MIN;
//cout << "dsx" << dsx << "dsy" << dsy << "atan2" << atan2(dsx, dsy) << endl;
return atan(dsy / dsx); //注意,antan2函数会返回带象限的方向
}
double lineslope(double x1, double y1, double x2, double y2)
{//斜率 返回弧度
double dsx = x1 - x2;
double dsy = y1 - y2 + DBL_MIN;
return atan(dsy / dsx); //注意,antan2函数会返回带象限的方向
}
double linelen(Vec4f line)
{ //线段长度
double x1 = line[0];
double y1 = line[1];
double x2 = line[2];
double y2 = line[3];
return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
int MyInterSec(double X1, double Y1, double X2, double Y2, double X3, double Y3, double X4, double Y4, double &x, double &y)
{//相交在前线上return 1,后线return 2,交于外面return 3,不相交return 0
//这部分不单独使用,一般用后面的函数 lineIntersection(Vec4f line1, Vec4f line2, int& result)
double k1, k2;
if ((X1 == X2) && (Y1 == Y2) && (Y3 == Y4) && (X3 == X4))
{
return 0;
}
if ((X1 == X2) && (Y1 == Y2))
{
if ((X3 == X4) && (X1 == X3))
{
x = X1;
y = Y1;
return 1;
}
else if (Y2 == ((X2 - X3)*(Y4 - Y3) / (X4 - X3) + Y3))
{
x = X1;
y = Y1;
return 1;
}
}
if ((Y3 == Y4) && (X3 == X4))
{
if ((X2 == X1) && (X1 == X3))
{
x = X3;
y = Y3;
return 2;
}
else if (Y3 == ((X3 - X1)*(Y2 - Y1) / (X2 - X1) + Y1))
{
x = X3;
y = Y3;
return 2;
}
}
if (X1 != X2)
{
k1 = (Y2 - Y1) / (X2 - X1);
if (X3 != X4)
{
k2 = (Y4 - Y3) / (X4 - X3);
if (k1 == k2)
{
return 0;
}
x = (Y3 - Y1 - k2*X3 + X1*k1) / (k1 - k2);
y = k1*(x - X1) + Y1;
if (((X1 - x)*(X2 - x)<0 || (X1 - x)*(X2 - x) == 0) && ((Y1 - y)*(Y2 - y)<0 || (Y1 - y)*(Y2 - y) == 0))
return 1;
if (((X3 - x)*(X4 - x)<0 || (X3 - x)*(X4 - x) == 0) && ((Y3 - y)*(Y4 - y)<0 || (Y3 - y)*(Y4 - y) == 0))
return 2;
if ((X3 - x)*(X4 - x)>0 && (Y3 - y)*(Y4 - y)>0 && (X1 - x)*(X2 - x)>0 && (Y1 - y)*(Y2 - y)>0)
return 3;
}
if (X3 == X4)
{
x = X3;
y = k1*(X3 - X1) + Y1;
return 1;
}
}
else
{
if (X3 != X4)
{
k2 = (Y4 - Y3) / (X4 - X3);
x = double(X1);
y = k2*(X1 - X3) + Y3;
return 2;
}
if (X3 == X4)
{
return 0;
}
}
return 0;
}
Point2f lineIntersection(Vec4f line1, Vec4f line2, int& result)
{ //求垂点
double x, y;
//cout << line1[0] << "," << line1[1] << "," << line1[2] << "," << line1[3] << endl;
//cout << line2[0] << "," << line2[1] << "," << line2[2] << "," << line2[3] << endl;
result = MyInterSec(line1[0], line1[1], line1[2], line1[3], line2[0], line2[1], line2[2], line2[3], x, y);
if (result)
return Point2f(x, y);
return Point2f(-1, -1);
}
Point2f lineVertical(Vec4f line, Point2f p)
{ //求过直线外一点的垂点
Point2f result;
float A, B, C;
A = (line[3] - line[1]) / (line[2] - line[0] + DBL_MIN);
B = -1;
C = -A*line[0] + line[1];
//double tmp = A * A + B * B;
//result.x = (B * B * p.x - A * B * p.y - A * C) / tmp;
//result.y = (A * A * p.y - A * B * p.x - B * C) / tmp;
result.x = (A* p.y - A*C + p.x)/(A*A+1);
result.y = result.x *A + C;
return result;
}
Point2f linePara(Vec4f line, Point2f p)
{ //求过点p平行线 ()
Point2f result;
float k;
k = (line[3] - line[1]) / (line[2] - line[0] + DBL_MIN);
result.x = 100.1;
result.y = k*(100 - p.x) + p.y;
if (fabs(k) < 0.01)
result.y = p.y + 100;//竖线
return result;
}
double PointToSegDist(double x, double y, double x1, double y1, double x2, double y2)
{ //返回点线距离 其中x1y1,x2y2是线段
double k = (y2 - y1) / (x2 - x1 + 0.0000000000001);
double b = y1 - k*x1;
return abs(k*x - y + b) / sqrt(1 + k*k);
}
double PointToSegDist(double x, double y, Vec4f line)
{ //返回点线距离
double x1 = line[0];
double y1 = line[1];
double x2 = line[2];
double y2 = line[3];
double k = (y2 - y1) / (x2 - x1 + 0.0000000000001);
double b = y1 - k*x1;
return abs(k*x - y + b) / sqrt(1 + k*k);
}
double lineAngle(Vec4f line1, Vec4f line2)
{ //返回线段夹角
//余弦定理 //这个angle给的是最小的夹角,如果要0-180的夹角请修改返回值得方法
double cosfi = 0, fi = 0, norm = 0;
double dsx = line1[0] - line1[2];
double dsy = line1[1] - line1[3];
double dex = line2[0] - line2[2];
double dey = line2[1] - line2[3];
cosfi = dsx * dex + dsy * dey;
norm = (dsx * dsx + dsy * dsy) * (dex * dex + dey * dey);
cosfi /= sqrt(norm);
if (cosfi >= 1.0) return 0;
if (cosfi <= -1.0) return 0;
fi = acos(cosfi);
if (180 * fi / CV_PI <90)
{
return 180 * fi / CV_PI;
}
else
{
return 180 - 180 * fi / CV_PI;
}
}
double lineDist(Vec4f line1, Vec4f line2)
{//返回短线中点到长线中点的距离//由于有sort函数长直线放在第一个参数
double x1, x2, x, y1, y2, y;
x1 = line1[0]; y1 = line1[1];
x2 = line1[2]; y2 = line1[3];
x = (line2[0] + line2[2]) / 2;
y = (line2[1] + line2[3]) / 2;
double k = (y2 - y1) / (x2 - x1 + 0.0000000000001);
double b = y1 - k*x1;
return abs(k*x - y + b) / sqrt(1 + k*k);
}
/线长排序//
bool sortMethod(const LenOrder &v1, const LenOrder &v2)
{
return v1.len >v2.len;
}
void lineSort(vector<Vec4f> line, vector<LenOrder>&order)
{
//线长排序,输入line是一组直线段,输出的vector<LenOrder>&order是一组以直线长度从长到短排序的序列。
//其中LenOrder结构的.order 是直线段在原来直线组里的下标,.len是该直线段的长度//
//用法实例 假如有一组直线段 Stdlineall 类型(vector<Vec4f>)
//vector<LenOrder>Stdorder; //1
//lineSort(Stdlineall, Stdorder); //2
//Stdlineall.at(Stdorder.at(0).order) //最长的直线
// Stdorder.at(0).order //最长的直线的长度
order.clear();
for (int i = 0; i < line.size(); i++)
{
LenOrder lo;
lo.len = Pointdistance(line.at(i)[0], line.at(i)[1], line.at(i)[2], line.at(i)[3]);
lo.order = i;
order.push_back(lo);
}
sort(order.begin(), order.end(), sortMethod);
}
线段长排序
///后两个函数是Contours转化为线段的函数,可以直接不理会
void ContoursLine(vector<Vec4f>& lineall, vector<Point> contours, double distepsilon)
{ //轮廓点拟合成线段组 第一个参数是输出的直线,第二个参数是输入的轮廓点集,第三个参数是线段合并的距离临界,一般取5-20
vector<double> xcur, ycur;
Vec4f linecur;
int flag;
int num = contours.size();
for (int k = 0; k < num; k++)
{
for (; k < num&&xcur.size() < 5; k++)
{
xcur.push_back(contours.at(k).x);
ycur.push_back(contours.at(k).y);
}//不足五个点,补齐
linecur[0] = xcur.at(0);
linecur[1] = ycur.at(0);
linecur[2] = xcur.at(xcur.size() - 1);
linecur[3] = ycur.at(xcur.size() - 1);//首尾作为一条直线
if (xcur.size() > 2)
{
for (int L = 1; L < xcur.size() - 1; L++)
{
if (PointToSegDist(xcur.at(L), ycur.at(L), linecur) > distepsilon)
{
xcur.erase(xcur.begin());
ycur.erase(ycur.begin());
linecur[0] = xcur.at(0);
linecur[1] = ycur.at(0);
L = 1;
}
}//前五个点中寻找非共线点s
if (xcur.size() > 2)
{
// 确定有三点或者以上的点共线后//
flag = 1;
for (k = k + 1; k < num&&flag; k++) //往后寻找新点
{
if (PointToSegDist(contours.at(k).x, contours.at(k).y, linecur) <= distepsilon)
{
xcur.push_back(contours.at(k).x);
ycur.push_back(contours.at(k).y);
}
else
{
linecur[2] = contours.at(k).x;
linecur[3] = contours.at(k).y;
for (int L = 1; L < xcur.size(); L++)
{
if (PointToSegDist(xcur.at(L), ycur.at(L), linecur) > distepsilon)
{
flag = 0; //找到终点,停止外层循环
break;
}
}
}
}//到这一步找完终点
if (xcur.size() > 5)
{
double A, B;
std::vector<Point> points;
for (int i = 0; i < xcur.size() - 1; i++)
{
points.push_back(Point(xcur.at(i), ycur.at(i)));
}
Vec4f linex;
fitLine(Mat(points), linex, CV_DIST_L2, 0, 0.01, 0.01);
A = linex[1] / linex[0];
B = linex[3] - A*linex[2];
if (fabs(A) <1)
{
linecur[0] = xcur.at(0);
linecur[1] = xcur.at(0)*A + B;
linecur[2] = xcur.at(xcur.size() - 1);
linecur[3] = xcur.at(xcur.size() - 1)*A + B;
}
else
{
linecur[0] = (ycur.at(0) - B) / A;
linecur[1] = ycur.at(0);
linecur[2] = (ycur.at(xcur.size() - 1) - B) / A;
linecur[3] = ycur.at(xcur.size() - 1);
}
lineall.push_back(linecur);
//找到终点,保存直线
}
xcur.clear();
ycur.clear();
//确定有三点或者以上的点共线后//
}
}// if size>2,确保线段长度足够
}//外循环,线段提取
//找出所有直线/
}
void lineMerge(vector<Vec4f>& lineall, double alfa,double cita)
{ //轮廓上的直线合并 (首尾相连的直线段s) //第一个参数是输入也是输出,第二个是角度范围,如可容忍直线的夹角为0-8度填写8 第三个是距离范围,是一条线段中点到另一条直线的距离,
for (int L = 0; L < lineall.size() - 2; ++L)
{
Vec4f line1 = lineall.at(L);
Vec4f line2 = lineall.at(L + 1);
Vec4f linem;
if (lineAngle(line1, line2) < alfa && lineDist(line1, line2) < cita)
{
double d13 = Pointdistance(line1[0], line1[1], line2[0], line2[1]);
double d23 = Pointdistance(line1[2], line1[3], line2[0], line2[1]);
double d24 = Pointdistance(line1[2], line1[3], line2[2], line2[3]);
double d14 = Pointdistance(line1[0], line1[1], line2[2], line2[3]);
double d12 = linelen(line1);
double d34 = linelen(line2);
if (d14 >= d13 && d14 >= d23 && d14 >= d24 && d14 >= d12&&d14 >= d34)
{
linem[0] = line1[0]; //14最长
linem[1] = line1[1];
linem[2] = line2[2];
linem[3] = line2[3];
}
else if (d13 >= d23&&d13 >= d24&&d13 >= d14&&d13 >= d12&&d13 >= d34)
{
linem[0] = line1[0]; //13最长
linem[1] = line1[1];
linem[2] = line2[0];
linem[3] = line2[1];
}
else if (d23 >= d13&&d23 >= d24&&d23 >= d14&&d23 >= d12&&d23 >= d34)
{
linem[0] = line1[2]; //23最长
linem[1] = line1[3];
linem[2] = line2[0];
linem[3] = line2[1];
}
else if (d24 >= d13&&d24 >= d23&&d24 >= d14&&d24 >= d12&&d24 >= d34)
{
linem[0] = line1[2]; //24最长
linem[1] = line1[3];
linem[2] = line2[2];
linem[3] = line2[3];
}
else if (d12 >= d13&&d12 >= d23&&d12 >= d24&&d12 >= d14&&d12 >= d34)
{
linem = line1;
}
else
linem = line2;
lineall[L] = linem;
lineall.erase(lineall.begin() + L + 1);
}
else
{
line2 = lineall.at(L + 2);
if (lineAngle(line1, line2) < alfa && lineDist(line1, line2) < cita)
{
double d13 = Pointdistance(line1[0], line1[1], line2[0], line2[1]);
double d23 = Pointdistance(line1[2], line1[3], line2[0], line2[1]);
double d24 = Pointdistance(line1[2], line1[3], line2[2], line2[3]);
double d14 = Pointdistance(line1[0], line1[1], line2[2], line2[3]);
double d12 = linelen(line1);
double d34 = linelen(line2);
if (d14 >= d13 && d14 >= d23 && d14 >= d24 && d14 >= d12&&d14 >= d34)
{
linem[0] = line1[0]; //14最长
linem[1] = line1[1];
linem[2] = line2[2];
linem[3] = line2[3];
}
else if (d13 >= d23&&d13 >= d24&&d13 >= d14&&d13 >= d12&&d13 >= d34)
{
linem[0] = line1[0]; //13最长
linem[1] = line1[1];
linem[2] = line2[0];
linem[3] = line2[1];
}
else if (d23 >= d13&&d23 >= d24&&d23 >= d14&&d23 >= d12&&d23 >= d34)
{
linem[0] = line1[2]; //23最长
linem[1] = line1[3];
linem[2] = line2[0];
linem[3] = line2[1];
}
else if (d24 >= d13&&d24 >= d23&&d24 >= d14&&d24 >= d12&&d24 >= d34)
{
linem[0] = line1[2]; //24最长
linem[1] = line1[3];
linem[2] = line2[2];
linem[3] = line2[3];
}
else if (d12 >= d13&&d12 >= d23&&d12 >= d24&&d12 >= d14&&d12 >= d34)
{
linem = line1;
}
else
linem = line2;
lineall[L] = linem;
lineall.erase(lineall.begin() + L + 2);
}
}//else
}//for
/后两根直线的处理
if (lineall.size()>1)
{
int L = lineall.size() - 2;
Vec4f line1 = lineall.at(L);
Vec4f line2 = lineall.at(L + 1);
Vec4f linem;
if (lineAngle(line1, line2) < alfa && lineDist(line1, line2) < cita)
{
double d13 = Pointdistance(line1[0], line1[1], line2[0], line2[1]);
double d23 = Pointdistance(line1[2], line1[3], line2[0], line2[1]);
double d24 = Pointdistance(line1[2], line1[3], line2[2], line2[3]);
double d14 = Pointdistance(line1[0], line1[1], line2[2], line2[3]);
double d12 = linelen(line1);
double d34 = linelen(line2);
if (d14 >= d13 && d14 >= d23 && d14 >= d24 && d14 >= d12&&d14 >= d34)
{
linem[0] = line1[0]; //14最长
linem[1] = line1[1];
linem[2] = line2[2];
linem[3] = line2[3];
}
else if (d13 >= d23&&d13 >= d24&&d13 >= d14&&d13 >= d12&&d13 >= d34)
{
linem[0] = line1[0]; //13最长
linem[1] = line1[1];
linem[2] = line2[0];
linem[3] = line2[1];
}
else if (d23 >= d13&&d23 >= d24&&d23 >= d14&&d23 >= d12&&d23 >= d34)
{
linem[0] = line1[2]; //23最长
linem[1] = line1[3];
linem[2] = line2[0];
linem[3] = line2[1];
}
else if (d24 >= d13&&d24 >= d23&&d24 >= d14&&d24 >= d12&&d24 >= d34)
{
linem[0] = line1[2]; //24最长
linem[1] = line1[3];
linem[2] = line2[2];
linem[3] = line2[3];
}
else if (d12 >= d13&&d12 >= d23&&d12 >= d24&&d12 >= d14&&d12 >= d34)
{
linem = line1;
}
else
linem = line2;
lineall[L] = linem;
lineall.erase(lineall.begin() + L + 1);
}
}
//最后一根和第一根
if (lineall.size()>1)
{
int L = lineall.size() - 2;
Vec4f line1 = lineall.at(L+1);
Vec4f line2 = lineall.at(0);
Vec4f linem;
if (lineAngle(line1, line2) < alfa && lineDist(line1, line2) < cita)
{
double d13 = Pointdistance(line1[0], line1[1], line2[0], line2[1]);
double d23 = Pointdistance(line1[2], line1[3], line2[0], line2[1]);
double d24 = Pointdistance(line1[2], line1[3], line2[2], line2[3]);
double d14 = Pointdistance(line1[0], line1[1], line2[2], line2[3]);
double d12 = linelen(line1);
double d34 = linelen(line2);
if (d14 >= d13 && d14 >= d23 && d14 >= d24 && d14 >= d12&&d14 >= d34)
{
linem[0] = line1[0]; //14最长
linem[1] = line1[1];
linem[2] = line2[2];
linem[3] = line2[3];
}
else if (d13 >= d23&&d13 >= d24&&d13 >= d14&&d13 >= d12&&d13 >= d34)
{
linem[0] = line1[0]; //13最长
linem[1] = line1[1];
linem[2] = line2[0];
linem[3] = line2[1];
}
else if (d23 >= d13&&d23 >= d24&&d23 >= d14&&d23 >= d12&&d23 >= d34)
{
linem[0] = line1[2]; //23最长
linem[1] = line1[3];
linem[2] = line2[0];
linem[3] = line2[1];
}
else if (d24 >= d13&&d24 >= d23&&d24 >= d14&&d24 >= d12&&d24 >= d34)
{
linem[0] = line1[2]; //24最长
linem[1] = line1[3];
linem[2] = line2[2];
linem[3] = line2[3];
}
else if (d12 >= d13&&d12 >= d23&&d12 >= d24&&d12 >= d14&&d12 >= d34)
{
linem = line1;
}
else
linem = line2;
lineall[L] = linem;
lineall.erase(lineall.begin() );
}
}
}
bool ContoursRect(vector<Vec4f>& lineall, vector<Point> contours, vector<Vec4f>& lineRect, double LineDistTh, double LineLenTh, double LineAngleTh)
{ //优点:能减少部分外点
lineRect.clear();
vector<LenOrder> order;
vector<Vec4f> lineTem;
lineSort(lineall, order);
int found = 0;
Vec4f line1, line2;
for (int L = 0; L < order.size(); L++)
{
line1 = lineall.at(order.at(L).order);
for (int K = L + 1; K < order.size(); K++)
{
line2 = lineall.at(order.at(K).order);
if (lineAngle(line1, line2) < LineAngleTh&&lineDist(line1, line2) > LineDistTh&& order.at(L).len > LineLenTh)
{
found = 1;
break;
}
}
if (found)
break;
}
if (found)
{
//cout << "line1[0]" << line1[0] << " line1[1]" << line1[1] << "line1[2]" << line1[2] << " line1[3] " << line1[3] << endl;
//cout << "line2[0]" << line2[0] << " line2[1]" << line2[1] << "line2[2]" << line2[2] <<" line2[3] "<< line2[3] << endl;
Point2f Pt1 = Point2f(line2[0] / 2 + line2[2] / 2, line2[1] / 2 + line2[3] / 2);
Point2f Pt2 = lineVertical(line1, Pt1);
Vec4f lineMed;
lineMed[0] = Pt1.x;
lineMed[1] = Pt1.y;
lineMed[2] = Pt2.x;
lineMed[3] = Pt2.y;
double Maxdist = 0;
Point2f Pt3;
for (int i = 0; i < contours.size(); i++)
{
if (PointToSegDist(contours.at(i).x, contours.at(i).y, lineMed) > Maxdist)
{
Maxdist = PointToSegDist(contours.at(i).x, contours.at(i).y, lineMed);
Pt3 = contours.at(i);
}
}
Point2f Pt4 = lineVertical(line1, Pt3);
Point2f Pt5 = lineVertical(line2, Pt3);
Vec4f line3;
line3[0] = Pt4.x;
line3[1] = Pt4.y;
line3[2] = Pt5.x;
line3[3] = Pt5.y;
Maxdist = 0;
Point2f Pt6;
for (int i = 0; i < contours.size(); i++)
{
if (PointToSegDist(contours.at(i).x, contours.at(i).y, line3) > Maxdist)
{
Maxdist = PointToSegDist(contours.at(i).x, contours.at(i).y, line3);
Pt6 = contours.at(i);
}
}
Point2f Pt7 = lineVertical(line1, Pt6);
Point2f Pt8 = lineVertical(line2, Pt6);
line1[0] = Pt4.x;
line1[1] = Pt4.y;
line1[2] = Pt7.x;
line1[3] = Pt7.y;
lineTem.push_back(line1);
line1[0] = Pt5.x;
line1[1] = Pt5.y;
line1[2] = Pt8.x;
line1[3] = Pt8.y;
lineTem.push_back(line1);
lineTem.push_back(line3);
line1[0] = Pt7.x;
line1[1] = Pt7.y;
line1[2] = Pt8.x;
line1[3] = Pt8.y;
lineTem.push_back(line1);
if (linelen(lineTem[0]) > linelen(lineTem[2]))
{
lineRect = lineTem;
}
else
{
lineRect.push_back(lineTem[2]);
lineRect.push_back(lineTem[3]);
lineRect.push_back(lineTem[0]);
lineRect.push_back(lineTem[1]);
}
return 1;
}
else
return 0;
}