Search code examples
pythonpython-3.xpython-3.7pyspin

Why does PySpin.CameraList().GetSize() return zero devices?


Why does the following code return a cameralist with a device via PySpin.System() class and not via PySpin.CameraList() class?

The return value may differ depending on how many cameras you've attached from the manufacturer.

import PySpin

system = PySpin.System.GetInstance()

cam_list = system.GetCameras()

numCams  = cam_list.GetSize()                 # return value >= 1

numCams2  = PySpin.CameraList().GetSize()     # return value  = 0 

print ("No. of cams: %s - %s" % (numCams, numCams2))

Result:

No. of cams: 1 - 0


Solution

  • class PySpin.System(*args, **kwargs):

    Here the system object GetCameras() is used to retrieve the list of interfaces and cameras available on your OS. This only works if the static systempointer GetInstance() is used. Then the devices are loaded into the CameraList() and therefor not empty.

    class PySpin.CameraList(*args):

    Used to hold a list of camera objects and does not retrieve it by itself.

    Hence, numCams = len(system.GetCameras()) will also work to get the No. of devices.