【发布时间】:2017-01-25 21:03:17
【问题描述】:
请原谅我提出的问题可能过于宽泛。但是,我的任务非常具体:对 Python 没有太多经验,我想将 Python 代码重写为 C++(OpenCV),我想知道是否有针对某些 C++ 库的良好文档比较(我知道存在 OpenBLAS、Eigen、等)这将允许我相对轻松地重复在原始代码中进行的所有数组操作,这对我使用 OpenCV 来说是一个相当大的挑战。也许有人真的写过关于语法比较的帖子?
Python 代码:
image = im_orig.copy()
# Create input for multiples of net input/output changes.
im_bg_width = int(_np.ceil(
float(image.shape[1]) * scale_factor / _STRIDE) * _STRIDE)
im_bg_height = int(_np.ceil(
float(image.shape[0]) * scale_factor / _STRIDE) * _STRIDE)
pad_size = 64
im_bot_pixels = image[-1:, :, :]
im_bot = _np.tile(im_bot_pixels, (pad_size, 1, 1))
image = _np.vstack((image, im_bot))
im_right_pixels = image[:, -1:, :]
im_right = _np.tile(im_right_pixels, (1, pad_size, 1))
image = _np.hstack((image, im_right))
image = _scipy.misc.imresize(image, scale_factor, interp='bilinear')
image = image.astype('float32') - _MEAN
net_input = _np.zeros((im_bg_height, im_bg_width, 3), dtype='float32')
net_input[:min(net_input.shape[0], image.shape[0]),
:min(net_input.shape[1], image.shape[1]), :] =\
image[:min(net_input.shape[0], image.shape[0]),
:min(net_input.shape[1], image.shape[1]), :]
编辑:我想不惜一切代价摆脱对 python 的依赖(尤其是来自 python C++ API),并让程序真正可读,这与 Cython 产生的不同。
【问题讨论】:
-
您可能想要搜索 C++ 数值库,但请注意,如果您使用 C++ 重写代码以提高性能,您可能会感到失望 — 好的 NumPy 代码往往很快开始与。
-
@DietrichEpp 谢谢,我知道 NumPy 很快,但不惜一切代价摆脱 Python 是必不可少的。
-
“不惜一切代价”不应该出现在工程师的词汇中:-)