Hướng dẫn image path python - con trăn đường dẫn hình ảnh

60 ví dụ mã Python được tìm thấy liên quan đến "Nhận đường dẫn hình ảnh". Bạn có thể bỏ phiếu cho những người bạn thích hoặc bỏ phiếu cho những người bạn không thích và đi đến dự án gốc hoặc tệp nguồn bằng cách theo các liên kết trên mỗi ví dụ. get image paths". You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. get image paths". You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

Nội dung chính

  • Làm cách nào để có được một đường dẫn hình ảnh đầy đủ?
  • Làm cách nào để có được đường dẫn tệp trong Python?
  • Đường dẫn của một hình ảnh là gì?
  • Con đường () làm gì trong Python?

ví dụ 1

def get_image_paths(dir):
    all_images = []
    for root, _, files in os.walk(dir):
        files = [os.path.join(root, f) for f in filter(lambda x: os.path.splitext(x)[-1].lower() in SUPPORTED_IMAGES, files)]
        all_images.extend(files)

    return all_images 

Ví dụ 2

def get_image_paths(image_dir, predictions):
    """
    A simple function that will find the paths of the detected images.
    :param image_dir: The location of the image directory.
    :param predictions: The vector of predictions
    :return: A list containing the paths to every images detected
    """

    images_names = get_all_images_path(image_dir)
    image_paths = []

    if len(images_names) > len(predictions):
        raise AssertionError('More prediction than files found. Probably your directory has subdirectories.')
    for idx, prediction in enumerate(predictions):
        if prediction:
            image_paths.append(images_names[idx])

    return image_paths 

Ví dụ 3

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 

Ví dụ 4

def get_image_paths(data_type, dataroot):
    '''get image path list
    support lmdb or image files'''
    paths, sizes = None, None
    if dataroot is not None:
        if data_type == 'lmdb':
            paths, sizes = _get_paths_from_lmdb(dataroot)
        elif data_type == 'img':
            paths = sorted(_get_paths_from_images(dataroot))
        else:
            raise NotImplementedError(
                'data_type [{:s}] is not recognized.'.format(data_type))
    return paths, sizes


###################### read images ###################### 

Ví dụ 5

def get_image_paths_and_labels_cam_dict(list_path, num_per_class):
  image_path_list_tmp = []
  image_path_list = []
  num_cameras_total = -1
  for line in open(os.path.expanduser(list_path), 'r'):
    part_line = line.split(' ')
    image_path = part_line[0]
    label_index = part_line[1]
    cam_index = part_line[2]
    while len(image_path_list_tmp) <= int(label_index):
      image_path_list_tmp.append([])
    image_path_list_tmp[int(label_index)].append((image_path, int(cam_index)))
    if int(cam_index) > num_cameras_total:
      num_cameras_total = int(cam_index)

  num_examples_total = 0
  for idx in range(len(image_path_list_tmp)):
    if len(image_path_list_tmp[idx]) >= num_per_class:
      image_path_list.append(image_path_list_tmp[idx])
      num_examples_total += len(image_path_list_tmp[idx])

  num_classes_total = len(image_path_list)
  num_cameras_total += 1

  return image_path_list, num_examples_total, num_classes_total, num_cameras_total 

Ví dụ 6

def get_image_paths_and_labels_and_cam(list_path):
  image_paths_flat = []
  labels_flat = []
  cam_flat = []
  for line in open(os.path.expanduser(list_path), 'r'):
    part_line = line.split()
    image_path = part_line[0]
    label_index = part_line[1]
    cam_index = part_line[2]
    image_paths_flat.append(image_path)
    labels_flat.append(int(label_index))
    cam_flat.append(int(cam_index))

  num_examples_total = len(labels_flat)
  num_classes_total = max(labels_flat)+1
  num_cameras_total = max(cam_flat)+1

  return image_paths_flat, labels_flat, cam_flat, num_examples_total, num_classes_total, num_cameras_total 

Ví dụ 7

def get_image_paths_and_labels_dict(list_path, num_per_class):
  image_path_list_tmp = []
  image_path_list = []
  for line in open(os.path.expanduser(list_path), 'r'):
    part_line = line.split(' ')
    image_path = part_line[0]
    label_index = part_line[1]
    if len(image_path_list_tmp) <= int(label_index):
      image_path_list_tmp.append([])
    image_path_list_tmp[int(label_index)].append(image_path)

  num_examples_total = 0
  for idx in range(len(image_path_list_tmp)):
    if len(image_path_list_tmp[idx]) >= num_per_class:
      image_path_list.append(image_path_list_tmp[idx])
      num_examples_total += len(image_path_list_tmp[idx])

  num_classes_total = len(image_path_list)

  return image_path_list, num_examples_total, num_classes_total 

