gpt4 book ai didi

python - .dilate()OpenCV的替代方法

转载 作者:行者123 更新时间:2023-12-02 17:41:09 24 4
gpt4 key购买 nike

我在脚本中使用cv2Pillow:

image = Image.open("img1.png")
#do some stuff to the image
image.save("result1.png")

image = cv2.imread("result1.png")
kernel = np.ones((5, 5), np.uint8)
dilated_image = cv2.dilate(image, kernel, iterations=3)
cv2.imwrite("result2.png", dilated_image)

final_image = Image.open("result2.png")
#do some other stuff to the image
final_image.save("final_result.png")

如您所见,我必须在 OpenCVPillow之间切换,并保存三个图像。我想要的只是保存 一个结果,而不是 三个

有没有一种方法,我可以继续使用Pillow,以几乎与 相同的执行速度扩展图像,而无需使用cv2?

我已经尝试过 image.filter(ImageFilter.MaxFilter(size=3)),但是它占用了太多的CPU时间。花费太多时间的原因是,为了获得与oj​​it_code相同的效果,我至少应使用 cv2.dilate(image, kernel, iterations=5)

最佳答案

如果您只是在为标准库中的功能寻找OpenCV替代品,则可以尝试SciPy的功能(SO Question here)

关于python - .dilate()OpenCV的替代方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44887958/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com