我是一条新Python。在
我写了一些代码尝试混合图片到一个新的图片。在
我做完了,但浪费了太多时间。在
所以我试着用Numba让代码在我的gpu上工作。 但是遇到了一些警告和错误
os Ubuntu 16
pyhton version 3.5
for i in piclist:
img = cv2.imread(str(filepath)+'/'+str(i))
print (i)
b,g,r = cv2.split(img)
bcolorlist.append(b)
gcolorlist.append(g)
rcolorlist.append(r)
@jit(nopython = True)
def select(bcolorlist,gcolorlist,rcolorlist):
for i in range(len(bcolorlist)):
b = bcolorlist[i].reshape(2073600,1)
g = gcolorlist[i].reshape(2073600,1)
r = rcolorlist[i].reshape(2073600,1)
bcolorlist[i] = b
gcolorlist[i] = g
rcolorlist[i] = r
bbb = np.concatenate(bcolorlist, axis=1)
ggg = np.concatenate(gcolorlist, axis=1)
rrr = np.concatenate(rcolorlist, axis=1)
newb = []
newg = []
newr = []
for line in bbb:
newb.append(np.argmax(np.bincount(line)))
newb = np.array(newb)
for line in ggg:
newg.append(np.argmax(np.bincount(line)))
newg = np.array(newg)
for line in rrr:
newr.append(np.argmax(np.bincount(line)))
newr = np.array(newr)
return newb,newg,newr
没有@jit
也能正常工作
但是使用@jit
将显示下面的消息
test.py:61: NumbaWarning: Compilation is falling back to object mode WITH looplifting enabled because Function "select" failed type inference due to: Invalid use of Function() with argument(s) of type(s): (reflected list(array(uint8, 2d, C)), axis=Literalint)
根据建议立即更新代码
^{pr2}$一切正常!!!!在
但它不能生成输出图像。。。。。在
麻烦你给点建议好吗?在
更新—以rgb图像作为输入的工作示例。我以前没有用Python做过图像处理,所以这是一次不错的旅行。下面是一些代码。请注意,我为函数添加了一些输入参数,以使其更加通用。我还更改了一些变量名,但这只是一个口味问题,所以不用担心。在
…会产生这样奇怪的东西:
相关问题 更多 >
编程相关推荐