【发布时间】:2012-02-28 23:28:42
【问题描述】:
我知道 SO 不是租用编码器,但我有一个非常简单的 python 示例,我需要帮助翻译成 C++
grey_image_as_array = numpy.asarray( cv.GetMat( grey_image ) )
non_black_coords_array = numpy.where( grey_image_as_array > 3 )
# Convert from numpy.where()'s two separate lists to one list of (x, y) tuples:
non_black_coords_array = zip( non_black_coords_array[1], non_black_coords_array[0] )
我猜第一个相当简单 - 创建一个线性可索引数组,其中包含从 cv.GetMat 中返回的字节,对吧?
什么相当于 pyton 的 where,尤其是这个 zip 函数?
【问题讨论】:
-
对于 zip,看看这个问题(你应该可以使用 boost::zip_iterator):stackoverflow.com/questions/8511035/…
-
您不需要在 C++ 等效项中使用
zip(),因为您会以non_black_coords_array立即具有所需结构的方式编写代码。在 Python 中需要它,因为您无法控制numpy.where()的输出格式。
标签: c++ python opencv numpy port