Skip to content

Commit

Permalink
testing in flir is now working.
Browse files Browse the repository at this point in the history
  • Loading branch information
hoodjd committed Feb 12, 2021
1 parent 1c8918c commit c1adf85
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 7 deletions.
Binary file modified flir_repo/flir/__pycache__/driver.cpython-38.pyc
Binary file not shown.
12 changes: 5 additions & 7 deletions flir_repo/flir/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def await_trigger(self, EXPOSURE_TIME):

def convert_image(self,num_of_im):
# try:
# Acquire images
# Acquire images. Output is python list of images as numpy arrays
images=[]
for i in range(num_of_im):
print("Before GetNextImage")
Expand Down Expand Up @@ -195,12 +195,10 @@ def save_image(self, imagearray):#,image_1, image_2):
print("Error in save_image(), try restarting artiq")

def reset(self):
self.cam_1.DeInit()
self.cam_1.EndAcquisition()
del self.cam
self.cam_list.Clear()
PySpin.System.CloseInstance()

cam_1.EndAcquisition()
cam_1.DeInit()
del cam_1
cam_list.Clear()


#####################################################################
Expand Down
187 changes: 187 additions & 0 deletions flir_repo/flir/testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
# -*- coding: utf-8 -*-
"""
Created on Fri Feb 12 09:23:31 2021
@author: ho
"""

#%%
import matplotlib.pyplot as plt
import driver
t = driver.FLIR()

#%%

t.await_trigger(int(50))

output = t.convert_image(1)
img = output[0]



plt.imshow(img)

t.reset()


#%% Import libraries
import math
import logging
import asyncio
import asyncserial
import os
import matplotlib.pyplot as plt
import keyboard
import time
import PySpin
import sys
import time
import numpy as np
from PIL import Image



#%% Initialize camera
# Set camera serial numbers
serial_1 = '20343286' # abs camera
#serial_2 = '20409335'# fluorescence camera

# Get system
system = PySpin.System.GetInstance()

# Get camera list
cam_list = system.GetCameras()

# Get cameras by serial
cam = cam_list.GetBySerial(serial_1)

# Initialize cameras
cam.Init()

#cam.FactoryReset()

# Set acquisition mode to acquire a single frame, this ensures acquired images are sync'd since camera 2 and 3 are setup to be triggered
cam.AcquisitionMode.SetValue(PySpin.AcquisitionMode_Continuous)
cam.ExposureAuto.SetValue(PySpin.ExposureAuto_Off)
cam.ExposureMode.SetValue(PySpin.ExposureMode_Timed) #Timed or TriggerWidth (must comment out trigger parameters other that Line)
cam.ExposureTime.SetValue(100) #us
cam.GainAuto.SetValue(PySpin.GainAuto_Off)
cam.Gain.SetValue(23.8)

#cam.Gamma.SetValue(GAMMA_VALUE) #always fails?
#cam.AdcBitDepth.SetValue(PySpin.AdcBitDepth_Bit16) #always fails?

cam.PixelFormat.SetValue(PySpin.PixelFormat_Mono16)
cam.Width.SetValue(1288)
cam.Height.SetValue(964)
# cam.OffsetX.SetValue(WIDTH_OFFSET)
# cam.OffsetY.SetValue(HEIGHT_OFFSET)

#This takes an image quickly. The first image is always corrupt for whatever reason. This picture is not saved.
#cam.BeginAcquisition()
#cam.EndAcquisition()

cam.V3_3Enable.SetValue(True)
cam.TriggerMode.SetValue(PySpin.TriggerMode_Off)
cam.TriggerSource.SetValue(PySpin.TriggerSource_Line0)
cam.TriggerMode.SetValue(PySpin.TriggerMode_On)

cam.TriggerSelector.SetValue(1) #0,1 PySpin.TriggerSelector_FrameStart
cam.TriggerActivation.SetValue(PySpin.TriggerActivation_RisingEdge)



print("FLIR driver initialization successful...")

#%% Begin Acquisition
#cam.TriggerMode.SetValue(PySpin.TriggerMode_Off)
cam.ExposureTime.SetValue(int(50)) #min value 49.2us

cam.BeginAcquisition()


#%% Get Images
num_of_im = 1
images=[]
for i in range(num_of_im):
print("Before GetNextImage")
#print('num images in use',cam.GetNumImagesInUse())
#print('data streams', cam.GetNumDataStreams())
image = cam.GetNextImage(5000) #timeout (ms) 10000
#print('num images in use',cam.GetNumImagesInUse())
#print('data streams', cam.GetNumDataStreams())
print(image.IsIncomplete())
print("Picture Successfully taken at: ",time.strftime("%d %b %Y %H:%M:%S", time.localtime()))
images.append(np.array(image.GetData(),dtype="uint16").reshape((image.GetHeight(),image.GetWidth()))) #convert PySpin ImagePtr into numpy array
image.Release()
#print('num images in use', cam.GetNumImagesInUse())
#print('data streams', cam.GetNumDataStreams())

#% Plot image
for i in range(num_of_im):
img = images[i]
print( np.amax(img) , np.amin(img) )
plt.imshow(img)
plt.colorbar()
plt.show()



#%%
cam.EndAcquisition()

#%%
f = plt.figure()


#%% Close camera
try:
cam.EndAcquisition()
except:
pass

cam.DeInit()
del cam
cam_list.Clear()
#system.ReleaseInstance()




#%% Testing



cam.FactoryReset()
cam.FileAccessBuffer()
'ExposureActiveMode',
'ExposureAuto',
'ExposureMode',
'ExposureTime',
'ExposureTimeMode',
'ExposureTimeSelector',
'Gain',
'GainAuto',
'GainAutoBalance',
'GainSelector',
'Gamma',
'GammaEnable',
'GetNextImage',
print(cam.GetUserBufferCount()) #user buffer is not image buffer
print(cam.GetUserBufferSize)
print(cam.GetUserBufferTotalSize)
'Init',
'IsInitialized',
'IsStreaming',

'TriggerEventTest',
'V3_3Enable',

cam.TriggerMode.SetValue(PySpin.TriggerMode_Off)
cam.TriggerSource.SetValue(PySpin.TriggerSource_Line0)
cam.TriggerSelector.SetValue(PySpin.TriggerSelector_FrameStart)
cam.TriggerActivation.SetValue(PySpin.TriggerActivation_RisingEdge)
cam.TriggerMode.SetValue(PySpin.TriggerMode_On)

PayloadSize
TransferQueueCurrentBlockCount

0 comments on commit c1adf85

Please sign in to comment.