def matchAllImagesFlann(c,conn): c.execute('SELECT * FROM images') images =c.fetchall() #print images numimg = 0 for image1 in images: if numimg%50==0: print numimg imageId1 = image1[0] imageURL1 = image1[1] subNumImg = 0 print imageId1 for image2 in images: if subNumImg%50==0: print str(image1) +':' + str(subNumImg) imageId2 = image2[0] imageURL2 = image1[1] #print dirm.rootDirectory + imageURL try: kp1, des1 = surfHandlerP.reteriveSurfVals(imageId1,c) kp2, des2 = surfHandlerP.reteriveSurfVals(imageId2,c) matches,numMatches, meanDistance, matchesAT,numMatchesAT, meanDistanceAT = surf.flannMatcher(kp1, des1, kp2, des2) store(imageId1, imageId2, matches, numMatches, meanDistance, matchesAT,numMatchesAT, meanDistanceAT,c,conn) except Exception, e: print "unable to process image "+imageId1 + ", " + imageId2 print str(e) subNumImg = subNumImg + 1 numimg = numimg +1
def bow(c, con): # create BFMatcher object bf = cv2.BFMatcher(cv2.NORM_L2, crossCheck=True) c.execute('SELECT * FROM images') images = c.fetchall() images = images[:5] #print images numimg = 0 for image1 in images: if numimg % 50 == 0: print 'processed so far:' + str(numimg) imageId1 = image1[0] imageURL1 = image1[1] kp1, des1 = surfHandlerP.reteriveSurfVals(imageId1, c) bf.add(des1) numimg = numimg + 1 bf.train() print len(bf.getTrainDescriptors()) imageId2 = images[3][0] kp2, des2 = surfHandlerP.reteriveSurfVals(imageId2, c) print len(des2) matches = bf.match(des2) print len(matches) print matches[16] match = matches[1650] print match.distance, match.trainIdx, match.queryIdx, match.imgIdx matchesA = [0, 0, 0, 0, 0, 0, 0]
def bowKn(c,con): # FLANN parameters FLANN_INDEX_KDTREE = 0 index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5) search_params = dict(checks=50) # or pass empty dictionary flann = cv2.FlannBasedMatcher(index_params,search_params) c.execute('SELECT * FROM images') images =c.fetchall() images = images[:5] #print images numimg = 0 for image1 in images: if numimg%50==0: print 'processed so far:' + str(numimg) imageId1 = image1[0] imageURL1 = image1[1] kp1, des1 = surfHandlerP.reteriveSurfVals(imageId1,c) flann.add([des1]) numimg = numimg + 1 flann.train() print len(flann.getTrainDescriptors()) imageId2 = images[3][0] kp2, des2 = surfHandlerP.reteriveSurfVals(imageId2,c) print len(des2) matches = flann.knnMatch(des2,k=2) print len(matches) print matches[16] match = matches[1650] print match.distance, match.trainIdx, match.queryIdx, match.imgIdx matchesA = [0,0,0,0,0,0,0]
def bowKn(c, con): # FLANN parameters FLANN_INDEX_KDTREE = 0 index_params = dict(algorithm=FLANN_INDEX_KDTREE, trees=5) search_params = dict(checks=50) # or pass empty dictionary flann = cv2.FlannBasedMatcher(index_params, search_params) c.execute('SELECT * FROM images') images = c.fetchall() images = images[:5] #print images numimg = 0 for image1 in images: if numimg % 50 == 0: print 'processed so far:' + str(numimg) imageId1 = image1[0] imageURL1 = image1[1] kp1, des1 = surfHandlerP.reteriveSurfVals(imageId1, c) flann.add([des1]) numimg = numimg + 1 flann.train() print len(flann.getTrainDescriptors()) imageId2 = images[3][0] kp2, des2 = surfHandlerP.reteriveSurfVals(imageId2, c) print len(des2) matches = flann.knnMatch(des2, k=2) print len(matches) print matches[16] match = matches[1650] print match.distance, match.trainIdx, match.queryIdx, match.imgIdx matchesA = [0, 0, 0, 0, 0, 0, 0]
def bow(c,con): # create BFMatcher object bf = cv2.BFMatcher(cv2.NORM_L2, crossCheck=True) c.execute('SELECT * FROM images') images =c.fetchall() images = images[:5] #print images numimg = 0 for image1 in images: if numimg%50==0: print 'processed so far:' + str(numimg) imageId1 = image1[0] imageURL1 = image1[1] kp1, des1 = surfHandlerP.reteriveSurfVals(imageId1,c) bf.add(des1) numimg = numimg + 1 bf.train() print len(bf.getTrainDescriptors()) imageId2 = images[3][0] kp2, des2 = surfHandlerP.reteriveSurfVals(imageId2,c) print len(des2) matches = bf.match(des2) print len(matches) print matches[16] match = matches[1650] print match.distance, match.trainIdx, match.queryIdx, match.imgIdx matchesA = [0,0,0,0,0,0,0]
def matchAllImages(c, conn): c.execute('SELECT * FROM images') images = c.fetchall() #print images numimg = 0 for image1 in images: if numimg % 50 == 0: print numimg imageId1 = image1[0] imageURL1 = image1[1] subNumImg = 0 print imageId1 for image2 in images: if subNumImg % 50 == 0: print str(image1) + ':' + str(subNumImg) imageId2 = image2[0] imageURL2 = image1[1] #print dirm.rootDirectory + imageURL try: kp1, des1 = surfHandlerP.reteriveSurfVals(imageId1, c) kp2, des2 = surfHandlerP.reteriveSurfVals(imageId2, c) matches, numMatches, meanDistance, matchesAT, numMatchesAT, meanDistanceAT = surf.bfMatch( kp1, des1, kp2, des2) store(imageId1, imageId2, matches, numMatches, meanDistance, matchesAT, numMatchesAT, meanDistanceAT, c, conn) except Exception, e: print "unable to process image " + imageId1 + ", " + imageId2 print str(e) subNumImg = subNumImg + 1 numimg = numimg + 1