Ví dụ 8

def get_all_image_paths(master_folder: Path) -> List[Path]:
    """
    Finds all image paths in subfolders.

    Args:
        master_folder: Root folder containing subfolders.

    Returns:
        A list of the paths to the images found in the folder.
    """
    all_paths = []
    subfolders = get_subfolder_paths(folder=master_folder)
    if len(subfolders) > 1:
        for subfolder in subfolders:
            all_paths += get_image_paths(folder=subfolder)
    else:
        all_paths = get_image_paths(folder=master_folder)
    return all_paths 

Ví dụ 9

def get_image_paths(data_type, dataroot):
    '''get image path list
    support lmdb or image files'''
    paths, sizes = None, None
    if dataroot is not None:
        if data_type == 'lmdb':
            paths, sizes = _get_paths_from_lmdb(dataroot)
            return paths, sizes
        elif data_type == 'img':
            paths = sorted(_get_paths_from_images(dataroot))
            return paths
        else:
            raise NotImplementedError('data_type [{:s}] is not recognized.'.format(data_type))


###################### read images ###################### 

Ví dụ 10

def get_annot_image_paths(ibs, aid_list):
    r"""
    Args:
        aid_list (list):

    Returns:
        list of strs: gpath_list the image paths of each annotation

    RESTful:
        Method: GET
        URL:    /api/annot/image/file/path/
    """
    gid_list = ibs.get_annot_gids(aid_list)
    try:
        ut.assert_all_not_None(gid_list, 'gid_list')
    except AssertionError:
        print('[!get_annot_image_paths] aids=' + ut.repr4(aid_list))
        print('[!get_annot_image_paths] gids=' + ut.repr4(gid_list))
        raise
    gpath_list = ibs.get_image_paths(gid_list)
    ut.assert_all_not_None(gpath_list, 'gpath_list')
    return gpath_list 

Ví dụ 11

def get_image_paths(image_dir, predictions):
    """
    A simple function that will find the paths of the detected images.
    :param image_dir: The location of the image directory.
    :param predictions: The vector of predictions
    :return: A list containing the paths to every images detected
    """

    images_names = get_all_images_path(image_dir)
    image_paths = []

    if len(images_names) > len(predictions):
        raise AssertionError('More prediction than files found. Probably your directory has subdirectories.')
    for idx, prediction in enumerate(predictions):
        if prediction:
            image_paths.append(images_names[idx])

    return image_paths 
0

Ví dụ 12

def get_image_paths(image_dir, predictions):
    """
    A simple function that will find the paths of the detected images.
    :param image_dir: The location of the image directory.
    :param predictions: The vector of predictions
    :return: A list containing the paths to every images detected
    """

    images_names = get_all_images_path(image_dir)
    image_paths = []

    if len(images_names) > len(predictions):
        raise AssertionError('More prediction than files found. Probably your directory has subdirectories.')
    for idx, prediction in enumerate(predictions):
        if prediction:
            image_paths.append(images_names[idx])

    return image_paths 
1

Ví dụ 13

def get_image_paths(image_dir, predictions):
    """
    A simple function that will find the paths of the detected images.
    :param image_dir: The location of the image directory.
    :param predictions: The vector of predictions
    :return: A list containing the paths to every images detected
    """

    images_names = get_all_images_path(image_dir)
    image_paths = []

    if len(images_names) > len(predictions):
        raise AssertionError('More prediction than files found. Probably your directory has subdirectories.')
    for idx, prediction in enumerate(predictions):
        if prediction:
            image_paths.append(images_names[idx])

    return image_paths 
2

Ví dụ 14

def get_image_paths(image_dir, predictions):
    """
    A simple function that will find the paths of the detected images.
    :param image_dir: The location of the image directory.
    :param predictions: The vector of predictions
    :return: A list containing the paths to every images detected
    """

    images_names = get_all_images_path(image_dir)
    image_paths = []

    if len(images_names) > len(predictions):
        raise AssertionError('More prediction than files found. Probably your directory has subdirectories.')
    for idx, prediction in enumerate(predictions):
        if prediction:
            image_paths.append(images_names[idx])

    return image_paths 
3

Ví dụ 15

