Examples#
Enumerate the cameras#
from pyDCAM import *
def main():
print("PROGRAM START")
device_count = dcamapi_init()
print("dcamapi_init() found {} device(s).".format(device_count))
for i_device in range(device_count):
with HDCAM(i_device) as hdcam:
model = hdcam.dcamdev_getstring(DCAM_IDSTR.DCAM_IDSTR_MODEL)
camera_id = hdcam.dcamdev_getstring(DCAM_IDSTR.DCAM_IDSTR_CAMERAID)
bus = hdcam.dcamdev_getstring(DCAM_IDSTR.DCAM_IDSTR_BUS)
print("{} ({}) on {}".format(model, camera_id, bus))
dcamapi_uninit()
print("PROGRAM END")
if __name__ == '__main__':
main()
Show properties of the camera#
from pyDCAM import *
def main(i_device = 0):
print("PROGRAM START")
with use_dcamapi:
with HDCAM(i_device) as hdcam:
for prop_id in hdcam.dcamprop_ids():
name = hdcam.dcamprop_getname(prop_id)
value = hdcam.dcamprop_getvalue(prop_id)
print(name, value)
print("PROGRAM END")
if __name__ == '__main__':
main()
Capture a single image#
from pyDCAM import *
import matplotlib.pyplot as plt
def main(i_device = 0):
print("PROGRAM START")
with use_dcamapi:
with HDCAM(i_device) as hdcam:
# Configure the readout speed. Use slowest option for the ultraquite mode
hdcam.readout_speed = DCAMPROPMODEVALUE.DCAMPROP_READOUTSPEED__SLOWEST
hdcam.dcambuf_alloc(1)
hwait = hdcam.dcamwait_open()
hdcam.dcamcap_start()
# Wait for the frame to be ready, it has a timeout of 1000 millisec
hwait.dcamwait_start(timeout=1000)
# Copy the frame from the internal buffer to create a numpy array
array = hdcam.dcambuf_copyframe()
# Stop the capture and release the buffer
hdcam.dcamcap_stop()
hdcam.dcambuf_release()
# Display the image
plt.imshow(array)
plt.show()
print("PROGRAM END")
if __name__ == '__main__':
main()
Capture a single image with subarray mode#
from pyDCAM import *
import matplotlib.pyplot as plt
def main(i_device = 0):
print("PROGRAM START")
with use_dcamapi:
with HDCAM(i_device) as hdcam:
# Configure the readout speed. Use slowest option for the ultraquite mode
hdcam.readout_speed = DCAMPROPMODEVALUE.DCAMPROP_READOUTSPEED__SLOWEST
hdcam.subarray_mode = True # Enable subarray mode
hdcam.subarray_size = (100, 100) # 100x100 pixels
hdcam.subarray_pos = (200, 200) # 200 pixels from the top-left corner
hdcam.dcambuf_alloc(1)
hwait = hdcam.dcamwait_open()
hdcam.dcamcap_start()
# Wait for the frame to be ready, it has a timeout of 1000 millisec
hwait.dcamwait_start(timeout=1000)
# Copy the frame from the internal buffer to create a numpy array
array = hdcam.dcambuf_copyframe()
# Stop the capture and release the buffer
hdcam.dcamcap_stop()
hdcam.dcambuf_release()
# Display the image
plt.imshow(array)
plt.show()
print("PROGRAM END")
if __name__ == '__main__':
main()
Capture images with triggers#
from collections.abc import Callable, Iterable, Mapping
from typing import Any
from pyDCAM import *
import matplotlib.pyplot as plt
import time
import threading
def main(i_device = 0):
print("PROGRAM START")
with use_dcamapi:
with HDCAM(i_device) as hdcam:
# Use the software trigger. Alternatively, use DCAMPROP_TRIGGERSOURCE__EXTERNAL
# to use the external trigger.
hdcam.dcamprop_setvalue(DCAMIDPROP.DCAM_IDPROP_TRIGGERSOURCE,
DCAMPROPMODEVALUE.DCAMPROP_TRIGGERSOURCE__SOFTWARE
)
delay = 5
class FireSoftwareTrigger(threading.Thread):
def run(self):
for i in range(delay, 0, -1):
print(i)
time.sleep(1)
print("Firing software trigger")
hdcam.dcamcap_firetrigger()
hdcam.dcambuf_alloc(1)
hwait = hdcam.dcamwait_open()
hdcam.dcamcap_start()
# Firing the software trigger from a separate thread
FireSoftwareTrigger().start()
# Blocking until the software trigger is fired
hwait.dcamwait_start()
array = hdcam.dcambuf_copyframe()
hdcam.dcamcap_stop()
hdcam.dcambuf_release()
plt.imshow(array)
plt.show()
print("PROGRAM END")
if __name__ == '__main__':
main()