티스토리 뷰
[map merging] 맵 합치기
feature 검출의 다양한 방법 사용해 ransac까지
특징점(feature) 검출하는 detector는 다양하다.
SIFT,SURF,KAZE,ORB등등이 있다.
그 중에 KAZE와 ORB로 맵의 특징점을 뽑고 매칭 해보겠다.
1. KAZE
detector = cv2.KAZE_create()
import cv2
import numpy as np
img1 = cv2.imread('lab.pgm')
img2 = cv2.imread('lab2.pgm')
cv2.imshow('lab',img1)
cv2.imshow("lab2",img2)
detector = cv2.KAZE_create()
kp1, des1 = detector.detectAndCompute(img1,None)
kp2, des2 = detector.detectAndCompute(img2,None)
bf = cv2.BFMatcher()
matches= bf.knnMatch(des1,des2,k=2)
good = []
for m,n in matches:
if m.distance < 0.6*n.distance:
good.append([m])
print('good',len(good))
img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,good,None,flags=2)
cv2.imshow("matching",img3)
cv2.imwrite('matching.jpg',img3)
cv2.waitKey(0)
지금은 RANSAC을 진행하지 않고 굿 매칭만 한 것이라 오매칭이 더러 있다.
good match - 76
2. ORB뿐
detector = cv2.ORB_create()
위 kaze코드에서 detector만 바꾸면 된다.
good match가 7개 뿐
결론
kaze가 좀 더 성능이 좋은 것으로 보임
ransac까지 진행해보자.
RANSAC
ORB
정확도
accuracy: 86/143(0.60%)
KAZE ransac이 안되서
AKAZE로 시도하니 성공 ..? 왜일까
일단 오류는 올려둔다.
match하는 부분에서 계속 오류가 나옴
AKAZE로 RANSAC
정확도
accuracy: 85/124(0.69%)
둘 중 kaze가 피처가 적지만 알맞은 매칭이 더 많이 발생
AKAZE ransac코드
import cv2
import numpy as np
img1 = cv2.imread('lab2.pgm')
img2 = cv2.imread('lab.pgm')
cv2.imshow('lab',img1)
cv2.imshow("lab2",img2)
detector = cv2.AKAZE_create()
kp1, des1 = detector.detectAndCompute(img1,None)
kp2, des2 = detector.detectAndCompute(img2,None)
matcher = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches = matcher.match(des1, des2)
matches = sorted(matches, key=lambda x:x.distance)
res1 = cv2.drawMatches(img1, kp1, img2, kp2, matches, None, \
flags=cv2.DRAW_MATCHES_FLAGS_NOT_DRAW_SINGLE_POINTS)
src_pts = np.float32([ kp1[m.queryIdx].pt for m in matches ])
dst_pts = np.float32([ kp2[m.trainIdx].pt for m in matches ])
mtrx, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0)
h,w = img1.shape[:2]
pts = np.float32([ [[0,0]],[[0,h-1]],[[w-1,h-1]],[[w-1,0]] ])
dst = cv2.perspectiveTransform(pts,mtrx)
img2 = cv2.polylines(img2,[np.int32(dst)],True,255,3, cv2.LINE_AA)
matchesMask = mask.ravel().tolist()
res2 = cv2.drawMatches(img1, kp1, img2, kp2, matches, None, \
matchesMask = matchesMask,
flags=cv2.DRAW_MATCHES_FLAGS_NOT_DRAW_SINGLE_POINTS)
accuracy=float(mask.sum()) / mask.size
print("accuracy: %d/%d(%.2f%%)"% (mask.sum(), mask.size, accuracy))
cv2.imshow('Matching-All', res1)
cv2.imwrite('matching-all_kaze.jpg',res1)
cv2.imshow('Matching-Inlier', res2)
cv2.imwrite('matching-inlier_kaze.jpg',res2)
cv2.waitKey()
cv2.destroyAllWindows()
'robot' 카테고리의 다른 글
[map merging] 파노라마 stitiching (0) | 2021.07.19 |
---|---|
[map merging] OpenCv - feature matching (0) | 2021.07.14 |
[gmapping map size] 맵 사이즈 변경 (0) | 2021.07.12 |
[kobuki] 내비게이션 파라미터 조정 (0) | 2021.07.05 |
[꼬부기/kobuki] navigation (0) | 2021.06.25 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- wpf 재생목록
- diagrams.net
- lwip
- 백준
- 텐서플로우 #tensorflow # tensor #텐서 #flow #플로우
- SWEA
- 6204
- 4831
- add button
- WPF
- 으에엑
- 2163번
- 버튼 클릭 시 메뉴
- 티스토리 코드블럭
- 표처럼 코드가 나와요
- 2588
- cartographer
- 네트워크 구성도
- 내 몸에서
- 어이구 두야
- 10869
- 파일 올리기
- 버튼에 메뉴만들기
- rosbag
- 재생목록
- 꺼저
- c#
- #전기버스
- gmapping
- 빈 txt
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함