2017-12-17 17 views
0

저는 최근 opencv에서 작업하고 있습니다. 내 우분투 16.04에 설치했습니다. 나는 그것이 몇 가지 문제가 있다고 생각한다. 나는 함수는이 오류를 야기cv2.imshow() 구현 중 문제가 발생했습니다

cv2.imshow('frame',frame) 

를 실행하려고 할 때마다

OpenCV Error: Unspecified error (The function is not implemented. 
Rebuild the library with Windows, GTK+ 2.x or Carbon support. 
If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /tmp/build/80754af9/opencv_1512687413662/work/modules/highgui/src/window.cpp, line 611 
Traceback (most recent call last): 
    File "hands.py", line 12, in <module> 
    cv2.imshow('frame',frame) 
    cv2.error: /tmp/build/80754af9/opencv_1512687413662/work/modules/highgui/src/window. 
cpp:611: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon 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 

내가 실행하려고 코드는 내가 가능한 모든 일을 Google에 노력하고있어 모든 것을했다

import numpy as numpy 
import cv2 
import matplotlib.pyplot as plt 

cap = cv2.VideoCapture(0) 
bg = cv2.bgsegm.createBackgroundSubtractorMOG() 

while True: 
    ret,frame = cap.read() 
    vid = bg.apply(frame) 

    cv2.imshow('frame',frame) 
    cv2.imshow('vid',vid) 
    key = cv2.waitKey(0) & 0xff 
    if key == 27: 
     break 

cap.release() 
cap.destroyAllWindows() 

입니다 가능하지만 여전히 문제를 해결할 수는 없습니다.

내가 대신

cv2.imshow('frame',frame) 

matplotlib.pyplot.imshow('frame',frame) 
matplotlib.pyplot.show() 

를 사용하여 시도하지만이 웹캠에서 캡처 한 비디오를 표시하는 오류를

TypeError: unhashable type: 'numpy.ndarray' 

을 제공합니다. 비디오 또는이 오류 대신 cv2.waitkey()에서 이미지 및 오류 만 표시합니다. 이 오류를 해결할 방법이 있습니까? 또는 cv2 GUI 기능을 구현하려면?

+0

가 읽어주십시오과 [mcve] 이해를 참조 할 것이다. 오류를 얻기 위해 실행중인 코드가 명확하지 않습니다. 여기서 어떻게 도와야합니까? – ImportanceOfBeingErnest

+0

불완전한 질문에 대한 미안 해요, 내 코드 조각을 게시했습니다. 그걸로 나를 도울 수 있니? – Darshan

답변

0

cv2 설치에 문제가있는 것 같습니다. 나는 그걸 도울 수 없지만 재설치하고 시스템에 적합한 버전 (OS, 비트 깊이 및 파이썬 버전과 일치)이 사용되는지 확인하는 것이 좋습니다.

해결 방법으로 이미지를 표시하기 위해 실제로 matplotlib를 사용할 수 있습니다. 최소한의 예는

import cv2 
import matplotlib.pyplot as plt 

cap = cv2.VideoCapture(0) 

plt.ion() 
fig, ax = plt.subplots() 
ret,frame = cap.read() 
im = ax.imshow(frame) 

while True: 
    ret,frame = cap.read() 
    im.set_data(frame) 
    plt.pause(0.5) 

plt.ioff() 
plt.show() 

는 또한 update frame in matplotlib with live camera preview

+0

답변 주셔서 감사하지만이 오류가 발생합니다. '이미지 데이터를 float으로 변환 할 수 없습니다 .' – Darshan

+0

마지막 줄이 충분하지 않아 전체 오류 추적을 알아야합니다. – ImportanceOfBeingErnest

+0

'----> 9 im = ax.imshow (frame)' – Darshan