3
我是Python/numpy的新手。擴展numpy數組
我試圖擴展numpy.array,使它具有一些使圖像更好的功能(例如轉換爲灰度等)。
import numpy as np
import cv2
from support import *
import matplotlib.pyplot as plt
class Frame(np.array):
def __init__(self):
print "new frame"
f = Frame()
目前這給了我:
File "o.py", line 6, in <module>
class Frame(np.array):
TypeError: Error when calling the metaclass bases
cannot create 'builtin_function_or_method' instances
我不明白爲什麼這是Python的一個問題?
正如一個側面說明你應該看看:PIL Python Imaging Library http://www.pythonware.com/products/pil/#pil117。 它具有這些能力,並且從ndarray轉換到/從ndarray轉換是非常簡單 – odedsh
如果你打算去PIL,你應該嘗試它的叉['pillow'](http://pillow.readthedocs.org/en/latest/ ),這是一個更新的版本,它也與Python 3兼容。 –