将opencv函数应用于numpy数组

时间:2019-05-14 16:36:24

标签: python numpy

我有一些要灰度的图像阵列:

我尝试使用apply_over_axis,但是ndim出现问题?


import numpy as np
array = np.random.rand(1000, 720, 480, 3)

import cv2

def greyscale(array):
    result = cv2.cvtColor(array, cv2.COLOR_RGB2GRAY) 
    return result 

np.apply_over_axes(greyscaler, train, [0])

我希望最后一个命令能给我一个形状为numpy的数组:(1000, 720, 480, 1),但出现错误:

/opt/conda/lib/python3.6/site-packages/numpy/lib/shape_base.py in apply_over_axes(func, a, axes)
    459     """
    460     val = asarray(a)
--> 461     N = a.ndim
    462     if array(axes).ndim == 0:
    463         axes = (axes,)

AttributeError: 'dict' object has no attribute 'ndim'

0 个答案:

没有答案