現在、画像認識の勉強をしている最中です
opencvを用いて特徴点抽出をしようと以下のコードで実行し
import numpy as np
import cv2
img1 = cv2.imread('dollar.png',0)
img2 = cv2.imread('dollar_in_scene.png',0)
#特徴抽出機の生成
detector = cv2.xfeatures2d.SIFT_create()
#kpは特徴的な点の位置 destは特徴を現すベクトル
kp1, des1 = detector.detectAndCompute(img1, None)
kp2, des2 = detector.detectAndCompute(img2, None)
#特徴点の比較機
bf = cv2.BFMatcher()
matches = bf.knnMatch(des1,des2, k=2)
#割合試験を適用
good = []
match_param = 0.6
for m,n in matches:
if m.distance < match_param*n.distance:
good.append([m])
#cv2.drawMatchesKnnは適合している点を結ぶ画像を生成する
img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,good, None,flags=2)
cv2.imwrite("shift_result.png", img3)
実行したところエラーがでました
Traceback (most recent call last):
File "/home/pi/models/tutorials/image/imagenet/特徴点 抽出.py", line 8, in <module>
detector = cv2.xfeatures2d.SIFT_create()
AttributeError: 'module' object has no attribute 'xfeatures2d'
サイトには、OpenCVはライセンスフリーではないアルゴリズムはcontribパッケージに隔離されています。なので、SIFTやSURFを使うためにはcontribパッケージを導入する必要があります。と書いてあったのでcontrib付きのopencvを入れるためopencvをアンインストールしpip install opencv-contrib-pythonでインストールを行ったところ
Downloading/unpacking opencv-contrib-python
Could not find any downloads that satisfy the requirement opencv-contrib-python
Cleaning up...
No distributions at all found for opencv-contrib-python
Storing debug log for failure in /home/pi/.pip/pip.log
というエラーがおき、pip install opencv-pythonも同じようなエラーがでて困っています
よろしければアドバイスのほうよろしくお願いします
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/23 09:41
2017/11/23 12:07
2017/11/24 06:41
2017/11/24 06:41
2017/11/24 06:45
2017/11/24 09:07
2017/11/24 13:28
2017/11/24 16:33
2017/11/25 00:54
2017/11/25 14:48