-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenCvUtility.cpp
executable file
·46 lines (44 loc) · 1.13 KB
/
OpenCvUtility.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "OpenCvUtility.h"
void LineInterpolation(Point points[2],vector<Point> &PointList)
{
int absx=std::abs(points[0].x-points[1].x);
int absy=std::abs(points[0].y-points[1].y);
int x_temp=points[0].x<points[1].x?1:-1;
int y_temp=points[0].y<points[1].y?1:-1;
if (PointList.size() == 0) {
PointList.push_back(points[0]);
}
if (points[0].x == points[1].x && points[0].y == points[1].y) {
return;
}
if (absy>absx)
{
for (int itery=1;itery<=absy;itery++)
{
int y=points[0].y+y_temp*itery;
int x=(double)(points[1].x-points[0].x)/(points[1].y-points[0].y)*y_temp*itery+points[0].x;
PointList.push_back(Point(x,y));
}
}
else
{
for (int iterx=1;iterx<=absx;iterx++)
{
int x=points[0].x+x_temp*iterx;
int y=(double)(points[1].y-points[0].y)/(points[1].x-points[0].x)*x_temp*iterx+points[0].y;
PointList.push_back(Point(x,y));
}
}
}
void GetCurve(const vector<Point>& mouse_points, vector<Point> &PointList)
{
if(!PointList.empty())
{
PointList.clear();
}
for (int i=0;i<mouse_points.size()-1;i++)
{
Point points_temp[2]={mouse_points[i],mouse_points[i+1]};
LineInterpolation(points_temp,PointList);
}
}