【发布时间】:2017-03-24 04:41:37
【问题描述】:
我正在使用此代码来检测图像中的绿色。
问题是这个迭代真的很慢。
如何让它更快?如果是使用 numpy,如何使用 numpy 的方式呢?
def convertGreen(rawimg):
width, height, channels = rawimg.shape
size = (w, h, channels) = (width, height, 1)
processedimg = np.zeros(size, np.uint8)
for wimg in range(0,width):
for himg in range(0,height):
blue = rawimg.item(wimg,himg,0)
green = rawimg.item(wimg,himg,1)
red = rawimg.item(wimg,himg,2)
exg = 2*green-red-blue
if(exg > 50):
processedimg.itemset((wimg,himg,0),exg)
return processedimg
【问题讨论】:
标签: image-processing python opencv