Commit 1af4911f authored by root's avatar root
Browse files

camera binning

parent 2c006fdf
import numpy as np
import pypylon
import matplotlib.pyplot as plt
import Devices.InterferometerTools.routines as r
from Devices.CameraTools import binArray
# camera setup
# optical parameters
'''
config file:
y0: y offset in mm
z0: z offset in mm
binning: number of pixels to be summed
calibrated: boolean to check calibration
ExposureTimeAbs: exposure time in us
TriggerMode: On/Off
measurement file:
time: time (datetime object)
im1: first image
'''
mode = {False: 'Off', True: 'On'}
modei = {'Off': False, 'On': True}
class ScreenCamera:
#mendatory functions
def __init__(self, config):
self.psize=1./127.95*3/1.70 #mm
self.ep=1.74/self.psize
print ('connecting camera')
self.connect_camera()
print ('done')
self.set_config(config)
self.plot_server_im = None
def set_config(self,config):
self.cam.properties['ExposureTimeAbs']=config['ExposureTimeAbs']
self.cam.properties['TriggerMode']=mode[config['TriggerMode']]
self.y0 = config['y0']
self.z0 = config['z0']
self.n_binning = config['binning']
self.calibrated = config['calibrated']
def get_config(self):
config = {}
config['ExposureTimeAbs'] = self.cam.properties['ExposureTimeAbs']
config['TriggerMode'] = modei[self.cam.properties['TriggerMode']]
config['y0'] = self.y0
config['z0'] = self.z0
config['binning'] = self.n_binning
config['calibrated'] = self.calibrated
return config
def measure(self):
import datetime
time = datetime.datetime.now()
D=[]
if self.calibrated:
for img in self.cam.grab_images(2):
D.append(np.fliplr(img))
measurement = {'time': time,'im': D[0], 'im_c': D[1]}
return measurement
for img in self.cam.grab_images(1):
D.append(np.fliplr(img))
measurement = {'time': time,'im': D[0]}
return measurement
def plot_measure(self, measurement, config = None):
from PlottingServers import Plot2DServer
if self.plot_server_im == None:
self.plot_server_im = Plot2DServer({'title':'ScreenCamera', 'xlabel':'z [mm]', 'ylabel': 'y [mm]', 'image': False})
im1 = measurement['im']
try:
im_c = measurement['im_c']
im1 = im1 - im_c
except:
print ('not calibrated')
im1 = binArray(im1, 0, self.n_binning, self.n_binning, np.sum)
im1 = binArray(im1, 1, self.n_binning, self.n_binning, np.sum)
shape = im1.shape
self.plot_server_im.update(np.flipud(im1.astype('int8')),extent=np.array([0.,shape[1], 0., shape[0]]) - np.array([self.z0, self.z0, self.y0, self.y0]))
def turn_off(self):
self.cam.close()
#additional function
def connect_camera(self):
available_cameras = pypylon.factory.find_devices()
if len(available_cameras) == 0:
assert 'No cameras found'
print ('available cameras:')
for cam in available_cameras:
print(cam)
for availca in available_cameras:
if str(availca)[-3] == '2':
self.cam_to_connect = availca
cam = pypylon.factory.create_device(availca)
print ('camera found =) Be happy')
try:
cam.open()
except:
assert('camera not found')
#cam.properties['GevSCPSPacketSize']=9014
cam.properties['PixelFormat'] = 'Mono16'
self.cam = cam
\ No newline at end of file
No preview for this file type
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -10,13 +10,13 @@ class test_device1:
def get_config(self):
config = {}
config['id'] = self.id
config['id1'] = self.id
config['list'] = self.list
config['okasdasd'] = self.ok
return config
def set_config(self, config):
self.id = config['id']
self.id = config['id1']
self.list = config['list']
self.ok = config['okasdasd']
......
......@@ -521,10 +521,9 @@ class parameter_chooser:
device = self.select_device.value
scannable = []
config = dm.get_config([device])
scannable = []
for item in config[type(device).__name__].items():
if np.dtype(type(item[1])) == np.dtype('float64') or np.dtype(type(item[1])) == np.dtype(int):
scannable += [item[0]]
......@@ -541,15 +540,18 @@ class parameter_chooser:
if parameter == None:
return
device = self.select_device.value
try:
device = self.select_device.value
config = dm.get_config([device])
current_value = config[type(device).__name__][parameter]
config = dm.get_config([device])
current_value = config[type(device).__name__][parameter]
self.current_value.value = '<b> current value: '+str(current_value)+' </b>'
self.current_value.value = '<b> current value: '+str(current_value)+' </b>'
self.minv.value = current_value
self.maxv.value = current_value
self.minv.value = current_value
self.maxv.value = current_value
except:
print ('Choose parameter!!!')
def get_linspace(self):
return np.linspace(self.minv.value, self.maxv.value, self.nsteps.value)
......
This diff is collapsed.
......@@ -28,9 +28,7 @@ def plot_server_1d(connecx = None, connecy = None, config = {'xlabel' : '','ylab
p.plot_height = 300
p.plot_width = 500
r1 = p.square(x, y, fill_color=None, line_color="green")
r2 = p.line(x, y, line_color="green")
r1 = p.line(x, y, line_color="green")
p.xaxis.axis_label = config['xlabel']
p.yaxis.axis_label = config['ylabel']
......@@ -43,9 +41,7 @@ def plot_server_1d(connecx = None, connecy = None, config = {'xlabel' : '','ylab
# updating a single column of the the *same length* is OK
if connecx.poll(0.1):
r1.data_source.data["x"] = connecx.recv()
r2.data_source.data["x"] = r1.data_source.data["x"]
r1.data_source.data["y"] = connecy.recv()
r2.data_source.data["y"] = r1.data_source.data["y"]
doc.add_periodic_callback(update, 50)
......
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bd8a02b8cfd1475d90b759289bfd3b95"
}
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from security import gui\n",
"gui().show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
No preview for this file type
No preview for this file type
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment