def match(filename1, filename2, method): if (method == 'sift'): img1, kp1, des1 = sift(filename1) img2, kp2, des2 = sift(filename2) bf = cv2.BFMatcher( cv2.NORM_L2, crossCheck=True) # sift的normType应该使用NORM_L2或者NORM_L1 matches = bf.match(des1, des2) matches = sorted(matches, key=lambda x: x.distance) knnMatches = bf.knnMatch(des1, des2, k=1) # drawMatchesKnn if (method == 'surf'): img1, kp1, des1 = surf(filename1) img2, kp2, des2 = surf(filename2) bf = cv2.BFMatcher( cv2.NORM_L2, crossCheck=True) # surf的normType应该使用NORM_L2或者NORM_L1 matches = bf.match(des1, des2) matches = sorted(matches, key=lambda x: x.distance) knnMatches = bf.knnMatch(des1, des2, k=1) # drawMatchesKnn if (method == 'orb'): img1, kp1, des1 = orb(filename1) img2, kp2, des2 = orb(filename2) bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True) # orb的normType应该使用NORM_HAMMING matches = bf.match(des1, des2) matches = sorted(matches, key=lambda x: x.distance) knnMatches = bf.knnMatch(des1, des2, k=1) # drawMatchesKnn # 过滤 for m in matches: for n in matches: if (m.distance >= n.distance * 0.75): matches.remove(m) break print('%s size of kp: %d, after filtering: %d' % (method, len(des1), len(matches))) img = cv2.drawMatches(img1, kp1, img2, kp2, matches[:50], img2, flags=2) cv2.imshow(method, img) cv2.waitKey() cv2.destroyAllWindows()
def compare(filename): imgs = [] keyPoint = [] descriptor = [] img, keyPoint_temp, descriptor_temp = sift(filename) keyPoint.append(keyPoint_temp) descriptor.append(descriptor_temp) imgs.append(img) img, keyPoint_temp, descriptor_temp = surf(filename) keyPoint.append(keyPoint_temp) descriptor.append(descriptor_temp) imgs.append(img) img, keyPoint_temp, descriptor_temp = orb(filename) keyPoint.append(keyPoint_temp) descriptor.append(descriptor_temp) imgs.append(img) return imgs, keyPoint, descriptor
def findFeatures(self, image): features = [] features2 = [] features3 = [] for (x,y,w,h) in self.faces: # extract the face copy = cv.CloneImage(image) subImg = cv.GetSubRect(copy, (x,y,w,h)) offset = (x,y) features = surf(subImg, offset) features2 = harris(subImg, offset) features3 = canny(subImg, offset) self.faceFeatures = features self.faceFeatures2 = features2 self.faceFeatures3 = features3
if detector == 1: print("Detector:Good Features to Track") gftt(detector, emparejador, opcion, nombre1, nombre2) if detector == 2: print("Detector:FAST") fast(detector, emparejador, nombre1, nombre2) if detector == 3: print("Detector:BRIEF") brief(detector, emparejador, nombre1, nombre2) if detector == 4: print("Detector:ORB") orb(detector, emparejador, nombre1, nombre2) if detector == 5: print("Detector:AGAST") agast(detector, emparejador, nombre1, nombre2) if detector == 6: print("Detector:AKAZE") akaze(detector, emparejador, nombre1, nombre2) if detector == 7: print("Detector:BRISK") brisk(detector, emparejador, nombre1, nombre2) if detector == 8: print("Detector:KAZE") kaze(detector, 13, nombre1, nombre2) if detector == 9: print("Detector:SIFT") sift(detector, 13, nombre1, nombre2) if detector == 10: print("Detector:SRF") surf(detector, 13, nombre1, nombre2)
if detector == 1: print("Detector:Good Features to Track") gftt(detector, emparejador) if detector == 2: print("Detector:FAST") fast(detector, emparejador) if detector == 3: print("Detector:BRIEF") brief(detector, emparejador) if detector == 4: print("Detector:ORB") orb(detector, emparejador) if detector == 5: print("Detector:AGAST") agast(detector, emparejador) if detector == 6: print("Detector:AKAZE") akaze(detector, emparejador) if detector == 7: print("Detector:BRISK") brisk(detector, emparejador) if detector == 8: print("Detector:KAZE") kaze(detector, 13) if detector == 9: print("Detector:SIFT") sift(detector, 13) if detector == 10: print("Detector:SRF") surf(detector, 13)
if emparejador in relacion_det_empa[:, (detector - 1)]: brief(detector, emparejador) if detector == 4: print("Detector:ORB") if emparejador in relacion_det_empa[:, (detector - 1)]: orb(detector, emparejador) if detector == 5: print("Detector:AGAST") if emparejador in relacion_det_empa[:, (detector - 1)]: agast(detector, emparejador) if detector == 6: print("Detector:AKAZE") if emparejador in relacion_det_empa[:, (detector - 1)]: akaze(detector, emparejador) if detector == 7: print("Detector:BRISK") if emparejador in relacion_det_empa[:, (detector - 1)]: brisk(detector, emparejador) if detector == 8: print("Detector:KAZE") if emparejador in relacion_det_empa[:, (detector - 1)]: kaze(detector, emparejador) if detector == 9: print("Detector:SIFT") if emparejador in relacion_det_empa[:, (detector - 1)]: sift(detector, emparejador) if detector == 10: print("Detector:SURF") if emparejador in relacion_det_empa[:, (detector - 1)]: surf(detector, emparejador)
1) Norm_L1 2)Norm_L2 -- Seleccion:__ ")) kaze(detector, 12, opcion, nombre1, nombre2, norma) if detector == 9: print("Detector:SIFT") print("Emparejador:Brute_force") norma = int( input("Seleccione norma para medicion de distancia:\n\ 1) Norm_L1 2)Norm_L2 -- Seleccion:__ ")) sift(detector, 12, opcion, nombre1, nombre2, norma) if detector == 10: print("Detector:SRF") print("Emparejador:Brute_force") norma = int( input("Seleccione norma para medicion de distancia:\n\ 1) Norm_L1 2)Norm_L2 -- Seleccion:__ ")) surf(detector, 12, opcion, nombre1, nombre2, norma) if emparejador == 'b': norma = '' if detector == 1: print("Detector:Good Features to Track") print("Emparejador:FLANN") gftt(detector, 13, opcion, nombre1, nombre2, norma) if detector == 2: print("Detector:FAST") print("Emparejador:FLANN") fast(detector, 13, opcion, nombre1, nombre2, norma) if detector == 3: print("Detector:BRIEF") print("Emparejador:FLANN") brief(detector, 13, opcion, nombre1, nombre2, norma)