python - 从单个图像中获取多个图像裁剪
问题描述
我正在开发一个 OCR,它扫描检测器模块检测到的文本,假设一个图像具有n
边界框,我想要一个读取.xml
坐标的函数来裁剪边界框周围的图像。这是我尝试过的:
def get_cropped_image(image_file,
images_path = "data/split/train/images",
annotations_path = "data/split/train/annotations"):
images_filenames = os.listdir(images_path)
annotations_filenames = os.listdir(annotations_path)
image = cv2.imread(os.path.join(images_path, image_file))
annotation_filename = image_file.split(sep='.')[0]+'.xml'
bboxes, labels = read_annotation_file(annotations_path, annotation_filename)
for idx, label in enumerate(labels):
try:
cropped_img = imcrop(image, bboxes[idx]).copy()
return cropped_img
except:
raise
但是,此函数仅返回每个图像的第一个边界框裁剪。我怎样才能真正n
从每张图像中返回作物?
解决方案
您可以返回裁剪图像的列表:
imgList = []
for idx, label in enumerate(labels):
imgList.append(imcrop(image, bboxes[idx]).copy())
return imgList
推荐阅读
- delphi - 如何将我所有的软件证书分别导出到 .pfx 文件?
- java - 在屏幕旋转时保存 exoplayer 流位置和文本,并且视频不应暂停
- amazon-web-services - 有没有办法从 AWS - Device Farm 获取设备区域设置?我目前正在使用 Appium-Python-Android
- python - Azure 认知服务的语音服务 (SST) 支持哪些音频格式?
- mysql - 我的 SQL 语句被执行了两次(我是初学者)
- python - 如何编辑 sympy 乳胶打印的顺序?
- java - Eureka Discovery Client 添加自签名证书
- node.js - 在URL中传递参数后如何使用nodejs从mongodb获取和显示数据?
- automated-tests - 使用 Klov 查看完整的范围报告
- c - 多个scanfs?