gpt4 book ai didi

python - 在 python 中使用 cv2 模块查看二进制图像之类的图像(进入循环)

转载 作者:太空宇宙 更新时间:2023-11-03 22:06:34 24 4
gpt4 key购买 nike

我再次尝试更好地解决我的问题 (http://stackoverflow.com/questions/14349550/convert-image-in-a-binary-image-with-cv2-module-in-python)

在这段代码中(与第一段相比有一点变化)我可以很容易地使用转换后的二值图像,提取轮廓,计算面积......但是不可能再次执行此代码行:cv2.imshow ('gray_image',imgray).

它向我展示了一个完全灰色的窗口,仅此而已。我必须退出 python,因为会进入循环。

imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray,127,255,0)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
print('oggetti trovati')
print(len(contours))
cnt = contours[0]
print(len(cnt))
cv2.imshow('gray_image',imgray)

我能做什么?

最佳答案

这里需要在cv2.imshow('gray_image',imgray)之后添加cv2.waitKey()。此函数用于处理任何窗口事件,例如在 OpenCV 中创建或显示图像。

关于python - 在 python 中使用 cv2 模块查看二进制图像之类的图像(进入循环),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14370677/

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