1
我想要搜索图片中的矩形。这张照片是从PIL收集的。这意味着我会得到一个2d数组,其中每个项目都是一个带有三个颜色条目的列表。numpy.equal与嵌套列表
要使用搜索的颜色得到矩形的位置,我使用的是np.equal
。这里的缩水下来例如:
>>> l = np.array([[1,1], [2,1], [2,2], [1,0]])
>>> np.equal(l, [2,1]) # where [2,1] is the searched color
array([[False, True],
[ True, True],
[ True, False],
[False, False]], dtype=bool)
但我预计:
array([False, True, False, False], dtype=bool)
或
array([[False, False],
[ True, True],
[ False, False],
[False, False]], dtype=bool)
我怎样才能实现与numpy
嵌套列表比较呢?
注意:然后我想用np.where
从np.equal
的结果中提取矩形的索引。
取决于你想做什么可能是一种矫枉过正,但是你可以用'scipy.ndimage.filters.correlate'执行模板匹配(在图片中寻找一个固定结构的对象),并获取相关位置最大值为'result [numpy.argwhere(result == result.max())]'。 – heltonbiker