cv2.imshow 错误“功能未实现”

Posted

技术标签:

【中文标题】cv2.imshow 错误“功能未实现”【英文标题】:cv2.imshow error "The function is not implemented" 【发布时间】:2019-07-24 14:39:27 【问题描述】:

我正在尝试连接到我的笔记本电脑摄像头作为实时流媒体,但它不起作用。 cv2.imshow() 引发错误。我在 Windows 10 上使用 Python 3.6 和 OpenCV 4.1.0。

我尝试重建库 GTK+ 2.x,但没有任何改变。

import cv2

cap = cv2.VideoCapture(0)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))

while True:
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow('frame', gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

这是错误:

Traceback (most recent call last):
  File "C:/Users/hiba/PycharmProjects/Python for CV/12-Connecting_to_Camera.py", line 21, in <module>
    cv2.imshow('frame', gray)
cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:627: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'

[ WARN:0] terminating async callback

Process finished with exit code 1

【问题讨论】:

【参考方案1】:
pip install opencv-contrib-python

【讨论】:

以上是关于cv2.imshow 错误“功能未实现”的主要内容,如果未能解决你的问题,请参考以下文章