[英]cv2.imshow() function isn't displaying anything when I call it
I'm following one of the openCV python tutorials on displaying a live video feed from your camera.我正在关注有关显示来自相机的实时视频源的 openCV python 教程之一。 When I run the program, the green light for the webcam comes on (as I'm on a Mac) and there aren't any errors.
当我运行程序时,网络摄像头的绿灯亮起(因为我在 Mac 上)并且没有任何错误。 Theres also a python rocketship thing that comes up in my dock, but it doesn't show any windows or anything.
还有一个 python 火箭飞船出现在我的码头上,但它没有显示任何窗口或任何东西。 This also happens when I try and display one image.
当我尝试显示一张图像时也会发生这种情况。
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
This is the code I'm using.这是我正在使用的代码。 Any help would be much appreciated.
任何帮助将非常感激。 Thanks
谢谢
Try to use cv.named Window command
to open a new window :尝试使用
cv.named Window command
打开一个新窗口:
cv2.namedWindow('frame', cv2.WINDOW_AUTOSIZE)
cv2.imshow('frame',gray)
cv2.WaitKey(1)
cv2.destroyAllWindows()
I hope this works well with you我希望这对你很有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.