処理が良くわかっていないのでdstの値が255のもののx座標がxであるときのyの最小値と最大値を取り出す方法を書いておきますので、これを参考にしてください。
python
1>>> x = 10
2>>> print(dst)
3[[ 0 0 0 ... 255 255 255]
4 [ 0 0 0 ... 0 255 255]
5 [255 0 0 ... 255 255 255]
6 ...
7 [255 255 255 ... 255 255 255]
8 [255 255 255 ... 255 255 255]
9 [255 255 255 ... 255 255 255]]
10>>> print(dst.shape)
11(333, 500)
12>>> x_columns = dst[:,x]
13>>> print(x_columns)
14[ 0 0 0 0 255 255 0 0 0 255 255 255 255 255 255 255 255 255
15 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
16 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
17 255 0 0 255 0 255 0 255 0 255 255 0 255 255 255 255 0 0
18 255 255 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
19 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
20 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
21 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
22 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
23 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
24 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
25 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
26 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
27 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
28 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
29 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
30 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
31 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
32 255 255 255 255 255 255 255 255 255]
33>>> x_positions = np.where(x_columns == 255)
34>>> print(x_positions)
35(array([ 4, 5, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
36 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
37 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
38 46, 47, 48, 49, 50, 51, 52, 53, 54, 57, 59, 61, 63,
39 64, 66, 67, 68, 69, 72, 73, 75, 76, 77, 78, 79, 80,
40 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
41 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
42 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
43 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132,
44 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
45 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158,
46 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171,
47 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
48 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197,
49 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210,
50 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
51 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236,
52 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249,
53 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262,
54 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275,
55 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288,
56 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301,
57 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
58 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327,
59 328, 329, 330, 331, 332], dtype=int64),)
60>>> y_min = np.min(x_positions)
61>>> y_max = np.max(x_positions)
62>>> print(f'上の座標は({x}, {y_min})')
63上の座標は(10, 4)
64>>> print(f'下の座標は({x}, {y_max})')
65下の座標は(10, 332)
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/05/19 14:53
2021/05/24 22:41