OpenCV 显示灰色窗口
我正在尝试使用 OpenCV 显示图像。我有以下非常基本的代码:
import cv2
img = cv2.imread('myimage.png', 0) # Reads a Gray-scale image
img2 = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
cv2.imshow("window", img2)
窗口已正确打开,大小正确,但它是灰色的 - 没有图像。图像被正确读取(在调试器中查看 img 和 img2 我看到了预期值,而不仅仅是一种阴影)。
注意:显然我打算在显示图像之前进行一些图像处理,但首先我需要能够看到图像......
I'm trying to display an image using OpenCV. I have the following very basic code:
import cv2
img = cv2.imread('myimage.png', 0) # Reads a Gray-scale image
img2 = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
cv2.imshow("window", img2)
The window is opened properly, with the correct size, but it's gray - there's no image. The image is read properly (looking at both img and img2 in the debugger I see the expected values, not just one shade).
Note: Obviously I intend to do some image processing prior to showing the image, but first I need to be able to see the image...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,明白了。
结果我需要让 OpenCV 开始处理事件,它没有处理 WM_PAINT 事件。添加 cv2.waitKey() 修复了这个问题。
OK, got it.
Turns out I needed to let OpenCV start handling events, it wasn't handling the WM_PAINT event. Adding cv2.waitKey() fixed this.
有时图像大小对于
imshow()
来说足够大。尝试通过以下方式调整图像大小:
Sometimes the image size is high enough for
imshow()
.Try to resize the image by: