A blundering burglar was caught after a quick-thinking victim took his photograph as he made his getaway, a court was told.