我得到了一个名为cartoonize(image_path)
的函数,它以'path/to/image'作为参数。这个脚本有点大,需要几分钟来处理一个1920x1080大小的图像。我试着用8 cores
和multiprocessing module
来使用我所有的8 cores
,但是在下面的代码中没有看到性能提升。另一个问题是如何保存图像。它返回一个CV2对象。通常情况下,我通过see below code
将映像保存到磁盘上,但是使用多处理会产生错误"img is not a numpy array, neither a scalar."
我还希望获得性能提升,但我不知道如何有效地做到这一点。你知道吗
out_final = cartoonize('path/to/image'))
cv2.imwrite('cartoon.png', out_final)
import multiprocessing
if __name__ == '__main__':
# mark the start time
startTime = time.time()
print "cartoonizing please wait ..."
pool = multiprocessing.Pool(processes=multiprocessing.cpu_count())
pool_outputs = pool.apply_async(cartoonize, args=(image_path,))
pool.close()
pool.join()
print ('Pool:', pool_outputs)
# mark the end time
endTime = time.time()
print('Took %.3f seconds' % (startTime - endTime))
您的代码返回
AsyncResult
相关问题 更多 >
编程相关推荐