Demo entry 5865320

hihi

   

Submitted by anonymous on Aug 16, 2016 at 01:06
Language: Python. Code size: 2.6 kB.

#timenow = time.time()
for QueryImage_n, QueryImage in enumerate(QueryImages):

    img1 = cv2.imread('//Users/yuting/Data/2016Feb4_Talbot_SigeVision/QueryImages/%d.jpg'%(QueryImage),0) # queryImage
    kp1, des1 = orb.detectAndCompute(img1,None)                                    # find the keypoints and descriptors

    file_n, filename, matching_distance_list = [], [],[]

    for RefImages90_n, RefImages90_filename in enumerate(RefImages90):
        
        img2 = cv2.imread('/Users/yuting/Data/2016Feb4_Talbot_SigeVision/RefImages_refined/%s'%(RefImages90_filename),0) # refImage
        kp2, des2 = orb.detectAndCompute(img2,None)

        # Match descriptors.
        matches = bf.match(des1,des2)

        # ignore matches found in horizon box
        # (160-->340)
        # (165-->295)

        mask = np.ones(np.size(matches))

        for n, tmp in enumerate(matches):
            x,y = kp1[tmp.queryIdx].pt
            if 160<x<340 and 165<y<295:
                mask[n] = 0

        good = []
        for index in np.where(mask==1)[0]:
            good.append(matches[index])
            
        # Sort them in the order of their distance.
        good = sorted(good, key = lambda x:x.distance)

        # Find homography
        src_pts = np.float32([ kp1[m.queryIdx].pt for m in good ]).reshape(-1,1,2)
        dst_pts = np.float32([ kp2[m.trainIdx].pt for m in good ]).reshape(-1,1,2)

        M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC,5.0)
        matchesMask = mask.ravel().tolist()

        if np.sum(matchesMask)<10:
            continue

        if np.linalg.det(M)<=0:
            continue

        maskedmatches = []
        for index in np.where(np.array(matchesMask)==1)[0]:
            maskedmatches.append(good[index])

        matching_distance = 0
        for n in range(10):
            matching_distance = matching_distance + maskedmatches[n].distance

        matching_distance_list.append(matching_distance)
        filename.append(RefImages90_filename)
        file_n.append(RefImages90_n)
        
    search_array = np.array(matching_distance_list)/np.mean(np.array(matching_distance_list))
    search_array_min = np.min(search_array)
    searchmin[QueryImage_n] = search_array_min
    
    tmp2 = np.where(search_array==search_array_min)[0][0]
    #lat[QueryImage_n] = filename[tmp2].split('_')[0]
    lon[QueryImage_n] = filename[tmp2].split('_')[1]
    
timelater=time.time()
timediff = timelater-timenow
print(timediff)
sio.savemat('./Aug15.mat',{'searchmin':searchmin,'lat':lat,'lon':lon})

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).