Reputation: 907
I am very new to computer vision and using the OpenCV libraries for some basic functions like opening a window for the camera. I used the code from the OpenCV book I run a code from there. A part is shown below:
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()
I get the following error:
'module' object has no attribute 'nameWindow'
And this the line it points to:
139 def createWindow (self):
140 cv2.namedWindow(self._windowName)
--> 141 self._isWindowCreated = True
142 def show(self, frame):
143 cv2.imshow(self._windowName, frame)
Can someone help me what's going on?
Upvotes: 1
Views: 11538
Reputation: 507
It's hard to say from the code what the problem is, but I believe is cv2.namedWindow()
not nameWindow
. Also, add cv2.waitKey(1)
after the imshow()
function call.
Here's a simpler way to open the webcam using python and 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()
Upvotes: 5