Basler pylon SDK × C#
When you need to reproduce a specific capture condition or quickly switch between multiple setups, being able to save and load Basler camera settings as PFS files is extremely useful.
In this article, we’ll look at how to save and restore camera settings in .pfs format using the Basler pylon SDK.
What Is the PFS Format?
A PFS file (pylon Feature Stream file) is Basler’s configuration format for saving and loading camera settings.
✅ Typical Use Cases
-
Backup of camera settings
- Decide on a stable configuration once → save it → reuse it after reboot or on another PC.
-
Sharing experiment conditions
- Distribute settings so everyone in a lab or production line captures under the same conditions.
-
Loading settings from your software
- Call
camera.Parameters.Load("config.pfs")to instantly apply a predefined setup (shown later).
- Call
✅ Environment
| Item | Value |
|---|---|
| Camera | Basler acA2500-14gm |
| SDK | Basler pylon Camera Software Suite |
| Language | C# / .NET 8 |
| File Format | .pfs (pylon Feature Set / Feature Stream) |
📝 Saving Camera Settings (Save)
As in previous articles, we’ll extend the same BaslerCameraSample class introduced in:
- How to Display and Save Basler Camera Images with OpenCV
- How to Capture a Single Image Using the Basler pylon SDK in C#
To save settings, we can use the Camera.Parameters.Save() method.
The example below saves the CameraDevice settings. The ParameterPath argument can be either a direct string or one of the predefined properties of the ParameterPath class.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
using Basler.Pylon; namespace BaslerSamples { public static class BaslerCameraSample { public void SaveCameraDeviceParameters(string filePath) { if (Camera == null || !IsConnected) throw new InvalidOperationException(“Camera is not connected.”); if (string.IsNullOrWhiteSpace(filePath)) throw new ArgumentException(“File path cannot be null or empty.”, nameof(filePath)); Camera.Parameters.Save(filePath, ParameterPath.CameraDevice); Console.WriteLine($“Camera settings saved to {filePath}”); } } } |
In many practical scenarios, saving just CameraDevice is sufficient.
However, if you want to dump multiple parameter groups at once, you can iterate over all string properties of ParameterPath via reflection.
Even though we check Camera.Parameters.Contains(value) before calling Save(), some properties may still cause Save() to throw an ArgumentException due to model differences or unsupported paths.
In that case we catch and skip them.
Note: Relying on exceptions as control flow is not ideal; if you know of a cleaner approach, feel free to adapt this logic.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
public void SaveAllParameters(string directory) { var t = typeof(ParameterPath); var stringProps = t .GetProperties(BindingFlags.Public | BindingFlags.Static) .Where(p => p.PropertyType == typeof(string)); foreach (var prop in stringProps) { // Static property, so the first argument of GetValue should be null. string value = (string)(prop.GetValue(null) ?? string.Empty); if (!string.IsNullOrEmpty(value) && Camera.Parameters.Contains(value)) { string filePath = System.IO.Path.Combine(directory, $“{value}.pfs”); try { Camera.Parameters.Save(filePath, value); } catch (ArgumentException) { // Skip parameters that cannot be saved by this camera. continue; } Console.WriteLine($“Saved {value} to {filePath}”); } } Console.WriteLine($“Camera settings saved to {directory}”); } |
📂 Example of a Saved PFS File
If you open a .pfs file in a text editor, you can see that the configuration values are stored in a tab-separated (TSV) format.
Most of the important parameters are grouped under CameraDevice, so in many cases saving just that group is enough.
|
1 2 3 4 5 6 |
ExposureMode Timed // Exposure mode ExposureAuto Off // Auto exposure off (manual control) ExposureTimeRaw 35000 // Unit: µs AcquisitionFrameRateEnable 1 // Enable frame rate control AcquisitionFrameRateAbs 30.0003 // Frame rate setting |
📥 Loading Settings (Load)
Next, let’s load a previously saved .pfs file back into the camera.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
public bool LoadCameraDeviceParameters(string filePath) { if (Camera == null || !IsConnected) throw new InvalidOperationException(“Camera is not connected.”); if (string.IsNullOrWhiteSpace(filePath)) throw new ArgumentException(“File path cannot be null or empty.”, nameof(filePath)); try { Camera.Parameters.Load(filePath, ParameterPath.CameraDevice); Console.WriteLine($“Camera settings loaded from {filePath}”); return true; } catch (Exception ex) { Console.WriteLine($“Failed to load camera settings: {ex.Message}”); return false; } } |
Example: Save & Load Round Trip
The following test changes the frame rate, saves the settings, then loads them back and verifies that the value was restored.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[TestMethod()] public void LoadCameraDeviceSettingsTest() { if (!_baslerCameraSample.IsConnected) _baslerCameraSample.Connect(); // Change frame rate as an example. _baslerCameraSample.EnableFrameRate(true); _baslerCameraSample.SetFrameRate(10); // 10 fps // Save current settings. _baslerCameraSample.SaveCameraDeviceParameters(“LoadCameraDeviceSettingsTest.pfs”); _baslerCameraSample.SetFrameRate(15); // Change to 15 fps _baslerCameraSample.LoadCameraDeviceParameters(“LoadCameraDeviceSettingsTest.pfs”); var loadedFrameRate = _baslerCameraSample.GetFrameRate(); Assert.AreEqual(10, loadedFrameRate, “Loaded frame rate should be 10 fps.”); } |
After loading, the camera’s frame rate returns to 10 fps, confirming that the PFS file was applied correctly.
⚠️ Notes & Caveats
| Point | Details |
|---|---|
| What gets saved | Only parameters that are exposed as user-accessible by the camera |
| Trigger & device-specific settings | Some hardware-dependent features may be excluded |
| Applying PFS to another camera | Prefer using the same model or a model with compatible features |
✅ Summary
-
Using
Camera.Parameters.Save()/Load()you can easily reproduce capture conditions. -
.pfsfiles are essentially TSV-based configuration files. -
Very useful for:
- Backing up camera setups
- Sharing experiment conditions
- Managing multiple capture profiles
Coming Up Next
In the next article, we’ll look at how to log metadata such as exposure, gain, and ROI together with captured images.
I’m also working on a GUI tool to conveniently view and edit Basler camera settings; that will be introduced in a future post.
Author: @MilleVision

コメントを残す