Class sensicam

class control.sensicam(board=c_long(0), hdriver=c_void_p(None))

Bases: threading.Thread

Python wrapper for sensicam SDK from pco.

This class is a Python wrapper for the Sensicam SDK of pco AG, Germany and provides an API to handle an pco camera in python. It is tested and used with a Dicam Pro. The constructor automatically intialized the PCI board and allocates hdriver accordingly.

Requires:

Sensicam SDK (>=v6.01.04), pco.camware(>=v3.16)

Parameters:
  • board (ctypes.c_int) – number of PCI-Controller-Board. Default: 0
  • hdriver (ctypes.wintypes.HANDLE) – Filehandle of the opened driver. Default: None

Example:

logging.basicConfig(filename="DEBUG_pco_init.log",
                    level=logging.DEBUG,
                    format='%(asctime)s - %(name)s - %(levelname)s'
                    ' - %(message)s')
board = cInt(0)
pcoCam = sensicam(board)
print("Card initialized.")
pcoCam.setup_camera()
print("Camera set up.")
# Setup a the COC
gain = cInt(0)     # normal analog gain
submode = cInt(0)  # sequential, busy out
roixmin = cInt(1)
roixmax = cInt(20)
roiymin = cInt(1)
roiymax = cInt(20)
hbin = cInt(1)
vbin = cInt(1)
# Table values:
phosphordecay, mcpgain, trigger, loops = 100, 999, 0, 1
imageTime1 = [0, 1000, 0, 300]
table = pcoCam.dicamTableGen(phosphordecay, mcpgain, trigger, loops,
                             imageTime1)
camera_type = cInt(5)     # For dicam pro
pcoCam.setCoc(gain, camera_type, submode, roixmin, roixmax, roiymin,
              roiymax, hbin, vbin, table)
print("COC loaded")
# Get sizes and allocate buffer
pcoCam.getSizes()
# Initialize a buffer
curBuf = imgBuf()
curBuf.width = cInt(10)
curBuf.height = cInt(5)
pcoCam.allocateBuffer(curBuf)
pcoCam.mapBuffer(curBuf)
pcoCam.setBufferEvent(curBuf)
# Set camera to state RUN
pcoCam.runCoc()
# Acquire and show the image
pcoCam.readImage12bit(curBuf, True)
curBuf.rawImage.show()
# Convert the rawImage to 8 bit
# TODO Check wether a transform due to 16bit image and 12bit colordepth
# is required
exportImage = curBuf.rawImage.convert("L")
exportImage.save("test.png",)
# Stop the camera, only necessary in continuous trigger mode.
# pcoCam.stopCoc()
# Free all buffers and close the camera
pcoCam.removeAllBuffersFromList()
pcoCam.freeBuffer(curBuf)
pcoCam.close()
print("Card closed.")
addBuffer(curBuf)

Adds buffer to the current list. The buffer is initialized.

Parameters:curBuf (class pydicamSDK.imgBuf) – Buffer to which the image will be saved.
allocateBuffer(curBuf)

Allocates a buffer for the camera in the memory.

Parameters:curBuf (class pydicamSDK.imgBuf) – Buffer to which the image will be saved.
Returns:curBuf.size, the computed size for the buffer in bit
Return type:ctypes.c_int
close()

Closes the connection to the board.

daemon

A boolean value indicating whether this thread is a daemon thread.

This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False.

The entire Python program exits when no alive non-daemon threads are left.

dicamTableGen(phosphordecay, mcpgain, trigger, loops, imageTime1, *imageTimes)

Table generator for dicam Pro.

Creates a valid table for the COC settings, which can be used in method setCoc.

Parameters:
  • phosphordecay (int) – Phosphor decay time in ms.
  • mcpgain (int) – MCP gain. Ranges from 0 to 999
  • trigger (int) – Selects the trigger mode.
  • loops (int) – Sets the number of loops.
  • imagetime (list or tuple of int) – list/tuple containing delayhigh (ms), delaylow(ns), timehigh(ms), timelow(ns)
Returns:

table for setCoc().

Return type:

str

errCheck(err)

Returns the error number from pcoError

Takes the proviced error number and uses the function getText(err) from module pcoError to retrieve the error message. If the error code is nor an error neither a warning, the function raises a RuntimeError.

Parameters:err – Number with the error of the another method
Type:int
freeBuffer(curBuf)

Frees the given input buffer.