def get_image_paths(image_dir, predictions):
    """
    A simple function that will find the paths of the detected images.
    :param image_dir: The location of the image directory.
    :param predictions: The vector of predictions
    :return: A list containing the paths to every images detected
    """

    images_names = get_all_images_path(image_dir)
    image_paths = []

    if len(images_names) > len(predictions):
        raise AssertionError('More prediction than files found. Probably your directory has subdirectories.')
    for idx, prediction in enumerate(predictions):
        if prediction:
            image_paths.append(images_names[idx])

    return image_paths 
4

Ví dụ 16

def get_image_paths(image_dir, predictions):
    """
    A simple function that will find the paths of the detected images.
    :param image_dir: The location of the image directory.
    :param predictions: The vector of predictions
    :return: A list containing the paths to every images detected
    """

    images_names = get_all_images_path(image_dir)
    image_paths = []

    if len(images_names) > len(predictions):
        raise AssertionError('More prediction than files found. Probably your directory has subdirectories.')
    for idx, prediction in enumerate(predictions):
        if prediction:
            image_paths.append(images_names[idx])

    return image_paths 
5

Ví dụ 17

def get_image_paths(image_dir, predictions):
    """
    A simple function that will find the paths of the detected images.
    :param image_dir: The location of the image directory.
    :param predictions: The vector of predictions
    :return: A list containing the paths to every images detected
    """

    images_names = get_all_images_path(image_dir)
    image_paths = []

    if len(images_names) > len(predictions):
        raise AssertionError('More prediction than files found. Probably your directory has subdirectories.')
    for idx, prediction in enumerate(predictions):
        if prediction:
            image_paths.append(images_names[idx])

    return image_paths 
6

Ví dụ 18

def get_image_paths(image_dir, predictions):
    """
    A simple function that will find the paths of the detected images.
    :param image_dir: The location of the image directory.
    :param predictions: The vector of predictions
    :return: A list containing the paths to every images detected
    """

    images_names = get_all_images_path(image_dir)
    image_paths = []

    if len(images_names) > len(predictions):
        raise AssertionError('More prediction than files found. Probably your directory has subdirectories.')
    for idx, prediction in enumerate(predictions):
        if prediction:
            image_paths.append(images_names[idx])

    return image_paths 
7

Ví dụ 19

def get_image_paths(image_dir, predictions):
    """
    A simple function that will find the paths of the detected images.
    :param image_dir: The location of the image directory.
    :param predictions: The vector of predictions
    :return: A list containing the paths to every images detected
    """

    images_names = get_all_images_path(image_dir)
    image_paths = []

    if len(images_names) > len(predictions):
        raise AssertionError('More prediction than files found. Probably your directory has subdirectories.')
    for idx, prediction in enumerate(predictions):
        if prediction:
            image_paths.append(images_names[idx])

    return image_paths 
8

Ví dụ 20

def get_image_paths(dir):
    all_images = []
    for root, _, files in os.walk(dir):
        files = [os.path.join(root, f) for f in filter(lambda x: os.path.splitext(x)[-1].lower() in SUPPORTED_IMAGES, files)]
        all_images.extend(files)

    return all_images 

Ví dụ 21

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
0

Ví dụ 22

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
1

Ví dụ 23

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
2

Ví dụ 24

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
2

Ví dụ 25

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
4

Ví dụ 26

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
5

Ví dụ 27

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
6

Ví dụ 28

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
7

Ví dụ 29

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
8

Ví dụ 30

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
9

Ví dụ 31

def get_image_paths(data_type, dataroot):
    '''get image path list
    support lmdb or image files'''
    paths, sizes = None, None
    if dataroot is not None:
        if data_type == 'lmdb':
            paths, sizes = _get_paths_from_lmdb(dataroot)
        elif data_type == 'img':
            paths = sorted(_get_paths_from_images(dataroot))
        else:
            raise NotImplementedError(
                'data_type [{:s}] is not recognized.'.format(data_type))
    return paths, sizes


###################### read images ###################### 
0

Ví dụ 32

def get_image_paths(data_type, dataroot):
    '''get image path list
    support lmdb or image files'''
    paths, sizes = None, None
    if dataroot is not None:
        if data_type == 'lmdb':
            paths, sizes = _get_paths_from_lmdb(dataroot)
        elif data_type == 'img':
            paths = sorted(_get_paths_from_images(dataroot))
        else:
            raise NotImplementedError(
                'data_type [{:s}] is not recognized.'.format(data_type))
    return paths, sizes


###################### read images ###################### 
1

Ví dụ 33

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
2

