这是一个创建于 1987 天前的主题,其中的信息可能已经有所发展或是发生改变。
我编了一个图像处理的程序,因为运行比较慢,所以去网上找了一下用多进程处理的方法,结果运行到图像合成的步骤就出错了,不知道怎么回事,代码如下:
if __name__ == '__main__':
img = cv2.imread('./2.jpg', cv2.IMREAD_ANYCOLOR)
image_0_1 = img/255
image = list(cv2.split(image_0_1))
gf1=Process(target=lvboout,kwargs={'img':image[0],})
gf2=Process(target=lvboout,kwargs={'img':image[1],})
gf3=Process(target=lvboout,kwargs={'img':image[2],})
gf1.start()
gf2.start()
gf3.start()
gf1.join()
gf2.join()
gf3.join()
'''gf1=lvboout(image[0])
gf2=lvboout(image[1])
gf3=lvboout(image[2])'''
gf = cv2.merge([gf1, gf2, gf3])
引号部分是原程序,运行没问题,错误提示是:mv is not a numpy array,neither a scalar
|
|
1
tottea 2019-05-02 18:59:54 +08:00 via iPhone
试下把入参转成 numpy array
|
|
|
2
mushuiyu 2019-05-03 09:55:57 +08:00
我调用 gf1 的数据看了一下,是返回值的问题,直接用 process 赋值的话,最后返回的是进程数据,不是函数的返回值。我去网上查了一下后,改用 pool 进程池,程序改为如下: pool = multiprocessing.Pool(processes = 3) results = [] for i in range(3): results.append(pool.apply_async(lvboout,(image[i],))) pool.close() pool.join()
gf1 = results[0].get() gf2 = results[1].get() gf3 = results[2].get() 最后得到的 gf1,gf2 和 gf3 就是函数的返回值了,接下来也没问题了。
|