【发布时间】:2014-04-16 16:36:43
【问题描述】:
我是 Python/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 pythonware.com/products/pil/#pil117。它具有这些功能,并且与 ndarray 之间的转换非常简单
-
如果你打算使用 PIL,你应该试试它的 fork
pillow,这是一个更新版本,也兼容 Python 3。
标签: python arrays opencv numpy