Write an algorithm to find the connected components in a 2D grid representing sensor inputs or physical obstacles.