Project

General

Profile

Using Python With Critical Link GenTL Producer » snap.py

Updated for api change of device to remote_device - Jonathan Cormier, 03/16/2020 07:25 PM

 
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
import os
9
print(os.getenv('HARVESTERS_XML_FILE_DIR'))
10

    
11
# set up a logger for the harvester library.
12
# this is not needed but can be useful for debugging your script
13
logger = logging.getLogger('harvesters');
14
ch = logging.StreamHandler()
15
logger.setLevel(logging.DEBUG)
16
ch.setLevel(logging.DEBUG)
17
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
18
ch.setFormatter(formatter)
19
logger.addHandler(ch)
20

    
21
# Create the harvester
22
h = Harvester(logger=logger)
23
# the harvester can load dlls as well as cti files.
24
h.add_cti_file('c:\\Program Files\\Critical Link LLC\\Gentle Viewer\\bin\\GenTL.dll')
25
h.update_device_info_list()
26
print(h.device_info_list)
27

    
28
# create an image acquirer
29
ia = h.create_image_acquirer(list_index=0)
30
# this is required for larger images (> 16 MiB) with Critical Link's producer.
31
ia.num_buffers = 4
32
ia.remote_device.node_map.PixelFormat.value = 'Mono8'
33
# Uncomment to set the image ROI width, height. Otherwise will get full frame
34
#ia.remote_device.node_map.Width.value, ia.remote_device.node_map.Height.value = 800, 600
35

    
36
print("Starting Acquistion")
37

    
38
ia.start_image_acquisition()
39

    
40
# just capture 1 frame
41
for i in range(1):
42
	with ia.fetch_buffer(timeout=4) as buffer:
43
		payload = buffer.payload
44
		component = payload.components[0]
45
		width = component.width
46
		height = component.height
47
		data_format = component.data_format
48
		print("Image details: {}w {}h {}".format(width, height, data_format))
49
		# for monochrome 8 bit images
50
		if int(component.num_components_per_pixel) == 1:
51
			content = component.data.reshape(height, width)
52
		else:
53
			content = component.data.reshape(height, width, int(component.num_components_per_pixel))
54
		if int(component.num_components_per_pixel) == 1:
55
			plt.imshow(content, cmap='gray')
56
		else:
57
			plt.imshow(content)
58
		plt.show()
59

    
60
#
61
ia.stop_image_acquisition()
62
ia.destroy()
(2-2/5) Go to top
Add picture from clipboard (Maximum size: 1 GB)