Ví dụ 34

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
2

Ví dụ 35

def get_image_paths(data_type, dataroot):
    '''get image path list
    support lmdb or image files'''
    paths, sizes = None, None
    if dataroot is not None:
        if data_type == 'lmdb':
            paths, sizes = _get_paths_from_lmdb(dataroot)
        elif data_type == 'img':
            paths = sorted(_get_paths_from_images(dataroot))
        else:
            raise NotImplementedError(
                'data_type [{:s}] is not recognized.'.format(data_type))
    return paths, sizes


###################### read images ###################### 
4

Ví dụ 36

def get_image_paths(data_type, dataroot):
    '''get image path list
    support lmdb or image files'''
    paths, sizes = None, None
    if dataroot is not None:
        if data_type == 'lmdb':
            paths, sizes = _get_paths_from_lmdb(dataroot)
        elif data_type == 'img':
            paths = sorted(_get_paths_from_images(dataroot))
        else:
            raise NotImplementedError(
                'data_type [{:s}] is not recognized.'.format(data_type))
    return paths, sizes


###################### read images ###################### 
5

Ví dụ 37

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
9

Ví dụ 38

def get_image_paths(data_type, dataroot):
    '''get image path list
    support lmdb or image files'''
    paths, sizes = None, None
    if dataroot is not None:
        if data_type == 'lmdb':
            paths, sizes = _get_paths_from_lmdb(dataroot)
        elif data_type == 'img':
            paths = sorted(_get_paths_from_images(dataroot))
        else:
            raise NotImplementedError(
                'data_type [{:s}] is not recognized.'.format(data_type))
    return paths, sizes


###################### read images ###################### 
7

Ví dụ 39

def get_image_paths(data_type, dataroot):
    '''get image path list
    support lmdb or image files'''
    paths, sizes = None, None
    if dataroot is not None:
        if data_type == 'lmdb':
            paths, sizes = _get_paths_from_lmdb(dataroot)
        elif data_type == 'img':
            paths = sorted(_get_paths_from_images(dataroot))
        else:
            raise NotImplementedError(
                'data_type [{:s}] is not recognized.'.format(data_type))
    return paths, sizes


###################### read images ###################### 
8

Ví dụ 40

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
9

Ví dụ 41

def get_image_paths(image_dir, predictions):
    """
    A simple function that will find the paths of the detected images.
    :param image_dir: The location of the image directory.
    :param predictions: The vector of predictions
    :return: A list containing the paths to every images detected
    """

    images_names = get_all_images_path(image_dir)
    image_paths = []

    if len(images_names) > len(predictions):
        raise AssertionError('More prediction than files found. Probably your directory has subdirectories.')
    for idx, prediction in enumerate(predictions):
        if prediction:
            image_paths.append(images_names[idx])

    return image_paths 
5

Ví dụ 42

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
9

Ví dụ 43

def get_image_paths_and_labels_cam_dict(list_path, num_per_class):
  image_path_list_tmp = []
  image_path_list = []
  num_cameras_total = -1
  for line in open(os.path.expanduser(list_path), 'r'):
    part_line = line.split(' ')
    image_path = part_line[0]
    label_index = part_line[1]
    cam_index = part_line[2]
    while len(image_path_list_tmp) <= int(label_index):
      image_path_list_tmp.append([])
    image_path_list_tmp[int(label_index)].append((image_path, int(cam_index)))
    if int(cam_index) > num_cameras_total:
      num_cameras_total = int(cam_index)

  num_examples_total = 0
  for idx in range(len(image_path_list_tmp)):
    if len(image_path_list_tmp[idx]) >= num_per_class:
      image_path_list.append(image_path_list_tmp[idx])
      num_examples_total += len(image_path_list_tmp[idx])

  num_classes_total = len(image_path_list)
  num_cameras_total += 1

  return image_path_list, num_examples_total, num_classes_total, num_cameras_total 
2

Ví dụ 44

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
2

Ví dụ 45

def get_image_paths_and_labels_cam_dict(list_path, num_per_class):
  image_path_list_tmp = []
  image_path_list = []
  num_cameras_total = -1
  for line in open(os.path.expanduser(list_path), 'r'):
    part_line = line.split(' ')
    image_path = part_line[0]
    label_index = part_line[1]
    cam_index = part_line[2]
    while len(image_path_list_tmp) <= int(label_index):
      image_path_list_tmp.append([])
    image_path_list_tmp[int(label_index)].append((image_path, int(cam_index)))
    if int(cam_index) > num_cameras_total:
      num_cameras_total = int(cam_index)

  num_examples_total = 0
  for idx in range(len(image_path_list_tmp)):
    if len(image_path_list_tmp[idx]) >= num_per_class:
      image_path_list.append(image_path_list_tmp[idx])
      num_examples_total += len(image_path_list_tmp[idx])

  num_classes_total = len(image_path_list)
  num_cameras_total += 1

  return image_path_list, num_examples_total, num_classes_total, num_cameras_total 
