import
cv2
import
matplotlib.pyplot as plt
img1
=
cv2.imread(
"image1.jpg"
)
img2
=
cv2.imread(
"image2.jpg"
)
def
BFMatching(img1, img2):
feat
=
cv2.ORB_create(
5
)
kpnt1, des1
=
feat.detectAndCompute(img1,
None
)
kpnt2, des2
=
feat.detectAndCompute(img2,
None
)
bf
=
cv2.BFMatcher()
matches
=
bf.knnMatch(des1, des2, k
=
2
)
good
=
[]
matched_image
=
cv2.drawMatchesKnn(img1,
kpnt1, img2, kpnt2, matches,
None
,
matchColor
=
(
0
,
255
,
0
), matchesMask
=
None
,
singlePointColor
=
(
255
,
0
,
0
), flags
=
0
)
for
m, n
in
matches:
if
m.distance <
0.98
*
n.distance:
good.append([m])
cv2.imshow(
"matches"
, matched_image)
cv2.waitKey(
0
)
print
(
"key points of first image- "
)
print
(kpnt1)
print
(
"\nkey points of second image-"
)
print
(kpnt2)
print
(
"\noverall features that matched by BFMatcher()-"
)
print
(matches)
return
(
"good features"
, good)
BFMatching(img1, img2)