1. 오류 전문
Traceback (most recent call last):
File "파일명", line 144, in <module>
if cv2.waitKey(1) == ord('q'):
cv2.error: OpenCV(4.10.0) /io/opencv/modules/highgui/src/window.cpp:1367: 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 'cvWaitKey'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "파일명", line 152, in <module>
cv2.destroyAllWindows()
cv2.error: OpenCV(4.10.0) /io/opencv/modules/highgui/src/window.cpp:1295: 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 'cvDestroyAllWindows'
2, 문제점
이 문제는 사용 중인 OpenCV 빌드에 GUI 지원(예: GTK+ 또는 Cocoa)이 빠져있기 때문에 발생한다.
cv2.imshow, cv2.waitKey, cv2.destroyAllWindows와 같은 GUI 함수는 이러한 라이브러리가 필요하다.
3. ubuntu 22.04 기준 해결방법
3-1. OpenCV에서 GUI 기능을 사용하려면 GTK+ 및 기타 종속 라이브러리를 설치해야 한다.
sudo apt update
sudo apt install libgtk2.0-dev pkg-config libgl1-mesa-glx libgl1-mesa-dri
3-2. GTK+가 올바르게 설치되었는지 확인
pkg-config --modversion gtk+-2.0
3-3. 현재 설치된 OpenCV를 제거하고 다시 설치
pip uninstall opencv-python
pip install opencv-python-headless
3-4. test script
import cv2
img = cv2.imread('path/to/sample_image.jpg')
cv2.imshow('테스트 윈도우', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
'python' 카테고리의 다른 글
python에서 pass, continue, break 차이 (0) | 2024.06.27 |
---|