Basler官方的python支持放到了GitHub上,GitHub - basler/pypylon: The official python wrapper for the pylon Camera Software Suite
截止到2022.11.27日,支持到python 3.10版本,因此先安裝python,再安裝pypylon。
3、安裝本地whl文件
cmd中輸入安裝(我把whl放到了C盤根目錄)
【實踐】
使用VS新建python項目
具體代碼:
from pypylon import pylon camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice()) camera.Open() # demonstrate some feature access new_width = camera.Width.GetValue() - camera.Width.GetInc() if new_width >= camera.Width.GetMin(): camera.Width.SetValue(new_width) numberOfImagesToGrab = 100 camera.StartGrabbingMax(numberOfImagesToGrab) while camera.IsGrabbing(): grabResult = camera.RetrieveResult(5000, pylon.TimeoutHandling_ThrowException) if grabResult.GrabSucceeded(): # Access the image data. print("SizeX: ", grabResult.Width) print("SizeY: ", grabResult.Height) img = grabResult.Array print("Gray value of first pixel: ", img[0, 0]) grabResult.Release() camera.Close()