4

Ví dụ 46

def get_image_paths(data_type, dataroot):
    '''get image path list
    support lmdb or image files'''
    paths, sizes = None, None
    if dataroot is not None:
        if data_type == 'lmdb':
            paths, sizes = _get_paths_from_lmdb(dataroot)
        elif data_type == 'img':
            paths = sorted(_get_paths_from_images(dataroot))
        else:
            raise NotImplementedError(
                'data_type [{:s}] is not recognized.'.format(data_type))
    return paths, sizes


###################### read images ###################### 
4

Ví dụ 47

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
2

Ví dụ 48

def get_image_paths_and_labels_cam_dict(list_path, num_per_class):
  image_path_list_tmp = []
  image_path_list = []
  num_cameras_total = -1
  for line in open(os.path.expanduser(list_path), 'r'):
    part_line = line.split(' ')
    image_path = part_line[0]
    label_index = part_line[1]
    cam_index = part_line[2]
    while len(image_path_list_tmp) <= int(label_index):
      image_path_list_tmp.append([])
    image_path_list_tmp[int(label_index)].append((image_path, int(cam_index)))
    if int(cam_index) > num_cameras_total:
      num_cameras_total = int(cam_index)

  num_examples_total = 0
  for idx in range(len(image_path_list_tmp)):
    if len(image_path_list_tmp[idx]) >= num_per_class:
      image_path_list.append(image_path_list_tmp[idx])
      num_examples_total += len(image_path_list_tmp[idx])

  num_classes_total = len(image_path_list)
  num_cameras_total += 1

  return image_path_list, num_examples_total, num_classes_total, num_cameras_total 
7

Ví dụ 49

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
9

Ví dụ 50

def get_image_paths_and_labels_cam_dict(list_path, num_per_class):
  image_path_list_tmp = []
  image_path_list = []
  num_cameras_total = -1
  for line in open(os.path.expanduser(list_path), 'r'):
    part_line = line.split(' ')
    image_path = part_line[0]
    label_index = part_line[1]
    cam_index = part_line[2]
    while len(image_path_list_tmp) <= int(label_index):
      image_path_list_tmp.append([])
    image_path_list_tmp[int(label_index)].append((image_path, int(cam_index)))
    if int(cam_index) > num_cameras_total:
      num_cameras_total = int(cam_index)

  num_examples_total = 0
  for idx in range(len(image_path_list_tmp)):
    if len(image_path_list_tmp[idx]) >= num_per_class:
      image_path_list.append(image_path_list_tmp[idx])
      num_examples_total += len(image_path_list_tmp[idx])

  num_classes_total = len(image_path_list)
  num_cameras_total += 1

  return image_path_list, num_examples_total, num_classes_total, num_cameras_total 
9

Ví dụ 51

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
9

Ví dụ 52

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
9

Ví dụ 53

def get_image_paths(data_type, dataroot):
    '''get image path list
    support lmdb or image files'''
    paths, sizes = None, None
    if dataroot is not None:
        if data_type == 'lmdb':
            paths, sizes = _get_paths_from_lmdb(dataroot)
        elif data_type == 'img':
            paths = sorted(_get_paths_from_images(dataroot))
        else:
            raise NotImplementedError(
                'data_type [{:s}] is not recognized.'.format(data_type))
    return paths, sizes


###################### read images ###################### 
7

Ví dụ 54

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
2

Ví dụ 55

def get_image_paths_and_labels_and_cam(list_path):
  image_paths_flat = []
  labels_flat = []
  cam_flat = []
  for line in open(os.path.expanduser(list_path), 'r'):
    part_line = line.split()
    image_path = part_line[0]
    label_index = part_line[1]
    cam_index = part_line[2]
    image_paths_flat.append(image_path)
    labels_flat.append(int(label_index))
    cam_flat.append(int(cam_index))

  num_examples_total = len(labels_flat)
  num_classes_total = max(labels_flat)+1
  num_cameras_total = max(cam_flat)+1

  return image_paths_flat, labels_flat, cam_flat, num_examples_total, num_classes_total, num_cameras_total 
