def get_mapself x1 x2 y1 y2 = 0 8191 0 8191 # selfbig_map40904097+540904097+5=255 while x1 8192 and npsumselfbig_mapx1 == 0 x1 += 1 while y1 8192 and
def get_map(self): # 取得地图的函数
# 设置地图的初始坐标
x1, x2, y1, y2 = 0, 8191, 0, 8191
# 寻找地图的左上角和右下角边缘,用于裁剪地图
while x1 < 8192 and np.sum(self.big_map[x1, :]) == 0:
x1 += 1
while y1 < 8192 and np.sum(self.big_map[:, y1]) == 0:
y1 += 1
while x2 > 0 and np.sum(self.big_map[x2, :]) == 0:
x2 -= 1
while y2 > 0 and np.sum(self.big_map[:, y2]) == 0:
y2 -= 1
# 如果地图的左上角和右下角坐标有误,则返回
if x1 >= x2 or y1 >= y2:
return
# 对地图进行深拷贝,并将值大于等于100的像素点置为255
tp = deepcopy(self.big_map[x1 - 1:x2 + 2, y1 - 1:y2 + 2])
tp[tp >= 100] = 255
# 对拷贝后的地图进行遍历,并将周围有255像素点的像素点置为255
bk = deepcopy(tp)
for i in range(tp.shape[0]):
for j in range(tp.shape[1]):
f = 0
for ii in range(0, 1):
for jj in range(0, 1):
if i + ii >= 0 and j + jj >= 0 and i + ii < tp.shape[0] and j + jj < tp.shape[1]:
if bk[i + ii, j + jj] == 255:
f = 1
break
if f:
tp[i, j] = 255
# 将像素点小于100的像素点置为0,并将地图保存为图片文件
tp[tp < 100] = 0
cv.imwrite(self.map_file + 'map_' + str(x1 - 1) + '_' + str(y1 - 1) + '_.jpg', tp)
cv.imwrite(self.map_file + 'target.jpg', tp
原文地址: https://www.cveoy.top/t/topic/fGeP 著作权归作者所有。请勿转载和采集!