本文主要是介绍1223西站坐标更新,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1223 西站坐标更新
1.Update for the station’s location
def initial_out_map_indoor_points(self):'''Load the indoor data and update both the wall_matrix and the ditch_matrix.'''# Initialize the wall_matrix# List of coordinatescoordinates = [(417, 287, 417, 290),(414, 254, 414, 257),(412, 222, 412, 225),(411, 209, 411, 211),(411, 203, 411, 205),(567, 275, 567, 276),(566, 268, 566, 270),(566, 261, 566, 263),(565, 247, 565, 249),(563, 215, 563, 218),(561, 189, 561, 192),(407, 238, 407, 245),(570, 226, 570, 234),(464, 291, 466, 292),(518, 288, 521, 288),(457, 187, 459, 187),(511, 183, 513, 183)]coordinates = self.sort_segments_clockwise(coordinates)last_pointx,last_pointy=0,0temp_no=0# Fill in the wall_matrixfor x1, y1, x2, y2 in coordinates:# apply the process of wall's calculationpoints = bresenham_line(x1, y1, x2, y2) # find all the points within the straight linefor x, y in points:if 0 <= x < len(self.wall_matrix) and 0 <= y < len(self.wall_matrix[0]):self.wall_matrix[int(x), int(y)] = 1 # Remember the location of the wall.if temp_no>=1 and calculate_distance(last_pointx,last_pointy,x1,y1)<=1000:points=bresenham_line(last_pointx,last_pointy,x1,y1)for x, y in points:if 0 <= x < len(self.wall_matrix) and 0 <= y < len(self.wall_matrix[0]):self.wall_matrix[int(x), int(y)] = 1 # Remember the location of the wall.# if calculate_distance(last_pointx,last_pointy,x1,y1)>100:# print(f'Out of range:(x1:{x},y1:{y})')temp_no=temp_no+1last_pointx,last_pointy=x2,y2begin_x1,begin_y1,begin_x2,begin_y2=coordinates[0]print(f'begin_x1:{begin_x1},begin_y1:{begin_y1},begin_x2:{begin_x2},begin_y2:{begin_y2}')points = bresenham_line(begin_x1, begin_y1, x2, y2) # find all the points within the straight linefor x, y in points:if 0 <= x < len(self.wall_matrix) and 0 <= y < len(self.wall_matrix[0]):self.wall_matrix[int(x), int(y)] = 1 # Remember the location of the wall.self.wall_matrix = self.fill_area(self.wall_matrix, target_value=1)# Update the location to the overall matrixself.outdoor_label[self.wall_matrix == 1] = 1df=pd.DataFrame(self.wall_matrix)df.to_csv('G:/HZXZ/Hws-Mirror-City/water_indoor/Model2_data/outdoor_data/temp_data/wall_matrix.csv', index=False)# label the location of the doorcurrent_dir = os.path.dirname(os.path.abspath(__file__))data_path = os.path.join(current_dir, 'Model2_data/outdoor_data/out_in_map_points.xlsx')data = pd.read_excel(data_path)for _, row in data.iterrows():# load the door coordinates and finish the transferid, x1, y1, x2, y2 = row['id'], row['x1'], row['y1'], row['x2'], row['y2']x1, y1 = self.indoor_transfer.cad2ue(x1, y1)x2, y2 = self.indoor_transfer.cad2ue(x2, y2)index_x1, index_y1 = self.outdoor_transer.ue2index_model2(x1, y1,self.scaled_width,self.scaled_height)index_x2, index_y2 = self.outdoor_transer.ue2index_model2(x2, y2,self.scaled_width,self.scaled_height)index_x1, index_y1, index_x2, index_y2 = int(index_x1), int(index_y1), int(index_x2), int(index_y2)if index_y1 > index_y2:tmp = index_y1index_y1 = index_y2index_y2 = tmp# print(f'x1:{index_x1}, x2:{index_x2}, y1:{index_y1}, y2:{index_y2}')# label the location of the indoor doorsif index_x1 == index_x2:self.outdoor_label[index_x1, index_y1:index_y2] = 5elif index_y1 == index_y2:self.outdoor_label[index_x1:index_x2, index_y1] = 5else:self.outdoor_label[index_x1:index_x2, index_y1:index_y2] = 5# self.wall_matrix = self.fill_area(self.wall_matrix, target_value=1) # fill the circled area
新增函数
def calculate_midpoint(self,segment):return ((segment[0] + segment[2]) / 2, (segment[1] + segment[3]) / 2)def calculate_centroid(self,segments):x_sum, y_sum = 0, 0for segment in segments:midpoint = self.calculate_midpoint(segment)x_sum += midpoint[0]y_sum += midpoint[1]return x_sum / len(segments), y_sum / len(segments)def calculate_angle(self,centroid, point):return math.atan2(point[1] - centroid[1], point[0] - centroid[0])def sort_segments_clockwise(self,segments):centroid = self.calculate_centroid(segments)return sorted(segments, key=lambda segment: self.calculate_angle(centroid, self.calculate_midpoint(segment)))
更细的函数
def showOutdoorImg(self, outdoor_acc_water_matrix):"""opencv可视化降雨量矩阵结果input: rainfall_matrixoutput: null"""# 获取矩阵中的最大值和对应的下标max_value = np.max(outdoor_acc_water_matrix)max_index = np.argmax(outdoor_acc_water_matrix)# 将一维下标转换为二维下标max_index_2d = np.unravel_index(max_index, outdoor_acc_water_matrix.shape)print(f'the largest water logging is {max_value}, the index is {max_index_2d}')mat = np.transpose(np.copy(outdoor_acc_water_matrix))[::-1]# 归一化矩阵# mat = cv2.normalize(mat, None, 200, 250, cv2.NORM_MINMAX, dtype=cv2.CV_8UC3)mat = mat / 300 * 250mat[mat > 250] = 250mat[mat < 30] = 30mat = mat.astype(np.uint8)mat = cv2.cvtColor(mat, cv2.COLOR_RGB2BGR)# 自定义颜色映射表custom_colormap = create_custom_colormap()# 将矩阵映射到蓝色色域image = cv2.applyColorMap(mat, custom_colormap)label = np.transpose(self.outdoor_label)[::-1]outdoor_acc_water_matrix = np.transpose(outdoor_acc_water_matrix)[::-1]image[outdoor_acc_water_matrix < 2] = [255, 255, 255] # 积水为0设置为白色image[label == 1] = [0,255,255] # 墙体设置为黄色image[label == 2] = 0 # 路面设置为黑色image[label == 3] = [0, 0, 255] # 河流部分设置为(30,144,255)image[label == 5] = [0, 255, 0] # 河流部分设置为(30,144,255)# image[label == 4] = [0, 255, 0]image[label == 9] = [25, 74, 230]image = cv2.resize(image, None, None, 1, 1, cv2.INTER_NEAREST)# 插入西站图片# west_station_img = cv2.imread('Model2_data/outdoor_data/west_station.png')# x, y = int(108*self.resize_scale), int(54*self.resize_scale)# west_station_img = cv2.resize(west_station_img, None, None, self.resize_scale, self.resize_scale, cv2.INTER_NEAREST)# image[y:y + west_station_img.shape[0], x:x + west_station_img.shape[1]] = west_station_imgcv2.imwrite(f'result/outdoor_imgs/time_stamp{self.time_stamp}.png', image)cv2.imwrite(f'Model2_data/outdoor_data/temp_data/time_stamp{self.time_stamp}.png', image)if self.__debug_mode:# 显示图像cv2.imshow("OutdoorImage", image)cv2.waitKey(500)# cv2.destroyAllWindows()
def initialMatrix(self):'''水体系统,初步生成室外降水 渗透 地势三个matrix0.土壤1.墙体2.道路3.河流4.沟渠5.室内外映射点位9.易涝点初步生成室内地势matrix1.ditch2.wall3.Stair4.RoadStair'''# 初始化outdoor_label矩阵soil_label = 0walls_label = 1roads_label = 2river_label = 3ditch_label = 4infinite = np.inf # 设置较大的值代表河流的渗透是无穷的infiltration_standard = 2 # 渗透量国标# 初始化地势图中各处的高度walls_height = np.infroads_height = 0river_height = -1ditch_height = -10# 室内初始化self.indoor_topographic_matrix[self.indoor_label == 1] = ditch_heightself.indoor_topographic_matrix[self.indoor_label == 2] = infinite# path = 'Model2_data/outdoor_data/'# np.save(path+'road_matrix_test.npy', self.road_matrix)# road_matrix = np.load(path+'road_matrix_test.npy')# 室外初始化# 对标签矩阵作转换,转换到UE矩阵中去# self.wall_matrix = self.outdoor_transer.four_point_transform(self.wall_matrix)# self.river_matrix = self.outdoor_transer.four_point_transform(self.river_matrix)# self.ditch_matrix = self.outdoor_transer.four_point_transform(self.ditch_matrix)# self.road_matrix = self.outdoor_transer.four_point_transform(self.road_matrix)# 初始化降雨矩阵soil_mask = (self.wall_matrix == 0) & (self.road_matrix == 0) & (self.river_matrix == 0) & (self.ditch_matrix == 0)self.rainfall_matrix[self.wall_matrix == 1] = 0self.rainfall_matrix[self.wall_matrix == 0] = 1# UE转为地势矩阵&初始化特殊地势矩阵self.initial_topographic_matrix()# print(f'topographic_matrix non zero points num is {np.count_nonzero(self.outdoor_topographic_matrix)}')self.outdoor_topographic_matrix[self.wall_matrix == 1] = walls_height# self.outdoor_topographic_matrix[self.road_matrix == 1] = roads_height# self.outdoor_topographic_matrix[self.river_matrix == 1] = river_heightself.outdoor_topographic_matrix[self.ditch_matrix == 1] = ditch_height# 西站坐标初始化# random_values = np.random.randint(-10, 10, size=np.count_nonzero(soil_mask))# self.outdoor_topographic_matrix[soil_mask] = random_values# 初始化标签self.outdoor_label[soil_mask] = soil_label# Updated way of labeling both the station and the ditchself.initial_out_map_indoor_points()self.outdoor_label[self.road_matrix == 1] = roads_label# self.outdoor_label[self.river_matrix == 1] = river_labelself.outdoor_label[self.ditch_matrix == 1] = ditch_label# self.outdoor_label[self.wall_matrix == 1] = walls_label# Realize this function.self.initial_river()df=pd.DataFrame(self.outdoor_label)df.to_csv('G:/HZXZ/Hws-Mirror-City/water_indoor/Model2_data/outdoor_data/temp_data/outdoor_label.csv', index=False)print(f'temporary numbers: {np.unique(self.outdoor_label)}')self.initial_prone_waterlogging_points()# 室内外映射点位初始化# for index in range(len(self.outdoor_map_indoor) // 2):# for (i, j) in self.outdoor_map_indoor[f'outdoor_point{index + 1}']:# self.outdoor_topographic_matrix[i][j] = 0# self.outdoor_label[i][j] = 5pass
Final Output
这篇关于1223西站坐标更新的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!