-
Notifications
You must be signed in to change notification settings - Fork 214
Description
Describe what you want to implement and what the issue & the steps to reproduce it are:
Hello,
I am developing an application for large-scale image acquisition with Basler GigE cameras (model: a2A3840-13gcBAS). The goal is to grab images from all cameras (typically each camera grabs 1–6 images per run, using .GrabOne()
), with all cameras connected via a network switch to a single physical Ubuntu machine.
Everything works as expected during image acquisition:
- All images can be grabbed from each camera successfully and saved.
However, after the acquisition is complete and the program exits (after attempting to release/close all resources), I very frequently encounter:
Segmentation fault (core dumped)
There is no other Python exception or error message. This happens right after the script finishes, never during image grabbing.
Is your camera operational in Basler pylon viewer on your platform?
- No
I cannot see or open the cameras in pylon viewer, but all cameras are visible in the pylon IP configurator tool.
Steps to reproduce
-
Connect 59 Basler a2A3840-13gcBAS cameras to the same physical PC via a network switch.
-
For each camera, open it, and grab 1–6 images using
.GrabOne()
, save each image. -
After all images are captured and all cameras are (supposedly) released/closed using
.Close()
and deleted, the script exits. -
Observe:
- All images are correctly captured and saved
- At the end of the script (program exit), a segmentation fault (
Segmentation fault (core dumped)
) frequently occurs.
-
This happens regardless of how many times
.Close()
ordel
is called for camera objects; no other Python exception is raised.
Code sample
import cv2
from pypylon import pylon
import os
import traceback
from datetime import datetime
def find_basler_cameras():
devices = pylon.TlFactory.GetInstance().EnumerateDevices()
return devices
def main():
export_dir = "/home/test"
converter = pylon.ImageFormatConverter()
converter.OutputPixelFormat = pylon.PixelType_BGR8packed
converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned
basler_devices = find_basler_cameras()
if len(basler_devices) == 0:
print("no camera detected!")
else:
print(f"{len(basler_devices)} cameras detected")
# Create an array of instant cameras for the found devices and avoid exceeding a maximum number of devices.
basler_cameras = pylon.InstantCameraArray(min(len(basler_devices), 100))
cam_dict = {}
grab_record_dict = dict()
for i, camera in enumerate(basler_cameras):
camera.Attach(pylon.TlFactory.GetInstance().CreateDevice(basler_devices[i]))
serial_num = camera.GetDeviceInfo().GetSerialNumber()
cam_model = camera.GetDeviceInfo().GetModelName()
print(f"{i}: {serial_num}: {cam_model}")
camera.Open()
camera.PixelFormat.Value = "BayerRG8"
cam_dict[serial_num] = {"cam": camera}
grab_record_dict[serial_num] = 0
now = datetime.now()
nowstring = now.strftime("%Y%m%d_%H%M%S")
export_dir_cams = os.path.join(export_dir, f"{nowstring}")
os.makedirs(export_dir_cams, exist_ok=True)
for num, cam_info in cam_dict.items():
cam = cam_info["cam"]
et = 50000
for et in [30000, 50000, 80000]:
cam.ExposureTime.Value = et
result = cam.GrabOne(5000)
if result.GrabSucceeded():
image = converter.Convert(result)
img = image.GetArray()
img_name = f"{num}_et{et}.jpg"
cv2.imwrite(os.path.join(export_dir_cams, img_name), img)
grab_record_dict[num] += 1
if cam.IsOpen():
cam.Close()
# clean up (with and without are the same)
cam_dict.clear()
del cam_dict
del basler_cameras
import gc;
gc.collect();
time.sleep(0.1)
main()
# (Segmentation fault occurs here, after script ends)
What I have tried
- Increased
ulimit -n
to 4096. - Explicitly called
.Close()
anddel
for all camera objects and theInstantCameraArray
. - Used
gc.collect()
and addedtime.sleep()
to allow resource cleanup. - No Python-level exception or error is raised; only segmentation fault after script exit.
- All image acquisition operations work fine and images are saved correctly.
Additional notes
- Each run is single-threaded (not multi-threaded or multi-process).
- Each camera only grabs a few images per session.
- Cameras are visible in pylon IP Configurator but not visible in pylon Viewer.
- No other user-space process is using the cameras.
Questions
- Is this a known resource management issue when using large numbers of cameras?
- Are there recommended practices / code for robust image capture using large numbers of cameras with pypylon?
- Could the network topology (all cameras via one switch) or pylon viewer detection issue be related to the segmentation fault?
- Is there a workaround or patch for this problem, or is there an upper limit for cameras per process?
Thank you for your support and advice!
Is your camera operational in Basler pylon viewer on your platform
No
Hardware setup used
- Platform: Physical machine (not a VM, not docker)
- CPU: Intel Core i5-14600KF ×20
- RAM: 32GB
- OS: Ubuntu 22.04 LTS
- Python: 3.10 (miniconda)
- pylon: 8.0.1-16188
- pypylon: 4.1.0
- Cameras: 59x Basler a2A3840-13gcBAS (GigE)
- Cameras connection: All cameras are connected to a netgear switch (PoE), which is connected to the PC via ethernet.
Camera(s) used
Basler a2A3840-13gcBAS (40378431)
p=vg4_imx334c_bas/s=r/v=2.4.2/i=8208.11/h=02e36ab
Basler a2A3840-13gcBAS (40439340)
p=vg4_imx334c_bas/s=r/v=2.4.2/i=8208.11/h=02e36ab
Basler a2A3840-13gcBAS (40444654)
p=vg4_imx334c_bas/s=r/v=2.4.2/i=8208.11/h=02e36ab
Basler a2A3840-13gcBAS (40604424)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604425)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604427)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604428)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604429)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604430)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604431)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604432)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604434)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604435)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604437)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604438)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604441)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604442)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604443)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604444)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604445)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604446)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604447)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604449)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604450)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604451)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604454)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604456)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604457)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604459)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604460)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604462)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604464)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604468)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604470)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604471)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604781)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604785)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40604786)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605112)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605115)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605116)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605117)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605118)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605119)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605121)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605123)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605124)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605125)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605127)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605128)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605130)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605131)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605132)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605133)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605134)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605135)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605140)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605141)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Basler a2A3840-13gcBAS (40605149)
p=vg4b_imx334c_bas/s=r/v=2.5.1/i=9421.6/h=e7c7a35
Runtime information:
python: 3.10.16 (main, Dec 11 2024, 16:24:50) [GCC 11.2.0]
platform: linux/x86_64/6.8.0-59-generic
pypylon: 4.1.0 / 9.0.3.215