How to set parameters of basler using python, _genicam.AccessException: Node is not writable

2.4k Views Asked by At

Hi everyone Is this correct way to set the basler camera parameters using basler?

Is any other way to access camera after calling camera.stratGrabbing() function?

I am getting error like :

return _genicam.IInteger_SetValue(self, Value, Verify) _genicam.AccessException: Node is not writable. : AccessException thrown in node 'Height' while calling 'Height.SetValue()' (file 'integert.h', line 77)

import cv2
from pypylon import pylon

camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())
converter = pylon.ImageFormatConverter()
camera.Open()
camera.CenterX=False
camera.CenterY=False

# 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.StartGrabbing()
camera.Open()
print("Max gain",camera.Gain.Max)
print("Min gain",camera.Gain.Min)
print("Max ExposureTime",camera.ExposureTime.Max)
print("Min ExposureTime",camera.ExposureTime.Min)
i=0
j=0
while camera.IsGrabbing():
    grabResult = camera.RetrieveResult(5000, pylon.TimeoutHandling_ThrowException)
    
    if grabResult.GrabSucceeded():
        i+=1
        j+=1
        if i==700:
            print(i)
            #camera.Open()
            camera.Height.SetValue( 200)
            camera.Width.SetValue( 300)
            
            camera.Gain=5
            camera.ExposureTime=8000
            i=0
        if j==500:
            #camera.Open()
            print(j)
            
            camera.Height.SetValue(1088)
            camera.Width.SetValue( 2048)
            
            camera.Gain=20
            camera.ExposureTime=8000
            j=0
        # Access the image data.
        
        print("AMAR :",camera.IsOpen())
        image = converter.Convert(grabResult)
        img = image.GetArray()
        cv2.imshow("image",img)
        cv2.waitKey(1)

grabResult.Release()
camera.Close()
2

There are 2 best solutions below

3
Amarnath Reddy Surapureddy On
# cam stop
cam.AcquisitionStop.Execute()
# grab unlock
cam.TLParamsLocked = False

cam.OffsetX = 0
cam.OffsetY = 0
cam.Width = cam.Width.Max // 4
cam.Height = cam.Height.Max // 4

# grab lock
cam.TLParamsLocked = True
# cam start
cam.AcquisitionStart.Execute()

With the lock it may help you

4
Marcin Kowalski On

You cannot change camera's Width/Height parameters while camera is in grabbing state (after camera.StartGrabbing() ). Only RW parameters regarding AOI settings is OffsetX/OffsetY and some other model dependent ones (CenterX /CenterY / MirrorX / MirrorY) since they do not require reallocating internal memory buffers inside camera.

Put any Width/Height changes before grabbing loop, and after camera.Open().

From your code I presume you want to make some kind of dynamic parameter changes while camera is grabbing. Please consider Sequencer function of Basler ace cameras. In the nutshell - camera can change some parameters autonomically, frame by frame, without any user commands. However still, it won't help you in your Width/Height case.

Further reading below:
https://docs.baslerweb.com/sequencer-%28usb-cameras%29
https://docs.baslerweb.com/sequencer-(gige-cameras)