def draw_corr(queryimgpath, matchedimg, matches, matchoutpath=None): matchimgpath = os.path.join(context.dbdump, '%s.jpg' % matchedimg) if matchoutpath == None: matchoutpath = os.path.expanduser('~/client-out.jpg') H, inliers = corr.draw_matches(matches, queryimgpath, matchimgpath, matchoutpath) return H, inliers
def compute_hom(C, Q, ranked_matches, comb_matches): match1 = any(check_img(C, Q, ranked_matches[0])) if not C.compute_hom: if match1: return if not C.log_failures: return if C.put_into_dirs: udir = os.path.join(C.resultsdir, Q.name) else: udir = C.resultsdir if not os.path.exists(udir): os.makedirs(udir) i = 0 data = {} for matchedimg, score, pairs in ranked_matches[:C.max_matches_to_analyze]: i += 1 if C.stop_on_homTrue and data.get('success'): break # we are done (found good homography) clat, clon = getlatlonfromdbimagename(C, matchedimg) matchimgpath = None # XXX this sucks, since we don't have a db image abstraction for ext in ['.jpg', '.JPG', '.png', '.PNG']: p = os.path.join(C.dbdump, '%s%s' % (matchedimg, ext)) if os.path.exists(p): matchimgpath = p assert matchimgpath match = any(check_img(C, Q, ranked_matches[i-1])) # matches = db_matches # rematch for precise fit db_matches = comb_matches[matchedimg + 'sift.txt'] matchsiftpath = os.path.join(C.dbdump, matchedimg + 'sift.txt') matches = corr.rematch(C, Q, matchsiftpath) # matches1 = matches # rp_matches = corr.rematch(C, Q, matchsiftpath) # concat db matches matches.extend(db_matches) # find homography rsc_matches, H, inliers = corr.find_corr(matches, hom=True, ransac_pass=True, data=data) rsc_inliers = np.compress(inliers, rsc_matches).tolist() u = corr.count_unique_matches(rsc_inliers) if C.drawtopcorr or (not match and C.log_failures): # draw picture matchoutpath = os.path.join(udir, Q.name + ';match' + str(i) + ';gt' + str(match) + ';hom' + str(data.get('success')) + ';uniq=' + str(u) + ';inliers=' + str(float(sum(inliers))/len(matches)) + ';' + matchedimg + '.jpg') # try: corr.draw_matches(C, Q, matches, rsc_matches, H, inliers, matchimgpath, matchoutpath, matchsiftpath, C.show_feature_pairs) # except IOError, e: # INFO(e) if C.dump_hom: if C.put_into_dirs: identifier = str(i) else: identifier = Q.name + ':' + str(i) H = np.matrix(np.asarray(H)) with open(os.path.join(udir, 'homography%s.txt' % identifier), 'w') as f: print >> f, H np.save(os.path.join(udir, 'inliers%s.npy' % identifier), rsc_inliers) ### POSIT ### if C.do_posit: posit.do_posit(C, Q, rsc_inliers, matchsiftpath, matchimgpath)
def draw_corr(queryimgpath, matchedimg, matches, matchoutpath=None): matchimgpath = os.path.join(context.dbdump, "%s.jpg" % matchedimg) if matchoutpath == None: matchoutpath = os.path.expanduser("~/client-out.jpg") H, inliers = corr.draw_matches(matches, queryimgpath, matchimgpath, matchoutpath) return H, inliers