编程杂记
Lee Chan
这个作者很懒,什么都没留下…
展开
-
检查损坏的图像(数据不完整)
以下代码能够检查出哪些图像导致 “image file is truncated” 和 “premature end of data segment” 错误。images_dir = '/data/train_images'# 返回 images_dir 目录下所有数据不完整图像的列表,支持多级目录broken_images_dirs = []for root, dirs, fi...原创 2019-11-12 23:13:46 · 1017 阅读 · 1 评论 -
labelme xml 标注文件输出掩码图片
离线标注版 labelme 和网页标注版 LabelMeAnnotationTool 的标注格式是不同的。以下代码实现通过网页标注版 labelme 输出的 xml 格式标注文件,输出掩码照片。代码地址:labelme_xml2mask.py# -*- coding: utf-8 -*-def xml2mask(image_path, xml, id2class_dict): ...原创 2019-11-02 16:30:27 · 1936 阅读 · 0 评论 -
PIL 和 OpenCV 读取图片为 numpy array 比较
为了适应图像模式为“RGBA”即四通道的情况,使用 PIL 读取图片数据时统一转为“RGB”格式。import cv2import PIL.Image as Imageimg_path = '/test.jpg'img = Image.open(img_path)(im_width, im_height) = img.sizenp_img_pil = np.array(img...原创 2019-10-30 00:21:43 · 618 阅读 · 0 评论