-
Notifications
You must be signed in to change notification settings - Fork 0
/
heatmapA_try_transfer.go
285 lines (235 loc) · 8.11 KB
/
heatmapA_try_transfer.go
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
package main
// load csv data in the range
// change axis
// get log
// smoothed
// paint
// paste to original picture
import (
"encoding/binary"
"encoding/csv"
"fmt"
"github.com/lisiminy/heatmapA"
"image"
// "image/draw"
"image/color"
"image/draw"
"image/png"
_ "image/jpeg"
"io/ioutil"
"log"
"net/http"
"os"
"strconv"
"strings"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func readRawData(fileName string) [][]string {
csvfile, err := os.Open(fileName)
check(err)
defer csvfile.Close()
reader := csv.NewReader(csvfile)
reader.FieldsPerRecord = -1 // see the Reader struct information below
rawCsvData, err := reader.ReadAll()
check(err)
return rawCsvData
}
func readParameterReverse(fileName string) ([9]float64, [3]float64) {
fd, err := os.Open(fileName)
check(err)
defer fd.Close()
var o2 int64
var f2 float32
var r [9]float64
for i := 0; i < 9; i++ {
o2, err = fd.Seek(int64(34*4+i*4), 0)
check(err)
// err = binary.Read(fd, binary.BigEndian, &f2)
err = binary.Read(fd, binary.LittleEndian, &f2)
check(err)
r[i] = float64(f2)
fmt.Println(r[i], o2/4)
}
var t [3]float64
for i := 0; i < 3; i++ {
o2, err = fd.Seek(int64(43*4+i*4), 0)
check(err)
// err = binary.Read(fd, binary.BigEndian, &f2)
err = binary.Read(fd, binary.LittleEndian, &f2)
check(err)
t[i] = float64(f2)
fmt.Println(t[i], o2/4)
}
return r, t
}
func getPicture(SensorId_selected string) image.Image {
resp, err := http.Get("http://54.223.151.143:8082/api/slices/live.thumbnail?sensorid=" + SensorId_selected + "&cachetime=10")
// resp, err := http.Get("http://i.imgur.com/Peq1U1u.jpg")
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
lines := strings.Split(string(body), "\n")
// fmt.Println(string(lines[0]))
url_picture := "http://54.223.151.143:8082/api/slices/thumbnail/" + lines[0]
fmt.Println(url_picture)
resp, err = http.Get(url_picture)
// resp, err := http.Get("http://i.imgur.com/Peq1U1u.jpg")
if err != nil {
log.Fatal(err)
}
fmt.Println("start decode image")
m, _, err := image.Decode(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println("end decode image")
return m
}
func pasetePicture(m image.Image, img image.Image, sensorSelected string) {
b := m.Bounds()
mm := image.NewNRGBA(b)
draw.Draw(mm, b, m, image.ZP, draw.Src)
draw.Draw(mm, img.Bounds(), img, image.ZP, draw.Over)
fmt.Println("save picuture")
savePicName := "d:/Desktop/output_" + sensorSelected + ".png"
out, err := os.Create(savePicName)
check(err)
err = png.Encode(out, mm)
check(err)
}
func main() {
// fileName := "output_20150603_dr_2d.csv"
// fileName := "D:/Desktop/go/output_20150603.csv"
fileName := "D:/Go/src/github.com/lisiminy/dg-heatmap/output_20150603.csv"
rawCsvData := readRawData(fileName)
// startTIme := 1433244616921
// endTime := 1433382753447
// 1433382753447 1433244616921
sensorSelected := "a1f20e44503436343300000500c90016"
calibFileName := "D:/Go/src/github.com/lisiminy/dg-heatmap/floor_calib4.dat"
// sensorSelected := "a1f20e44503436343300000500a60028"
// calibFileName := "D:/Go/src/github.com/lisiminy/dg-heatmap/floor_calib8.dat"
// sensorSelected := "a1f20e445034363433000005005c0022"
// calibFileName := "D:/Go/src/github.com/lisiminy/dg-heatmap/floor_calib14.dat"
// sensorSelected := "a1f20e44503436343300000500880029"
// calibFileName := "D:/Go/src/github.com/lisiminy/dg-heatmap/floor_calib15.dat"
// sensorSelected := "a1f20e44503436343300000500b60021"
// calibFileName := "D:/Go/src/github.com/lisiminy/dg-heatmap/floor_calib16.dat"
// sensorSelected := "a1f20e445034363433000005005c0022"
// calibFileName := "D:/Go/src/github.com/lisiminy/dg-heatmap/floor_calib98.dat"
// sensorSelected := "a1f20e44503436343300000500540029"
// calibFileName := "D:/Go/src/github.com/lisiminy/dg-heatmap/floor_calib99.dat"
// sensorSelected := "a1f20e44503436343300000500640029"
// calibFileName := "D:/Go/src/github.com/lisiminy/dg-heatmap/floor_calib103.dat"
// sensorSelected := "a1f20e44503436343300000500d80021"
// calibFileName := "D:/Go/src/github.com/lisiminy/dg-heatmap/floor_calib104.dat"
// sensorSelected := "a1f20e44503436343300000500630021"
// calibFileName := "D:/Go/src/github.com/lisiminy/dg-heatmap/floor_calib105.dat"
// sensorSelected := "a1f20e44503436343300000500db0028"
// calibFileName := "D:/Go/src/github.com/lisiminy/dg-heatmap/floor_calib106.dat"
///////////////////////////////////////////////////////////////////////////
// sensorSelected := "a1f20e44503436343300000500c90016"
// calibFileName := "D:/Desktop/heatmap_deepglint/floor_calib4.dat"
// sensorSelected := "a1f20e44503436343300000500a60028"
// calibFileName := "D:/Desktop/heatmap_deepglint/floor_calib8.dat"
// sensorSelected := "a1f20e445034363433000005005c0022"
// calibFileName := "D:/Desktop/heatmap_deepglint/floor_calib14.dat"
// sensorSelected := "a1f20e44503436343300000500880029"
// calibFileName := "D:/Desktop/heatmap_deepglint/floor_calib15.dat"
// sensorSelected := "a1f20e44503436343300000500b60021"
// calibFileName := "D:/Desktop/heatmap_deepglint/floor_calib16.dat"
// sensorSelected := "a1f20e445034363433000005005c0022"
// calibFileName := "D:/Desktop/heatmap_deepglint/floor_calib98.dat"
// sensorSelected := "a1f20e44503436343300000500540029"
// calibFileName := "D:/Desktop/heatmap_deepglint/floor_calib99.dat"
// sensorSelected := "a1f20e44503436343300000500640029"
// calibFileName := "D:/Desktop/heatmap_deepglint/floor_calib103.dat"
// sensorSelected := "a1f20e44503436343300000500d80021"
// calibFileName := "D:/Desktop/heatmap_deepglint/floor_calib104.dat"
// sensorSelected := "a1f20e44503436343300000500630021"
// calibFileName := "D:/Desktop/heatmap_deepglint/floor_calib105.dat"
// sensorSelected := "a1f20e44503436343300000500db0028"
// calibFileName := "D:/Desktop/heatmap_deepglint/floor_calib106.dat"
r, t := readParameterReverse(calibFileName)
fmt.Println(r, t)
points := []heatmapA.DataPoint{}
var xMax, yMax float64 = 0, 0
for _, data := range rawCsvData {
if data[1] == sensorSelected {
// if data[3] < startTIme {
// continue
// }
// if data[3] > endTime {
// continue
// }
xFloor, err := strconv.ParseFloat(data[4], 64)
xFloor = xFloor
xFloor = (xFloor + 10000) / 10
check(err)
yFloor, err := strconv.ParseFloat(data[5], 64)
yFloor = yFloor / 10
check(err)
// xCam := xFloor*r[0] + yFloor*r[3] + t[0]
// yCam := xFloor*r[1] + yFloor*r[4] + t[1]
// zCam := xFloor*r[2] + yFloor*r[5] + t[2]
// coeffX := 640 / 1.12213
// coeffY := 480 / 0.84160
// xImage := 320 - coeffX*(xCam/zCam)
// yImage := 240 + coeffY*(yCam/zCam)
// if yFloor > 0 {
if xFloor > 0 {
points = append(points, heatmapA.P(xFloor, yFloor))
}
if xFloor > xMax {
xMax = xFloor
}
if yFloor > yMax {
yMax = yFloor
}
}
}
xMax = xMax + 100
yMax = yMax + 100
img := heatmapA.HeatmapA(points , int(xMax) , int(yMax) , 20)
// img := heatmapA.HeatmapA(image.Rect(0, 0, int(xMax), int(yMax)),
// points, 20, 128, scheme)
resoluionX := 640
resoluionY := 480
imgTransfer := image.NewNRGBA(image.Rect(0, 0, resoluionX, resoluionY))
coeffX := float64(resoluionX) / 1.12213
coeffY := float64(resoluionY) / 0.84160
for x := 0; x < resoluionX; x++ {
for y := 0; y < resoluionY; y++ {
xImage := float64(resoluionX/2 - x)
yImage := -float64(y - resoluionY/2) ////
// fmt.Println(y)
zCam := -t[2] / (r[8] + r[2]*xImage/coeffX + r[5]*yImage/coeffY)
// fmt.Println(yImage, zCam)
xCam := xImage * zCam / coeffX
yCam := yImage * zCam / coeffY
xFloor := xCam*r[0] + yCam*r[3] + zCam*r[6] + t[0]
yFloor := xCam*r[1] + yCam*r[4] + zCam*r[7] + t[1]
xFloorInt := (int(xFloor) + 10000) / 10 ///
yFloorInt := int(yFloor) / 10
// fmt.Println(yFloor, zCam)
// fmt.Println(xFloorInt, yFloorInt) ///
r, g, b, a := img.At(xFloorInt, int(yMax)-yFloorInt).RGBA()
imgTransfer.Set(x, y, color.RGBA{
R: uint8(r >> 8),
G: uint8(g >> 8),
B: uint8(b >> 8),
A: uint8(a >> 8),
})
}
}
m := getPicture(sensorSelected)
// fmt.Println(m.Bounds())
fmt.Println("begin to pasete picuture")
pasetePicture(m, imgTransfer, sensorSelected)
}