본문 바로가기
프로그래밍/Python

AttributeError: module 'cv2.cv2' has no attribute 'xfeatures2d' 에러 해결

by Leeys 2022. 3. 23.
반응형

개발환경

 

- ubuntu18.04

- python3.7

 

1. Problem

 

sift = cv2.xfeatures2d.SIFT_create()

 

openCV의 해당 코드를 사용하려 할 때 에러가 발생

AttributeError: module 'cv2.cv2' has no attribute 'xfeatures2d' 

 

 

2. Reason

 

SIFT 같은 경우 OpenCV의 기본 repo 모듈의 일부가 아니기 때문에 발생하는 에러

 

3. Solution

 

해당 코드로 opencv-contrib을 설치

!pip install opencv-contrib-python

 

위의 방법으로 안되는경우 라이브러리 재설치

!pip uninstall opencv-contrib-python
!pip uninstall opencv-python

!pip install opencv-contrib-python
!pip install opencv-python

 

위 과정을 진행하고 jupyter notebook 또는 python을 종료 후 다시 실행해야함

 

만약 모두 실패할 시 git에서 라이브러리를 직접 설치해야한다.

https://github.com/opencv/opencv_contrib.git 

 

* cv2 version '4.5.2' 및 '4.5.1'은 opencv-contrib을 설치하지 않아도 작동한다고 함

반응형

댓글