image_reader.py 文件源码

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

项目:image_recognition 作者: tue-robotics 项目源码 文件源码
def read_annotated(dir_path, patterns=["*.jpg", "*.png", "*.jpeg"]):
    """
    Read annotated images from a directory. This reader assumes that the images in this directory are separated in
    different directories with the label name as directory name. The method returns a generator of the label (string)
    , the opencv image and the filename.
    :param dir_path: The base directory we are going to read
    :param patterns: Patterns of the images the reader should match
    """
    for label in os.listdir(dir_path):
        for root, dirs, files in os.walk(os.path.join(dir_path, label)):
            for basename in files:
                for pattern in patterns:
                    if fnmatch.fnmatch(basename, pattern):
                        filename = os.path.join(root, basename)
                        image = cv2.imread(filename)
                        if image is None:
                            print ">> Ignore empty image {f}".format(f=filename)
                        else:
                            yield label, image, filename
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号