1
|
# example python script for capturing an image from CMV50K EVK
|
2
|
# you must have c:\Program Files\Critical Link LLC\Gentle Viewer\bin
|
3
|
# in your path prior to running this script.
|
4
|
from harvesters.core import Harvester
|
5
|
import logging
|
6
|
import matplotlib.pyplot as plt
|
7
|
|
8
|
# set up a logger for the harvester library.
|
9
|
# this is not needed but can be useful for debugging your script
|
10
|
logger = logging.getLogger('harvesters');
|
11
|
ch = logging.StreamHandler()
|
12
|
logger.setLevel(logging.DEBUG)
|
13
|
ch.setLevel(logging.DEBUG)
|
14
|
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
15
|
ch.setFormatter(formatter)
|
16
|
logger.addHandler(ch)
|
17
|
|
18
|
# Create the harvester
|
19
|
h = Harvester(logger=logger)
|
20
|
# the harvester can load dlls as well as cti files.
|
21
|
h.add_cti_file('c:\\Program Files\\Critical Link LLC\\Gentle Viewer\\bin\\GenTL.dll')
|
22
|
h.update_device_info_list()
|
23
|
h.device_info_list
|
24
|
|
25
|
# create an image acquirer
|
26
|
ia = h.create_image_acquirer(list_index=0)
|
27
|
# this is required for larger images (> 16 MiB) with Critical Link's producer.
|
28
|
ia.num_buffers = 4
|
29
|
# set the width, height -> example is from a CMV50K EVK mono system
|
30
|
ia.device.node_map.Width.value, ia.device.node_map.Height.value = 8000, 6004
|
31
|
ia.device.node_map.PixelFormat.value = 'Mono8'
|
32
|
|
33
|
print("Starting Acquistion")
|
34
|
|
35
|
ia.start_image_acquisition()
|
36
|
|
37
|
# just capture 1 frame
|
38
|
for i in range(1):
|
39
|
with ia.fetch_buffer(timeout=4) as buffer:
|
40
|
payload = buffer.payload
|
41
|
component = payload.components[0]
|
42
|
width = component.width
|
43
|
height = component.height
|
44
|
data_format = component.data_format
|
45
|
# for monochrome 8 bit images
|
46
|
if int(component.num_components_per_pixel) == 1:
|
47
|
content = component.data.reshape(height, width)
|
48
|
else:
|
49
|
content = component.data.reshape(height, width, int(component.num_components_per_pixel))
|
50
|
if int(component.num_components_per_pixel) == 1:
|
51
|
plt.imshow(content, cmap='gray')
|
52
|
else:
|
53
|
plt.imshow(content)
|
54
|
plt.show()
|
55
|
|
56
|
#
|
57
|
ia.stop_image_acquisition()
|
58
|
ia.destroy()
|