【问题标题】:OpenCV, webcam window not openingOpenCV,网络摄像头窗口未打开
【发布时间】:2017-02-09 16:15:54
【问题描述】:

我对计算机视觉非常陌生,并且将 OpenCV 库用于一些基本功能,例如为相机打开一个窗口。我使用了 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)

有人可以帮我看看这是怎么回事吗?

【问题讨论】:

    标签: python-2.7 opencv computer-vision


    【解决方案1】:

    很难从代码中说出问题所在,但我相信是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()
    

    【讨论】:

    • 感谢您的回复。问题出在我这边。我没有完全重新启动内核。这就是为什么即使我修复了它也会给我同样的错误。唯一的问题是,为什么编译器一次给我一个错误,而不是一次给我所有错误。
    猜你喜欢
    • 2012-12-20
    • 2017-09-25
    • 2017-01-29
    • 2020-03-06
    • 1970-01-01
    • 2013-01-21
    • 2020-09-10
    • 2012-06-12
    • 2015-08-18
    相关资源
    最近更新 更多