pyvirtualcam icon indicating copy to clipboard operation
pyvirtualcam copied to clipboard

Numpy 2.0 is out, pyvirtualcam doesn't work with it

Open wrzwicky opened this issue 1 year ago • 1 comments

  • Operating system: Windows 11
  • Python version: 3.12.2
  • pyvirtualcam version: 0.11.1 (from pip install)
  • Virtual camera (OBS, v4l2loopback, UnityCapture): OBS
  • Virtual camera version: 30.1.2

Describe the bug Pyvirtualcam does not work with the new Numpy 2.0. You may want to update your dependencies to make that explicit, or update the code to support 2.0.

To Reproduce I installed the code for my Oak D Lite camera: pipenv shell pipenv install depthai pyvirtualcam This ended up installing Numpy 2.0.0.

I then ran their sample code to build a UVC camera. The result crashed from inside your camera.py, line 348 frame = np.array(frame.reshape(-1), copy=False, order='C') with the error:

ValueError: Unable to avoid copy while creating an array as requested.
If using `np.array(obj, copy=False)` replace it with `np.asarray(obj)` to allow a copy when needed (no behavior change in NumPy 1.x).

When I made the change suggested, I got a video feed that showed a flat grey color that flickered in brightness.

I then downgraded Numpy to 1.26 (pipenv install numpy==1.26) and the camera feed started working fine. When I reverted my change to your file, the camera feed continued to work fine.

wrzwicky avatar Jun 19 '24 04:06 wrzwicky

Can you download and test the preview wheels from the artifacts at https://github.com/letmaik/pyvirtualcam/actions/runs/9624551391#artifacts? This was built against numpy 2.

letmaik avatar Jun 22 '24 09:06 letmaik

@wrzwicky Ping

letmaik avatar Jul 06 '24 10:07 letmaik

Sorry for being a slacker, turns out depthai released 2.27 around the time you were doing your fix. Their 2.27 actually fixes the true problem, as using their 2.26 with your 0.12.0 exhibits the same gray flickering screen I saw above.

More importantly, their 2.27 works fine with your 0.11.1.

You'll need to decide whether to push your change; asarray() allowing copy will crash less, but may also sometimes consume more CPU with no explanation. And it may even be wrong, since a crash really means the incoming frame data is not in the expected format. If that's true, you may want to catch and rethrow a new exception with a more applicable message. (I did this sort of thing all the time in Java.)

And also, since I'm here, I can't make sense of np.array(frame.reshape()) on line 348. Looking at the docs, it appears copy=False basically means np.array() does nothing, and since reshape(-1) returns a 1-D array, then order='C' also does nothing.

Ok I'll stop now. Thanks for your time and attention.

wrzwicky avatar Jul 13 '24 22:07 wrzwicky

Closing as solved. Bug was fixed in depthai; both pyvirtualcam 0.11.1 and the proposed 0.12.0 work fine.

wrzwicky avatar Jul 13 '24 22:07 wrzwicky