ImageSimilarFinder.py 文件源码

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

项目:ImageSimilarFinder 作者: zhangjizxc 项目源码 文件源码
def arrangePics(targetDir, picDir):
    targetDirPathLen=len(targetDir)
    count=0
    for path, d, filelist in os.walk(targetDir):
        if (not path.endswith('.git')) and isPathInList(targetLimitedSubDirs, path):
            for filename in filelist:
                if (filename.endswith('jpg') or filename.endswith('png') or filename.endswith('jpeg') or filename.endswith('gif')):
                    fileNameWithPath = os.path.join(path, filename)
                    image = load_image(fileNameWithPath)
                    if (image is not None):
                        ratio = format(float(image.height) / float(image.width), '.2f')
                        tempPath = os.path.join(picDir, str(ratio))
                        if (not os.path.exists(tempPath)):
                            os.mkdir(tempPath)
                        filenameNew=fileNameWithPath[targetDirPathLen+1:].replace('/', "_", 50)
                        tempFileNameWithPath = os.path.join(tempPath, filenameNew)
                        print(fileNameWithPath+"  copy to "+tempFileNameWithPath)
                        count = count + 1
                        shutil.copy(fileNameWithPath, tempFileNameWithPath)
    print("Total Image count is "+str(count))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号