我试图使用np的矢量化,但imshow显示的是一个黑色图像,如果我正确理解矢量化,它应该是白色的。我想问题出在outputtype,但我不能让它工作。在
import numpy as np
import cv2
class Test():
def run(self):
arr = np.zeros((25,25))
arr[:]=255
cv2.imshow('white',arr)
flatarr = np.reshape(arr,25*25)
vfunc = np.vectorize(self.func)
#vfunc = np.vectorize(self.func,otypes=[np.int])#same effect
flatres = vfunc(flatarr)
shouldbewhite = np.reshape(flatres,(25,25))
cv2.imshow('shouldbewhite',shouldbewhite)
def func(self,a):
return 255
cv2.namedWindow('white',0)
cv2.namedWindow('shouldbewhite',0)
a = Test()
a.run()
cv2.waitKey(0)
从docs:
如果运行以下代码:
你会得到类似于:
^{pr2}$所以你的第二个例子被256除,它是整数除法,取整为0。试试看
您还可以考虑将第一个数组替换为
相关问题 更多 >
编程相关推荐