Tensor copy assertion error when cuda on

I had the same error and fixed it by installing a previous version of OpenCV: OpenCV 4.5.5.

See also this Git issue: OpenCV(4.6.0-dev) Error: Assertion failed (is_shape_same(dest, src)) · Issue #22586 · opencv/opencv · GitHub.