-
Notifications
You must be signed in to change notification settings - Fork 4
/
CommonFunctions.cpp
54 lines (43 loc) · 1.45 KB
/
CommonFunctions.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
47
48
49
50
51
52
53
54
#include "CommonFunctions.h"
int draw_lines(Mat frame, vector<double*> lines_vc, Scalar line_color, int line_width){
if(lines_vc.size()>0){
for(int i = 0; i < lines_vc.size(); i++){
Point pt1, pt2;
pt1.x = lines_vc[i][0];
pt1.y = lines_vc[i][1];
pt2.x = lines_vc[i][2];
pt2.y = lines_vc[i][3];
line(frame, pt1, pt2, line_color, line_width, CV_AA);
}
}
else{
cout<<"draw_lines failed: the size of lines_vc is zero!"<<endl;
}
return 1;
}
int draw_contour(Mat frame, vector<Point> points, Scalar point_color, int line_width){
if(points.size()>0){
for(int i = 0; i< points.size()-1; i++){
line(frame, points[i], points[i+1],point_color, line_width, CV_AA);
}
line(frame, points[points.size()-1], points[0],point_color, line_width, CV_AA);
}
else{
cout<<"draw_contour failed: the size of points is zero!"<<endl;
}
return 1;
}
int save_track_results(vector<Point> points, string fname){
const char* filename = fname.c_str();
FILE *fpt = fopen(filename, "a");
fprintf(fpt, "%d ", points.size());
for (int i=0; i<points.size(); i++){
fprintf(fpt, "%6.2lf %6.2lf ", (float)points[i].x,(float)points[i].y);
}
fprintf(fpt,"\n");
fclose(fpt);
return 1;
}
float distance(float x1, float y1, float x2, float y2){
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}