OpenCV works with numpy arrays in Python, so you can just call pred.numpy() to get the underlying array.
Your transpose/permute call also seems to be valid, as OpenCV works with channel-last images.
The issue seems to be more related to OpenCV than PyTorch, but what kind of error do you get in cv2.findContours, if you pass the numpy array as the input?