Is there a reason you are using old version of python CV and NP? I'm on the following versions and have no problems when I copy your snippet here:
OpenCV: 4.10.0
NumPy: 2.1.0
Python: 3.12.5
If you can update you probably should. Is there large functional difference is the major versions that would stop you from updating? If there are, maybe post the relevant code. There should be a way to adjust it to work with the new versions.