Merge pull request #5548 from berak:patch-2

This commit is contained in:
Vadim Pisarevsky 2015-10-21 11:41:25 +00:00
commit a91dcb015d
6 changed files with 19 additions and 17 deletions

View File

@ -48,6 +48,8 @@ BRIEF in OpenCV
Below code shows the computation of BRIEF descriptors with the help of CenSurE detector. (CenSurE
detector is called STAR detector in OpenCV)
note, that you need [opencv contrib](https://github.com/Itseez/opencv_contrib)) to use this.
@code{.py}
import numpy as np
import cv2
@ -55,11 +57,11 @@ from matplotlib import pyplot as plt
img = cv2.imread('simple.jpg',0)
# Initiate STAR detector
star = cv2.FeatureDetector_create("STAR")
# Initiate FAST detector
star = cv2.xfeatures2d.StarDetector_create()
# Initiate BRIEF extractor
brief = cv2.DescriptorExtractor_create("BRIEF")
brief = cv2.BriefDescriptorExtractor_create()
# find the keypoints with STAR
kp = star.detect(img,None)

View File

@ -101,7 +101,7 @@ from matplotlib import pyplot as plt
img = cv2.imread('simple.jpg',0)
# Initiate FAST object with default values
fast = cv2.FastFeatureDetector()
fast = cv2.FastFeatureDetector_create()
# find and draw the keypoints
kp = fast.detect(img,None)

View File

@ -44,7 +44,7 @@ img1 = cv2.imread('box.png',0) # queryImage
img2 = cv2.imread('box_in_scene.png',0) # trainImage
# Initiate SIFT detector
sift = cv2.SIFT()
sift = cv2.xfeatures2d.SIFT_create()
# find the keypoints and descriptors with SIFT
kp1, des1 = sift.detectAndCompute(img1,None)
@ -78,7 +78,7 @@ if len(good)>MIN_MATCH_COUNT:
M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC,5.0)
matchesMask = mask.ravel().tolist()
h,w = img1.shape
h,w,d = img1.shape
pts = np.float32([ [0,0],[0,h-1],[w-1,h-1],[w-1,0] ]).reshape(-1,1,2)
dst = cv2.perspectiveTransform(pts,M)

View File

@ -69,8 +69,8 @@ from matplotlib import pyplot as plt
img = cv2.imread('simple.jpg',0)
# Initiate STAR detector
orb = cv2.ORB()
# Initiate ORB detector
orb = cv2.ORB_create()
# find the keypoints with ORB
kp = orb.detect(img,None)

View File

@ -104,7 +104,7 @@ greater than 0.8, they are rejected. It eliminaters around 90% of false matches
So this is a summary of SIFT algorithm. For more details and understanding, reading the original
paper is highly recommended. Remember one thing, this algorithm is patented. So this algorithm is
included in Non-free module in OpenCV.
included in [the opencv contrib repo](https://github.com/Itseez/opencv_contrib)
SIFT in OpenCV
--------------
@ -119,7 +119,7 @@ import numpy as np
img = cv2.imread('home.jpg')
gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
sift = cv2.SIFT()
sift = cv2.xfeatures2d.SIFT_create()
kp = sift.detect(gray,None)
img=cv2.drawKeypoints(gray,kp)
@ -151,7 +151,7 @@ Now to calculate the descriptor, OpenCV provides two methods.
We will see the second method:
@code{.py}
sift = cv2.SIFT()
sift = cv2.xfeatures2d.SIFT_create()
kp, des = sift.detectAndCompute(gray,None)
@endcode
Here kp will be a list of keypoints and des is a numpy array of shape

View File

@ -80,7 +80,7 @@ examples are shown in Python terminal since it is just same as SIFT only.
# Create SURF object. You can specify params here or later.
# Here I set Hessian Threshold to 400
>>> surf = cv2.SURF(400)
>>> surf = cv2.xfeatures2d.SURF_create(400)
# Find keypoints and descriptors directly
>>> kp, des = surf.detectAndCompute(img,None)
@ -92,12 +92,12 @@ examples are shown in Python terminal since it is just same as SIFT only.
While matching, we may need all those features, but not now. So we increase the Hessian Threshold.
@code{.py}
# Check present Hessian threshold
>>> print surf.hessianThreshold
>>> print surf.getHessianThreshold()
400.0
# We set it to some 50000. Remember, it is just for representing in picture.
# In actual cases, it is better to have a value 300-500
>>> surf.hessianThreshold = 50000
>>> surf.setHessianThreshold(50000)
# Again compute keypoints and check its number.
>>> kp, des = surf.detectAndCompute(img,None)
@ -119,10 +119,10 @@ on wings of butterfly. You can test it with other images.
Now I want to apply U-SURF, so that it won't find the orientation.
@code{.py}
# Check upright flag, if it False, set it to True
>>> print surf.upright
>>> print surf.getUpright()
False
>>> surf.upright = True
>>> surf.setUpright(True)
# Recompute the feature points and draw it
>>> kp = surf.detect(img,None)
@ -143,7 +143,7 @@ Finally we check the descriptor size and change it to 128 if it is only 64-dim.
64
# That means flag, "extended" is False.
>>> surf.extended
>>> surf.getExtended()
False
# So we make it to True to get 128-dim descriptors.