4

Ví dụ 56

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
2

Ví dụ 57

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
2

Ví dụ 58

def get_image_paths_and_labels_and_cam(list_path):
  image_paths_flat = []
  labels_flat = []
  cam_flat = []
  for line in open(os.path.expanduser(list_path), 'r'):
    part_line = line.split()
    image_path = part_line[0]
    label_index = part_line[1]
    cam_index = part_line[2]
    image_paths_flat.append(image_path)
    labels_flat.append(int(label_index))
    cam_flat.append(int(cam_index))

  num_examples_total = len(labels_flat)
  num_classes_total = max(labels_flat)+1
  num_cameras_total = max(cam_flat)+1

  return image_paths_flat, labels_flat, cam_flat, num_examples_total, num_classes_total, num_cameras_total 
7

Ví dụ 59

def get_image_paths_and_labels_and_cam(list_path):
  image_paths_flat = []
  labels_flat = []
  cam_flat = []
  for line in open(os.path.expanduser(list_path), 'r'):
    part_line = line.split()
    image_path = part_line[0]
    label_index = part_line[1]
    cam_index = part_line[2]
    image_paths_flat.append(image_path)
    labels_flat.append(int(label_index))
    cam_flat.append(int(cam_index))

  num_examples_total = len(labels_flat)
  num_classes_total = max(labels_flat)+1
  num_cameras_total = max(cam_flat)+1

  return image_paths_flat, labels_flat, cam_flat, num_examples_total, num_classes_total, num_cameras_total 
8

Ví dụ 60

def get_image_paths(directory):
    """ Return a list of images that reside in a folder """
    logger = logging.getLogger(__name__)  # pylint:disable=invalid-name
    image_extensions = _image_extensions
    dir_contents = list()

    if not os.path.exists(directory):
        logger.debug("Creating folder: '%s'", directory)
        directory = get_folder(directory)

    dir_scanned = sorted(os.scandir(directory), key=lambda x: x.name)
    logger.debug("Scanned Folder contains %s files", len(dir_scanned))
    logger.trace("Scanned Folder Contents: %s", dir_scanned)

    for chkfile in dir_scanned:
        if any([chkfile.name.lower().endswith(ext)
                for ext in image_extensions]):
            logger.trace("Adding '%s' to image list", chkfile.path)
            dir_contents.append(chkfile.path)

    logger.debug("Returning %s images", len(dir_contents))
    return dir_contents 
9

Làm cách nào để có được một đường dẫn hình ảnh đầy đủ?

Nhấp vào nút Bắt đầu và sau đó nhấp vào Máy tính, nhấp để mở vị trí của tệp mong muốn, giữ phím Shift và nhấp chuột phải vào tệp. Sao chép dưới dạng đường dẫn: Nhấp vào tùy chọn này để dán đường dẫn tệp đầy đủ vào tài liệu. Thuộc tính: Nhấp vào tùy chọn này để xem ngay đường dẫn tệp (vị trí) đầy đủ.

Làm cách nào để có được đường dẫn tệp trong Python?

Để truy xuất một tệp trong Python, bạn cần biết đường dẫn chính xác để tiếp cận tệp, trong Windows, bạn có thể xem đường dẫn của một tệp cụ thể bằng cách nhấp chuột phải vào tệp-> Thuộc tính-> General-> vị trí.Tương tự, để chạy tập lệnh, thư mục làm việc cần được đặt thành thư mục chứa tập lệnh.right-clicking the File-> Properties-> General-> Location. Similarly, to run a script, the working directory needs to be set to the directory containing the script.right-clicking the File-> Properties-> General-> Location. Similarly, to run a script, the working directory needs to be set to the directory containing the script.

Đường dẫn của một hình ảnh là gì?

Đường dẫn tệp mô tả vị trí của một tệp trong cấu trúc thư mục của trang web.Các đường dẫn tệp được sử dụng khi liên kết với các tệp bên ngoài, như: các trang web.Hình ảnh.. File paths are used when linking to external files, like: Web pages. Images.. File paths are used when linking to external files, like: Web pages. Images.

Con đường () làm gì trong Python?

Dirname (đường dẫn): Nó được sử dụng để trả về tên thư mục từ đường dẫn được đưa ra.Hàm này trả về tên từ đường dẫn ngoại trừ tên đường dẫn.return the directory name from the path given. This function returns the name from the path except the path name.return the directory name from the path given. This function returns the name from the path except the path name.