bensondaled / pseyepy

PSEye-py: a python interface to the PS3Eye camera
Apache License 2.0
78 stars 26 forks source link

How to save the image after c.read() #17

Open autocomputer opened 9 months ago

autocomputer commented 9 months ago

Hi, I run the frame, timestamp = c.read() successfully and I got the frame. Could anyone tell me how to display frame by opencv-python? Thanks.

104player commented 7 months ago

I haven't used opencv python much, but the frame is a numpy array. You can get it as a PIL Image with

from PIL import Image img1 = Image.fromarray( frame )

and then if you are using a Jupyter notebook you can just view the image : img1

If you want to save it, you can just do: img1.save( filename )

Matplotlib may also be used to show the image from the numpy array directly: import matplotlib.pyplot as plt plt.imshow(frame)

For interactive display I've been using pygame so I used:

To change it fron BGR to RGB:

frameRGB = frame[:,:,::-1].copy()

to transpose from y,x to x,y .. and make it a pygame surface that can be easily blit to the screen:

SB = pygame.surfarray.make_surface( frameRGB.transpose(1,0,2) )