원래 주미에는 opencv 3.4.3(?) 버전이 설치되어있는데
이상하게 피처 매치 부분에서 계속 버그가 나더라
아무리 삽질해봐도 도저히 고칠수 없어서 다른 버전을 사용하려고 했다.
그래서 opencv를 업그레이드 하겠다고 한참 삽질을 하다가
whl 파일 설치해서 마무리하고
다시 ORB 특징을 이용한 MPU6050 피처 매치
좌측의 센서 사진은 그냥 폰으로 찍어서 사용했다.
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
#queryImg
#qImg = cv2.imread('./res/mpu6050_2.png',0)
qImg = cv2.imread('../../../res/mpu6050_2.png',0)
# Initiate STAR detector
orb = cv2.ORB_create()
# find the keypoints with ORB
kp1 = orb.detect(qImg,None)
# compute the descriptors with ORB
kp1, desc1 = orb.compute(qImg, kp1)
# create BFMatcher object
bf = cv2.BFMatcher()
print(len(desc1))
while(True):
ret, frame = cap.read()
frame = cv2.flip(frame, 0)
rsz = cv2.resize(frame, dsize=(320,240))
gray = cv2.cvtColor(rsz, cv2.COLOR_BGR2GRAY)
# find the keypoints with ORB
kp2 = orb.detect(gray,None)
# compute the descriptors with ORB
kp2, desc2 = orb.compute(gray, kp2)
# Match descriptors.
matches = bf.knnMatch(desc1,desc2, k=2)
# Apply ratio test
good = []
for m,n in matches:
if m.distance < 0.75*n.distance:
good.append([m])
gray = cv2.drawMatchesKnn(qImg,kp1,gray,kp2,good, None, flags=2)
cv2.imshow('res',gray)
if cv2.waitKey(20) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
'로봇 > 로봇' 카테고리의 다른 글
zumi - 29. 카메라 캘리브레이션과 왜곡 보정 (0) | 2020.08.28 |
---|---|
zumi - 28. 피처매칭과 호모그래피 (0) | 2020.08.28 |
zumi - 26. pi에서 빌드없이 opencv 설치하기 (0) | 2020.08.28 |
zumi - 25. mpu6050 가속도계로 속도, 위치 구하기 fail (0) | 2020.08.28 |
zumi - 24. ORB (0) | 2020.08.27 |