Learning Safety for Obstacle Avoidance via Control Barrier Functions