FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
3dv_tutorial/examples/image_stitching.py at master · mint-lab/3dv_tutorial · GitHub
mint-lab
3dv_tutorial
Repository navigation
Code
Issues
4
(4)
Pull requests
2
(2)
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
3dv_tutorial
/
examples
/
image_stitching.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
35 lines (29 loc) · 1.34 KB
Breadcrumbs
3dv_tutorial
/
examples
/
image_stitching.py
Copy path
File metadata and controls
35 lines (29 loc) · 1.34 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import
numpy
as
np
import
cv2
as
cv
# Load two images
img1
=
cv
.
imread
(
'../data/hill01.jpg'
)
img2
=
cv
.
imread
(
'../data/hill02.jpg'
)
assert
(
img1
is
not
None
)
and
(
img2
is
not
None
),
'Cannot read the given images'
# Retrieve matching points
fdetector
=
cv
.
BRISK_create
()
keypoints1
,
descriptors1
=
fdetector
.
detectAndCompute
(
img1
,
None
)
keypoints2
,
descriptors2
=
fdetector
.
detectAndCompute
(
img2
,
None
)
fmatcher
=
cv
.
DescriptorMatcher_create
(
'BruteForce-Hamming'
)
match
=
fmatcher
.
match
(
descriptors1
,
descriptors2
)
# Calculate planar homography and merge two images
pts1
,
pts2
=
[], []
for
i
in
range
(
len
(
match
)):
pts1
.
append
(
keypoints1
[
match
[
i
].
queryIdx
].
pt
)
pts2
.
append
(
keypoints2
[
match
[
i
].
trainIdx
].
pt
)
pts1
=
np
.
array
(
pts1
,
dtype
=
np
.
float32
)
pts2
=
np
.
array
(
pts2
,
dtype
=
np
.
float32
)
H
,
inlier_mask
=
cv
.
findHomography
(
pts2
,
pts1
,
cv
.
RANSAC
)
img_merged
=
cv
.
warpPerspective
(
img2
,
H
, (
img1
.
shape
[
1
]
*
2
,
img1
.
shape
[
0
]))
img_merged
[:,:
img1
.
shape
[
1
]]
=
img1
# Copy
# Show the merged image
img_matched
=
cv
.
drawMatches
(
img1
,
keypoints1
,
img2
,
keypoints2
,
match
,
None
,
None
,
None
,
matchesMask
=
inlier_mask
.
ravel
().
tolist
())
# Remove `matchesMask` if you want to show all putative matches
merge
=
np
.
vstack
((
np
.
hstack
((
img1
,
img2
)),
img_matched
,
img_merged
))
cv
.
imshow
(
'Planar Image Stitching'
,
merge
)
cv
.
waitKey
(
0
)
cv
.
destroyAllWindows
()
Back
|
FazBrowse Home
|
New Git URL