-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_ga_pcr.py
169 lines (99 loc) · 3.19 KB
/
run_ga_pcr.py
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
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 11 19:34:19 2023
@author: nekhtari
"""
import matplotlib.pyplot as plt
import numpy as np
import pdal
import json
import GA_real
from numpy.random import seed
import compare_with_icp
seed(40)
# fixed_file = r'D:\Working\BAA\Task 6\6.3\From Craig\cloudb.ply'
# moving_file = r'D:\Working\BAA\Task 6\6.3\From Craig\clouda.ply'
# output_file = r'D:\Working\BAA\Task 6\6.3\From Craig\output.txt'
fixed_file = r'./data/fixed.las'
moving_file = r'./data/moving.las'
output_file = r'./data/output.txt'
reader1 = [
{
"type":"readers.las",
"filename":fixed_file
},
{
"type":"filters.normal",
"knn":5
}
]
pipeline1 = pdal.Pipeline(json.dumps(reader1))
pipeline1.execute()
arrays1 = pipeline1.arrays
view1 = arrays1[0]
X1 = view1['X']
Y1 = view1['Y']
Z1 = view1['Z']
NX = view1['NormalX']
NY = view1['NormalY']
NZ = view1['NormalZ']
Normal = np.vstack([NX, NY, NZ]).T
# Read in The Moving Dataset - Smaller, Don't Need Normals
reader2 = [
{
"type":"readers.las",
"filename":moving_file
}
]
pipeline2 = pdal.Pipeline(json.dumps(reader2))
pipeline2.execute()
arrays2 = pipeline2.arrays
view2 = arrays2[0]
X2 = view2['X']
Y2 = view2['Y']
Z2 = view2['Z']
''' ----------------------------------------------------------------------- '''
''' ----------------------------------------------------------------------- '''
''' ----------------------------------------------------------------------- '''
# Compute X1 Point Cloud Centroid To Remove It
mean_x, mean_y, mean_z = np.mean(X1), np.mean(Y1), np.mean(Z1)
fixed = np.array([X1 - mean_x, Y1 - mean_y, Z1 - mean_z]).T
moving = np.array([X2 - mean_x, Y2 - mean_y, Z2 - mean_z]).T
''' ************************ Run GA registration ************************ '''
# bounds6 = np.array([[-0.1, 0.1], [-0.1, 0.1], [-0.1, 0.1], [-1, 1], [-1, 1], [-1, 1]]) * 3
# bounds3 = np.array([[-1, 1], [-1, 1], [-1, 1]]) * 5
# config = dict([("population_size", 40),
# ("num_params", 3),
# ("num_bits", 10),
# ("bounds", bounds3),
# ("selection", "roulette wheel"),
# ("selection_rate", 1),
# ("cross_over", "two_point"),
# ("mutation_rate", 0.05),
# ("max_generations", 40),
# ("epsilon", 1e-9)],)
# g = GA_real.GA(fixed, Normal, moving, output_file, config)
# g.run_ga()
# # fig = plt.figure()
# # plt.plot(g.score)
# ind_best = np.argmin(np.array(g.score))
# print("\n the best solution after {} generations has a fitness score of {} and is as follows:".format(ind_best + 1, np.round(np.min(g.score), 4)))
# print(g.best)
''' ************************ Run ICP registration ************************ '''
configs = {
'bounds' :None,
'method' : 'translation_only',
'prop_errors' : True,
'threshold' : 0,
'window_size' :50,
'step_size' : 50,
'margin': 2,
'min_points' : 50,
'converge' : 0.000001,
'max_iter' : 40,
'outlier_multiplier' : 5,
'outlier_percent' : 0.95,
'output_basename' : 'trans_icp_results'
}
config = compare_with_icp.icp_configs(configs)
res1, RMSE, Max = compare_with_icp.transicp(moving, fixed, Normal, config)