M = [[0.0 for i in range(grid_num_x)] for j in range(grid_num_y)] width3, height3 = cropped_image.size # 对于每个栅格 for i in range(1,grid_num_y+1): for j in range(1,grid_num_x+1): x0 = width3//2-GRID_STEPgrid_num_x//2 y0 = height3//2-GRID_STEPgrid_num_y//2 if any((x0 + GRID_STEP * i < x < x0 + GRID_STEP * (i+1) and y0 + GRID_STEP * j < y < y0 + GRID_STEP * (j+1)) for x, y in points3): M[i-1][j-1]=100 else: M[i-1][j-1]=100 提取出上述代码每一个ij对应的左上角坐标,储存在集合result中
时间: 2023-06-18 17:05:29 浏览: 82
BepInEx_x64_5.1.0.0_bepinex5.0.1_BepInEx_x64_bepinex5.0.1_BepInE
5星 · 资源好评率100%
可以将左上角坐标存储在一个列表中,每个元素为一个二元组,表示第i行第j列的左上角坐标。可以使用如下代码实现:
result = [(width3//2-GRID_STEP*grid_num_x//2 + j*GRID_STEP, height3//2-GRID_STEP*grid_num_y//2 + i*GRID_STEP) for i in range(grid_num_y) for j in range(grid_num_x)]
其中,i和j的顺序是先遍历列,再遍历行,与代码中的M[i-1][j-1]对应。
阅读全文