Parameters:curBuf (class pydicamSDK.imgBuf) – Buffer to which the image will be saved.
getCameraDesc()
getImageFromBuffer(curBuf, npArray=False)

Get the image from an filled buffer

Input:
Parameters:
  • curBuf (class pydicamSDK.imgBuf) – Buffer to which the image will be saved.
  • npArray (bool) – If set, the method returns a numpy array next to the rawImage
Returns:

Acquired image (curBuf.rawImage and curBuf.npImage)

Return type:

PIL/Pillow image object and numpy array

getName()
getSizes()

Obtain information about the CCD and images sizes.

Implements the following values according to the camera into the class

Parameters:
  • ccdxsize (ctypes.c_int) – resolution of CCD in x
  • ccdysize (ctypes.c_int) – resolution of CCD in y
  • curWidth (ctypes.c_int) – current width of image
  • curHeight (ctypes.c_int) – current height of image
  • curBitpix (ctypes.c_int) – current bits per pixel in image
ident

Thread identifier of this thread or None if it has not been started.

This is a nonzero integer. See the thread.get_ident() function. Thread identifiers may be recycled when a thread exits and another thread is created. The identifier is available even after the thread has exited.

isAlive()

Return whether the thread is alive.

This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads.

isDaemon()
is_alive()

Return whether the thread is alive.

This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads.

join(timeout=None)

Wait until the thread terminates.

This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.

When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call isAlive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.

When the timeout argument is not present or None, the operation will block until the thread terminates.

A thread can be join()ed many times.

join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.

mapBuffer(curBuf)

Adds buffer to the current list

The function mapBuffer is just a dummy function to maintain consistency with the SDK. The function addBuffer is used for addition of buffer.

Parameters:curBuf (class pydicamSDK.imgBuf) – Buffer to which the image will be saved.
name

A string used for identification purposes only.

It has no semantics. Multiple threads may be given the same name. The initial name is set by the constructor.

readImage12bit(curBuf, npArray=False)

Read an image in 12bit to the current selected buffer

Input:
Parameters:
  • curBuf (class pydicamSDK.imgBuf) – Buffer to which the image will be saved.
  • npArray (bool) – If set, the method returns a numpy array next to the rawImage
Returns:

Acquired image (curBuf.rawImage and curBuf.npImage)

Return type:

PIL/Pillow image object and numpy array

removeAllBuffersFromList()

Removes all buffers from list.

Parameters:curBuf (class pydicamSDK.imgBuf) – Buffer to which the image will be saved.
run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

runCoc(mode=c_long(4))

Starts the processing of the COC.

Parameters:mode – 10 for continuous, 4 for single trigger. Default 4
Type:int
setBufferEvent(curBuf)

Create or attach an event handle for curBuf.

Parameters:curBuf (class pydicamSDK.imgBuf) – Buffer to which the image will be saved.
Returns:curBuf.hEvent, event Handle for the buffer
Return type:ctypes.wintypes.HANDLE
setCoc(gain, camera_type, submode, roixmin, roixmax, roiymin, roiymax, hbin, vbin, table)

The Camera Operation Code (COC) is set with this function.

Further details can be obtained in the official SDK description.

Parameters:
  • gain (ctypes.c_int) – chosen gain (0 normal analog, 1 extended analog)
  • type (camera) – Selects the used camera (eg. 5 for Dicam Pro)
  • submode (ctypes.c_int) – Choses the submode (e.g. 0)
  • roixmin (ctypes.c_int) – Region of interest min value in x
  • roixmax (ctypes.c_int) – Region of interest max value in x
  • roiymin (ctypes.c_int) – Region of interest min value in y
  • roiymax (ctypes.c_int) – Region of interest max value in y
  • hbin (ctypes.c_int) – Value for horizontal binning
  • vbin (ctypes.c_int) – Value for vertical binning
  • table (str) – Set the delay and exposure times. Time values are separated by comma. The array concludes with the sequence “-1,-1”. Detailed information in SDK manual
setDaemon(daemonic)
setName(name)
setup_camera()

Sets up the camera

start()

Start the thread’s activity.

It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.

This method will raise a RuntimeError if called more than once on the same thread object.

stopCoc()

Stops the processing of the COC.

Only necessary if in continuous trigger mode.

waitForImage(timeout=1000)

Wait for the next to be aquired

Parameters:timeout (int) – waiting time for new image in ms. Default 1000