Ai
1 Star 0 Fork 0

Felix/batch-annotator

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.py 1.68 KB
一键复制 编辑 原始数据 按行查看 历史
import os
import cv2
import argparse
from tqdm import tqdm
from annotators import add_annotators_to_arg_parser
def main():
parser = argparse.ArgumentParser(
description="Batch converts images to depth map using MiDaS"
)
parser.add_argument("input_dir", help="input directory")
parser.add_argument("output_dir", help="output directory")
parser.add_argument("annotator", type=str, default="midas", help="Annotator to use")
parser.add_argument("--res", type=int, default=512,
help="Resolution to process at. -1 for original size (be careful for large images!)")
parser.add_argument("--gpu", type=int, default=0, help="GPU id to use")
add_annotators_to_arg_parser(parser)
args = parser.parse_args()
if args.gpu is not None:
os.environ["CUDA_VISIBLE_DEVICES"] = str(args.gpu)
# make output directory
if not os.path.exists(args.output_dir):
os.makedirs(args.output_dir, exist_ok=True)
from annotators import annotate
img_ext = [".jpg", ".jpeg", ".png", ".webp"]
image_paths = [img_path for img_path in os.listdir(args.input_dir) if
os.path.splitext(img_path)[1].lower() in img_ext]
print(f"Found {len(image_paths)} images")
for img_path in tqdm(image_paths):
full_img_path = os.path.join(args.input_dir, img_path)
img = cv2.imread(full_img_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
output = annotate(img, args)
output = output.astype('uint8')
output = cv2.cvtColor(output, cv2.COLOR_RGB2BGR)
cv2.imwrite(os.path.join(args.output_dir, img_path), output)
print("FIN")
if __name__ == "__main__":
main()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/dwhnicholas/batch-annotator.git
git@gitee.com:dwhnicholas/batch-annotator.git
dwhnicholas
batch-annotator
batch-annotator
main

搜索帮助