detection_label.py 文件源码

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

项目:Seg 作者: gxd1994 项目源码 文件源码
def generate_detecton_label(label_root,stride,save_root):
    if not os.path.exists(save_root):
        os.makedirs(save_root)
    files = os.listdir(label_root)
    for file in files:
        label = cv2.imread(os.path.join(label_root,file),cv2.CV_LOAD_IMAGE_UNCHANGED)
        target_shape = label.shape[0]//stride,label.shape[1]//stride
        feature_label = np.zeros(target_shape,dtype = np.uint8)
        if label is None:
            print 'plese check label root path'
        h,w = label.shape
        for y in range(0,h-stride,stride):
            for x in range(0,w-stride,stride):
                patch = label[y:(y+stride),x:(x+stride)]
                num_pixels = np.sum((patch != 0))
                if num_pixels >= 1:
                    feature_label[y//stride][x//stride] = 1

        cv2.imwrite(os.path.join(save_root,file),feature_label)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号