def take_image(filename): """take_image: The function will create a Operating System timestamp variable (OS_time), configure the 2 IRCSP cameras to take an image (image1 & image2) and store the FPA temperatures (temp1 & temp2) into an HDF5 File format with a unique naming convention. Parameters: filename - the filename of the HDF5 file. Returns: HDF5 file with 2 FLIR Boson Images, 2 FPA Temperatures & OS_time string. """ # Time/Speed Test - Start start = datetime.datetime.now() #Create Timestamp for File Creation Tracking now = datetime.datetime.now() OS_time = now.strftime("%H:%M") camera1 = Boson(port='COM4') #camera2 = Boson(port='COM6') print(camera1.find_video_device()) #print(camera2.find_video_device()) #set FFC to manual #camera1.set_ffc_manual() #camera2.set_ffc_manual() #get FPA temperature #temp1 = camera1.get_fpa_temperature() #temp2 = camera2.get_fpa_temperature() #Take Image #image1 = camera1.grab(device_id = 1) #image2 = camera2.grab(device_id = 2) #Close Camera camera1.close() #camera2.close() # Open as Read-Write ("a" - creates file if doesn't exist) #with h5py.File(filename, "a") as h5: #h5.attrs["OS_time"] = OS_time #h5["image1"] = image1 #h5["image2"] = image2 #h5["temp1"] = temp1 #h5["temp2"] = temp2 #Time/Speed Test - Finish finish = datetime.datetime.now() print("Image Capture File: ", filename, " created in ", finish - start) #Adjust Sleep for File Creation Rate - (File/Seconds) time.sleep(10)
class ThreadedBoson(ThreadedCamera): def __init__(self, device=None, port=None, baudrate=921600, loglevel=logging.WARNING): super(ThreadedBoson, self).__init__() self.temperature = None self._connect(device, port, baudrate, loglevel) def _connect(self, device, port, baudrate, loglevel): try: self.camera = Boson(port, baudrate, loglevel) self.camera.setup_video(device) self.camera.grab() if not self.camera.cap.isOpened(): warnings.warn("Failed to open camera") self.camera = None except IOError: warnings.warn("Failed to find camera") self.camera = None def height(self): return self.camera.cap.get(cv2.CAP_PROP_FRAME_HEIGHT) def width(self): return self.camera.cap.get(cv2.CAP_PROP_FRAME_WIDTH) def channels(self): return 1 def dtype(self): return np.uint16 def _grab(self): image = np.expand_dims(self.camera.grab(), -1) self.min_count = image.min() self.max_count = image.max() return image def close(self): self.camera.close() def get_target_fps(self): return self.camera.cap.get(cv2.CAP_PROP_FPS)
single_cam_mono_sweep Created on Wed Dec 9 13:12:18 2020 This script will sweep over wavelength on the monochomator for a single measurement configuration. This includes image capture for a single camera (no MS) And a single polarization state (unpol, H,V, ect) Output will be saved as a hdf5 file Uses flirpy, make sure enviroment is open uses python-usbtmc @author: khart """ from flirpy.camera.boson import Boson import matplotlib.pyplot as plt import numpy as np import h5py import time #initialize camera camera1 = Boson(port="COM5") camera2 = Boson(port="COM6") print(camera1.find_video_device()) print(camera2.find_video_device()) #close camera camera1.close() camera2.close()
motor.move_by(45) time.sleep(wait) plt.imshow(I45) plt.show() I90 = take_image(frames) motor.move_by(45) time.sleep(wait) plt.imshow(I90) plt.show() I135 = take_image(frames) plt.imshow(I135) plt.show() camera.close() S0 = (I0 + I45 + I90 + I135) / 4 S1 = I0 - I90 S2 = I45 - I135 plt.imshow(S0) plt.colorbar() plt.show() plt.imshow(S1 / S0) plt.colorbar() plt.show() plt.imshow(S2 / S0) plt.colorbar()
if ffc in ['Y', 'y', 'Yes', 'yes', 'YES']: print('Initiating FFC') cam.do_ffc() #Ask user how many images and at what intervals num = int(input('How many images to take? \n')) wait = float(input('How long to wait between images [s]? \n')) #ask for the file name and path path = input('What is the filepath? \n') if os.path.exists(path): print('\n saving data to ', path) else: print('path not found, closing camera') cam.close() name = input('What is the file name? \n') + '.h5.' user_notes = input('User Notes: \n') #preallocate file size images = np.zeros((num, 256, 320)) temps = np.zeros((num)) for i in range(num): images[i, :, :] = cam.grab(device_id=1) temps[i] = cam.get_fpa_temperature() print('on image ', str(i + 1), ' of ', str(num)) time.sleep(wait) cam.close()
from flirpy.camera.boson import Boson c = Boson(port="COM14") c.grab() c2 = Boson(port="COM17") c2.grab() c.close()
def test_open_boson(): camera = Boson() camera.close()