StudentCV / PyPylon

pylon wrapper for Python
Other
5 stars 3 forks source link

How to manipulate the Camera Properties #3

Open nmarc opened 7 years ago

nmarc commented 7 years ago

Hi ! and thank you four your great project. I try to change the Camera Properties, but I fail.

The examples in the PylonSDK (C++) use Camera = pTl->CreateDevice( devices[ 0 ] ); Camera.Open(); Camera.ExposureTimeRaw.SetValue( 500 ); but this does not work in Python.

may somebody please help me to modify the Brightness, Gain, Exposure-Time and Contrast ? Thanks in advance Marc

kwint commented 6 years ago

Marc have you fixed this already? I'm having the same issue

nmarc commented 6 years ago

Hi kwint, i found a workarround. you can load an full parameter set via *.pfs File.

Code Snippet: ` valid, self._pGrabber = self._cam.connectGrabber() print("GetDeviceInfo().GetSerialNumber = ", self._pGrabber.GetDeviceInfo().GetSerialNumber() ) grab= self._pGrabber.GrabOne(3000) # timeout von 3 sekunden if not grab.GrabSucceeded(): print("GRAP ERROR !!! ")

print("Camera is online and ready for setup !") self._cam.disconnectGrabber() self._cam.loadPFSFile(path) `

i build a Class like: Code snippet: ` class PylonCamera(): def init(self): self.logger = logging.getLogger('PylonCamera') self._tlfactory = pylon.TlFactory.GetInstance() self._ptl = self._tlfactory.CreateTl('BaslerGigE')
self._convertMethode = None self._pixelDataFormat = None self._pGrabber = None

def connectGrabber(self):

list devices

    if (pylon.__version__ == "1.2.0rc2+pylon5.0.12.11830" or pylon.__version__ == "1.1.0+pylon5.0.11.10913"):
        detected_devices = self._tlfactory.EnumerateDevices()# Bei der neuen Version wird das Enumerate über die Kamerainstanzs gemacht
    else:
        detected_devices = self._ptl.EnumerateDevices()# Bei der alten noch über den Transport Layer
    self.logger.info("%i devices detected:" % len(detected_devices))

    self.logger.info([d.GetFriendlyName() for d in detected_devices])

    #exit if no devices found
    if(len(detected_devices) == 0):
        self.logger.error("ERROR -> No device")
        raise RuntimeError("keine brauchbare Kamera auf dem GeniCam Bus")
    if (pylon.__version__ == "1.2.0rc2+pylon5.0.12.11830" or pylon.__version__ == "1.1.0+pylon5.0.11.10913"):
        self._pDevice = self._tlfactory.CreateDevice(detected_devices[0])# In der neuen Version über die Instanz
    else:
        self._pDevice = self._ptl.CreateDevice(detected_devices[0]) # Bei der alten über den Transport Layer

    self._pGrabber = pylon.InstantCamera(self._pDevice)
    self.investigateImageConverter()

    return (True,  self._pGrabber)

def disconnectGrabber(self): self._pGrabber.StopGrabbing() self._pGrabber.Close()

def loadPFSFile(self, path): """ Load a PFS File to the Camera :param path: :return: """ self._pGrabber.Open() pylon.FeaturePersistence.Load(path, self._pGrabber.GetNodeMap(), True) self._pGrabber.Close() time.sleep(0.3)

`

So you are able to manipulte the camera Settings. You can export the *.pfs-File from the Basler-Camera with the pylon-Viewer. Ist a verry simple file-format, so you can use a parser to generate an individual Setting on the fly.

I hope you can solve you task. Marc

GerrikLabra commented 11 months ago

Danke. Sprechen sprescht nett destuch, but I appreciate the load definition. That will be most helpful.