PyVCAM is a Python 3.x wrapper for the PVCAM library.
The wrapper can be installed using the following command in an environment with
python and pip:
pip install PyVCAM
It requires the latest PVCAM to be installed - can be downloaded here.
The binary packages are available for 64-bit Windows and Linux on Intel platform only. For 32-bit or Arm Linux platform it must be complied from the source code. Please follow the instructions for development below.
The installed package contains just the wrapper. If you want to get an image from
the camera right away before writing your own application, PyVCAM repository contains
multiple examples, like seq_mode.py or live_mode.py.
Get a local copy of the GitHub repository by downloading the zip archive or cloning it e.g. from git command prompt:
git clone https://github.com/Photometrics/PyVCAM.git PyVCAM
Then switch to the folder with examples and run one:
cd PyVCAM/examples
python seq_mode.py
Some examples show the image from camera in a UI window and require opencv-python
or matplotlib packages to be installed.
For troubleshooting or active contribution you may want to install PyVCAM from GitHub.
- Cloned repository from GitHub as described in Examples chapter above.
- A C/C++ compiler is needed to build native source code. On Windows, Visual Studio 2022 was used for testing.
- The latest PVCAM and PVCAM SDK - both can be downloaded here.
Use your command prompt to navigate into the directory that contains pyproject.toml
file and run:
pip install .
An understanding of PVCAM API is very helpful for understanding PyVCAM.
This will create a camera object using the first camera that is found that can then be used to interact with the camera.
from pyvcam import pvc
from pyvcam.camera import Camera
pvc.init_pvcam() # Initialize PVCAM
cam = next(Camera.detect_camera()) # Use generator to find first camera
cam.open() # Open the camera
This captures a single image with a 20 ms exposure time and prints the values of the first 5 pixels.
# A camera object named cam has already been created
frame = cam.get_frame(exp_time=20)
print("First five pixels of frame: {}, {}, {}, {}, {}".format(*frame[:5]))
This is an example of how to change some of the settings on the cameras.
cam.clear_mode = "Never"
cam.exp_mode = "Ext Trig Trig First"
The same setting can be done without the strings via predefined constants that are generated
from C header pvcam.h:
from pyvcam import constants as const
cam.clear_mode = const.CLEAR_NEVER
cam.exp_mode = const.EXT_TRIG_TRIG_FIRST
When changing speed table, set new value to all three properties in this exact order:
readout_port → speed → gain, otherwise some legacy cameras could
end up in invalid state.
cam.readout_port = 0
cam.speed = 0
cam.gain = 1
More information on how to use this wrapper and how it works can be found in docs/PyVCAM.md.