-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproj4p.cpp
109 lines (96 loc) · 2.26 KB
/
proj4p.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "def_general.h"
#include <stdio.h>
#include "proj4p.h"
#include "gj.h"
void CalcProjParam( strPoint *p1, strPoint *p2, strProjParam *param )
// 対応する4点から射影変換のパラメータを計算する
{
double a[kProjParamNum][kProjParamNum+1];
a[0][0] = p1[0].x;
a[0][1] = 0;
a[0][2] = -(p1[0].x * p2[0].x);
a[0][3] = p1[0].y;
a[0][4] = 0;
a[0][5] = -(p1[0].y * p2[0].x);
a[0][6] = 1;
a[0][7] = 0;
a[0][8] = p2[0].x;
a[1][0] = 0;
a[1][1] = p1[0].x;
a[1][2] = -(p1[0].x * p2[0].y);
a[1][3] = 0;
a[1][4] = p1[0].y;
a[1][5] = -(p1[0].y * p2[0].y);
a[1][6] = 0;
a[1][7] = 1;
a[1][8] = p2[0].y;
a[2][0] = p1[1].x;
a[2][1] = 0;
a[2][2] = -(p1[1].x * p2[1].x);
a[2][3] = p1[1].y;
a[2][4] = 0;
a[2][5] = -(p1[1].y * p2[1].x);
a[2][6] = 1;
a[2][7] = 0;
a[2][8] = p2[1].x;
a[3][0] = p1[2].x;
a[3][1] = 0;
a[3][2] = -(p1[2].x * p2[2].x);
a[3][3] = p1[2].y;
a[3][4] = 0;
a[3][5] = -(p1[2].y * p2[2].x);
a[3][6] = 1;
a[3][7] = 0;
a[3][8] = p2[2].x;
a[4][0] = 0;
a[4][1] = p1[1].x;
a[4][2] = -(p1[1].x * p2[1].y);
a[4][3] = 0;
a[4][4] = p1[1].y;
a[4][5] = -(p1[1].y * p2[1].y);
a[4][6] = 0;
a[4][7] = 1;
a[4][8] = p2[1].y;
a[5][0] = 0;
a[5][1] = p1[2].x;
a[5][2] = -(p1[2].x * p2[2].y);
a[5][3] = 0;
a[5][4] = p1[2].y;
a[5][5] = -(p1[2].y * p2[2].y);
a[5][6] = 0;
a[5][7] = 1;
a[5][8] = p2[2].y;
a[6][0] = p1[3].x;
a[6][1] = 0;
a[6][2] = -(p1[3].x * p2[3].x);
a[6][3] = p1[3].y;
a[6][4] = 0;
a[6][5] = -(p1[3].y * p2[3].x);
a[6][6] = 1;
a[6][7] = 0;
a[6][8] = p2[3].x;
a[7][0] = 0;
a[7][1] = p1[3].x;
a[7][2] = -(p1[3].x * p2[3].y);
a[7][3] = 0;
a[7][4] = p1[3].y;
a[7][5] = -(p1[3].y * p2[3].y);
a[7][6] = 0;
a[7][7] = 1;
a[7][8] = p2[3].y;
gj(a);
param->a1 = a[0][8];
param->a2 = a[1][8];
param->a3 = a[2][8];
param->b1 = a[3][8];
param->b2 = a[4][8];
param->b3 = a[5][8];
param->c1 = a[6][8];
param->c2 = a[7][8];
}
void ProjTrans( strPoint *src, strPoint *dst, strProjParam *param )
// パラメータで射影変換先の座標を計算する(正対画像の座標src,傾き画像の座標dst)
{
dst->x = (int)((param->a1 * src->x + param->b1 * src->y + param->c1 ) / ( param->a3 * src->x + param->b3 * src->y + 1.0 )+0.5);
dst->y = (int)((param->a2 * src->x + param->b2 * src->y + param->c2 ) / ( param->a3 * src->x + param->b3 * src->y + 1.0 )+0.5);
}