Reputation: 1428
I'm in the process of learning pypylon. The following code is my first success at capturing an image and displaying it via PIL. All good, but for one thing: it is capturing in grayscale and I would like to be capturing in color. And the information I need is lost in the vast sea of documentation and classes.
I can see that they offer zillion color formats, and I don't care: I just need something that is color and will convert nicely to a PIL image. Can someone suggest a small modification to this program that would accomplish that? (And by the way, what does the 2000 parameter do?)
# minimal capture image and show on screen in PIL format
import pypylon.pylon as py
from PIL import Image
tlf = py.TlFactory.GetInstance()
camera = py.InstantCamera(tlf.CreateDevice(devices[0]))
camera.Open()
camera.StartGrabbing(1)
grab = camera.RetrieveResult(2000, py.TimeoutHandling_Return)
if grab.GrabSucceeded():
img = grab.GetArray() # format: numpy array
print(f'Size of image: {img.shape}')
image = Image.fromarray(img)
image.show()
camera.Close()
Upvotes: 0
Views: 862
Reputation: 11
You should look at the following website: https://docs.baslerweb.com/pixel-format
You need to use the command: camera.PixelFormat.SetValue(PixelFormat_BGR8);
Upvotes: 0