descriptors.py 文件源码

python
阅读 38 收藏 0 点赞 0 评论 0

项目:object-classification 作者: HenrYxZ 项目源码 文件源码
def descriptors_from_class(dataset, class_img_paths, class_number, option = constants.ORB_FEAT_OPTION):
    """
    Gets all the local descriptors for a class. If an image has a side with more than 640 pixels it will be resized
    leaving the biggest side at 640 pixels and conserving the aspect ratio for the other side.

    Args:
        dataset (Dataset object): An object that stores information about the dataset.
        class_img_paths (array of strings): The paths for each image in certain class.
        class_number (integer): The number of the class.
        option (integer): If this is 49 (The key '1') uses ORB features, else use SIFT.

    Returns:
        numpy float matrix: Each row are the descriptors found in an image of the class
    """
    des = None
    step = (constants.STEP_PERCENTAGE * len(class_img_paths)) / 100
    for i in range(len(class_img_paths)):
        img_path = class_img_paths[i]
        img = cv2.imread(img_path)
        resize_to = 640
        h, w, channels = img.shape
        if h > resize_to or w > resize_to:
            img = utils.resize(img, resize_to, h, w)
        if option == constants.ORB_FEAT_OPTION:
            des_name = "ORB"
            new_des = orb(img)
        else:
            des_name = "SIFT"
            new_des = sift(img)
        if new_des is not None:
            if des is None:
                des = np.array(new_des, dtype=np.float32)
            else:
                des = np.vstack((des, np.array(new_des)))
        # Print a message to show the status of the function
        if i % step == 0:
            percentage = (100 * i) / len(class_img_paths)
            message = "Calculated {0} descriptors for image {1} of {2}({3}%) of class number {4} ...".format(
                des_name, i, len(class_img_paths), percentage, class_number
            )
            print(message)
    message = "* Finished getting the descriptors for the class number {0}*".format(class_number)
    print(message)
    print("Number of descriptors in class: {0}".format(len(des)))
    dataset.set_class_count(class_number, len(des))
    return des
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号