-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
192 additions
and
7 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |