Example #1
0
def demo():
    src_image_feature_path = 'wine_images/src_image_feature_path.path'

    feature_path_dict = rw.read_dict(src_image_feature_path)

    key_list = feature_path_dict.keys()


    img_name, img_kp, img_des = rw.read_feature(feature_path_dict[key_list[0]].strip())
    print( img_name )
    img_name2, img_kp2, img_des2 = rw.read_feature(feature_path_dict[key_list[100]].strip())
    print( img_name2)
    r_good_match, good_match = match(img_kp, img_des.astype(np.float32),img_kp2, img_des2.astype(np.float32), 0.75, 'bf')
    print(len(good_match))

    # MIN_MATCH_COUNT = 10
    # ransanc_good_match = []
    # if len(good_match) > MIN_MATCH_COUNT:
    #     # 获取关键点的坐标
    #     src_pts = np.float32([ img_kp[m[0].queryIdx].pt for m in good_match ]).reshape(-1,1,2)
    #     dst_pts = np.float32([ img_kp2[m[0].trainIdx].pt for m in good_match ]).reshape(-1,1,2)

    #     H, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC,5.0)
    # for i in range(len(mask)):
    #     if mask[i]:
    #         ransanc_good_match.append(good_match[i])
    # print( 'ransanc_good_match:', len( ransanc_good_match))

    print( len( r_good_match ) )

    print( img_des.shape )
Example #2
0
def read_des_feature(feature_path_dict):
    #from feature path dict to get des dict
    des_dict = dict()
    kp_dict = dict()
    for key in feature_path_dict.keys():
        img_name, img_kp, img_des = rw.read_feature(feature_path_dict[key])
        kp_dict[img_name] = img_kp
        des_dict[img_name] = img_des
    return kp_dict, des_dict
Example #3
0
def demo1():
    #save and load feature, save_feature function and read_feature function
    kp_aa = cv2.KeyPoint()
    kps_d = [kp_aa, kp_aa]
    des_a = np.array([[1, 2, 3], [2, 3, 4], [5, 6, 7]])
    rwOperate.save_feature('image1.jpg', kps_d, des_a, './test/data.surf')
    img_name, img_kp, img_des = rwOperate.read_feature('./test/data.surf')

    print(img_name)
    print(img_kp, type(img_kp))
    print(img_des, type(img_des))
Example #4
0
def getDescriptors(src_image_feature_path):
    #read image feature for
    #path = '../datafolder/test'
    image_feature_path = os.path.join(src_image_feature_path,
                                      'src_image_feature_path.path')
    if os.path.exists(image_feature_path):
        path_dict = rwOperate.read_dict(image_feature_path)
    else:
        print('have no src_image_feature_path.path to read!',
              image_feature_path)
        return -1

    descriptors = list()

    for key in path_dict.keys():
        one_image_feature_path = path_dict[key]
        _, _, img_des = rwOperate.read_feature(one_image_feature_path)
        descriptors.extend(img_des.tolist())

    descriptors = np.asarray(descriptors)
    return descriptors
Example #5
0
def save_VLAD_to_proto(src_image_feature_path, visualDictionary):
    image_feature_path = os.path.join(src_image_feature_path,
                                      'src_image_feature_path.path')
    if os.path.exists(image_feature_path):
        path_dict = rwOperate.read_dict(image_feature_path)
    else:
        print('have no src_image_feature_path.path to read!')

    descriptors_dict = dict()

    for key in path_dict.keys():
        try:
            one_image_feature_path = path_dict[key]
            _, _, img_des = rwOperate.read_feature(one_image_feature_path)
            v = VLAD.VLAD(img_des, visualDictionary)
            descriptors_dict[key] = v
        except:
            print('extract vlad feature failure')
            continue
    rwOperate.save_dict_des(
        descriptors_dict,
        os.path.join(src_image_feature_path, 'descriptors_dict.vlad'))
Example #6
0
def read_des_feature_by_path(feature_path):
    '''
        通过key读取特征数据,该方式占用内存少,但是耗时长
    '''
    img_name, img_kp, img_des = rw.read_feature( feature_path )
    return img_name, img_kp, img_des
Example #7
0
    read_image_st = time.time()
    img = cv2.imread(image_path)
    img = cv2.resize(img, (360, 360))
    print('read image time:', time.time() - read_image_st)

    kp, des = feature_extract.detect(surf, img)

    f_train_path = []
    for nameIdx in dest_name_list:
        f_train_path.append(feature_path_dict[nameIdx])

    f_train_des = []

    temp_image_name = []
    for pathIdx in f_train_path:
        img_name, img_kp, img_des = rwOperate.read_feature(pathIdx)

        r_good_match, good_match = feature_match.match(
            kp, des.astype(np.float32), img_kp, img_des.astype(np.float32),
            0.75, 'bf')
        if svm_clf.predict([[float(len(r_good_match)),
                             float(len(good_match))]]):
            print(img_name)
            temp_image_name.append(img_name)
    search_time.append(time.time() - st_time)
    search_result.append(temp_image_name)

    print('all time:', time.time() - st_time)

with open('result.txt', 'w+') as f:
    f.write(str(search_time))