OpenCV,网络摄像头 window 未打开
OpenCV, webcam window not opening
我对计算机视觉和使用 OpenCV 库的一些基本功能非常陌生,例如为相机打开 window。我使用了 OpenCV 书中的代码,我 运行 那里的代码。部分如下图:
def run(self):
"""Run the main loop"""
self._windowManager.createWindow()
while self._windowManager.isWindowCreated:
self._captureManager.enterFrame()
frame = self._captureManager.frame
self._captureManager.exitFrame()
self._windowManager.processEvents()
我收到以下错误:
'module' object has no attribute 'nameWindow'
这是它指向的行:
139 def createWindow (self):
140 cv2.namedWindow(self._windowName)
--> 141 self._isWindowCreated = True
142 def show(self, frame):
143 cv2.imshow(self._windowName, frame)
谁能帮我看看这是怎么回事?
很难从代码中判断问题出在哪里,但我相信 cv2.namedWindow()
不是 nameWindow
。此外,在 imshow()
函数调用之后添加 cv2.waitKey(1)
。
这是使用 python 和 opencv 打开网络摄像头的更简单方法:
import cv2
video_capture = cv2.VideoCapture(0)
cv2.namedWindow("Window")
while True:
ret, frame = video_capture.read()
cv2.imshow("Window", frame)
#This breaks on 'q' key
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video_capture.release()
cv2.destroyAllWindows()
我对计算机视觉和使用 OpenCV 库的一些基本功能非常陌生,例如为相机打开 window。我使用了 OpenCV 书中的代码,我 运行 那里的代码。部分如下图:
def run(self):
"""Run the main loop"""
self._windowManager.createWindow()
while self._windowManager.isWindowCreated:
self._captureManager.enterFrame()
frame = self._captureManager.frame
self._captureManager.exitFrame()
self._windowManager.processEvents()
我收到以下错误:
'module' object has no attribute 'nameWindow'
这是它指向的行:
139 def createWindow (self):
140 cv2.namedWindow(self._windowName)
--> 141 self._isWindowCreated = True
142 def show(self, frame):
143 cv2.imshow(self._windowName, frame)
谁能帮我看看这是怎么回事?
很难从代码中判断问题出在哪里,但我相信 cv2.namedWindow()
不是 nameWindow
。此外,在 imshow()
函数调用之后添加 cv2.waitKey(1)
。
这是使用 python 和 opencv 打开网络摄像头的更简单方法:
import cv2
video_capture = cv2.VideoCapture(0)
cv2.namedWindow("Window")
while True:
ret, frame = video_capture.read()
cv2.imshow("Window", frame)
#This breaks on 'q' key
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video_capture.release()
cv2.destroyAllWindows()