Inatall python opencv
为了能够使用SIFT应当安装opencv-contrib-python库,命令如下:
$ pip install opencv-contrib-python
Collecting opencv-contrib-python
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x0000022AA5C27CF8>, 'Connection to pypi.python.org timed out. (connect timeout=15)')': /simple/opencv-contrib-python/
Retrying (Retry(total=3, connect=None, read=None, redirect=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x0000022AA5C27978>, 'Connection to pypi.python.org timed out. (connect timeout=15)')': /simple/opencv-contrib-python/
Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x0000022AA5C27D30>, 'Connection to pypi.python.org timed out. (connect timeout=15)')': /simple/opencv-contrib-python/
Downloading opencv_contrib_python-3.3.0.10-cp36-cp36m-win_amd64.whl (45.5MB)
Requirement already satisfied: numpy>=1.11.3 in c:\users\lucientlau\appdata\local\programs\python\python36\lib\site-packages (from opencv-contrib-python)
Installing collected packages: opencv-contrib-python
Successfully installed opencv-contrib-python-3.3.0.10
SIFT Demo
import cv2
import numpy as np
from scipy import misc
import matplotlib.pyplot as plt
#Test numpy array use it just like MATLAB
img = misc.imread('C:\\Users\\LucientLau\\Desktop\\timg1.jpg')
#img= misc.face()
sizeimg = img.shape
print(type(img))
#img[:,:,2]=0
print(img[:,:,1])
fig1=plt.figure('fig1')
plt.imshow(img[:,:,0],cmap=plt.cm.gray)
fig1.show()
fig2=plt.figure('fig2')
plt.imshow(img[:,:,1],cmap=plt.cm.gray)
fig2.show()
filterimg = img[:,:,2]
filterimg[filterimg<60] = 0
fig3=plt.figure('fig3')
plt.imshow((filterimg),cmap=plt.cm.gray)
fig3.show()
plt.show()
print(img.shape)
#Test SIFT
img=cv2.imread('C:\\Users\\LucientLau\\Desktop\\timg.jpg',cv2.IMREAD_COLOR)
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cv2.imshow('origin',img)
img=cv2.imread('C:\\Users\\LucientLau\\Desktop\\timg.jpg',cv2.IMREAD_COLOR)
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cv2.imshow('origin',img)
detector=cv2.xfeatures2d.SIFT_create()
keypoints = detector.detect(gray, None)
cv2.drawKeypoints(gray,keypoints,img)
cv2.imshow('test',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
网友评论