OpenCV显示灰色窗口 [英] OpenCV Shows Gray Window
问题描述
我正在尝试使用OpenCV显示图像.我有以下非常基本的代码:
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)
以正确的大小正确打开了窗口,但是它是灰色的-没有图像.图像已正确读取(在调试器中同时查看img和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...
推荐答案
好的,知道了.
结果是我需要让OpenCV开始处理事件,但没有处理WM_PAINT事件.添加cv2.waitKey()可以解决此问题.
Turns out I needed to let OpenCV start handling events, it wasn't handling the WM_PAINT event. Adding cv2.waitKey() fixed this.
这篇关于OpenCV显示灰色窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!