Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flir camera adaptor #172

Merged
merged 30 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e3b9ed3
Adding directory for flir camera adapter
aduran-cz Jun 12, 2023
82fe142
Adding snap() and multiple() methods to get a single and multiple ima…
aduran-cz Jun 15, 2023
aae2cdc
adding demo
aduran-cz Jun 16, 2023
2d98189
correcting demo
aduran-cz Jun 16, 2023
016327e
implementing decorators as exception handlers
aduran-cz Jun 20, 2023
77bbb93
adding gain methods
aduran-cz Jun 21, 2023
01d259d
initialize camera as a class attribute, make all methods member metho…
aduran-cz Jun 22, 2023
4adbe47
removing decorators as exception handlers
aduran-cz Jun 22, 2023
8fdcf60
add instance attributes as properties. Add close() method to close th…
aduran-cz Jun 23, 2023
8b03208
fixed camera initialization bugs for exposure settings
aduran-cz Jun 25, 2023
6b7fb4c
fixed camera initialization bugs for exposure settings
aduran-cz Jun 25, 2023
571ecdd
demos for exposure, gain, framerate methods
aduran-cz Jun 25, 2023
83193ba
correct gain, frame rate demos
aduran-cz Jun 25, 2023
11a2e53
add method placeholders. add list_available_cameras
aduran-cz Jun 25, 2023
6a423cb
add method placeholders. add list_available_cameras
aduran-cz Jun 25, 2023
938039f
correct frame rate demos
aduran-cz Jun 25, 2023
1834351
adding open() and close() methods. Manage camera pointer as an instan…
aduran-cz Jun 29, 2023
fdd7ea0
adding device_id, nodemap properties. deleting repetitive code
aduran-cz Jun 29, 2023
c190a96
adding image_size method and remaining placeholders
aduran-cz Jun 29, 2023
3cc7162
adding binning() method. adding errors to settings outside of limits
aduran-cz Jun 30, 2023
648ed5e
Fixing buffer initialization bug. Adding explicit option to take mult…
aduran-cz Jul 6, 2023
2678631
removing whitespace
aduran-cz Jul 6, 2023
0697db6
changing return type of image acquisition methods: return intensity a…
aduran-cz Jul 7, 2023
827a9c5
changing return type of image acquisition methods: return intensity a…
aduran-cz Jul 7, 2023
9cbc482
adding a new save() method. Completing docstrings and demo
aduran-cz Jul 8, 2023
670795b
adding assert statements, changing variable names
aduran-cz Jul 20, 2023
b2b84ab
change docstrings to numpy style. join run_single_camera() and snap()…
aduran-cz Jul 20, 2023
40ff215
fix method to save to png, tif with openCV
aduran-cz Jul 21, 2023
e471c4b
save images with skimage. remove todos
aduran-cz Jul 24, 2023
fed84eb
adding viewer and demo for implementing snap() in flir camera
aduran-cz Jul 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions copylot/gui/viewer/demo/demo_flir_camera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from copylot.gui.viewer.viewer import Viewer
from copylot.hardware.cameras.flir.flir_camera import FlirCamera
import numpy as np

# create camera object
cam = FlirCamera()
# open the system
cam.open()


# 2 ways to stream in viewer
# FIRST OPTION: cycle one by one

# function to take and stack an image
def snap_mono(c: FlirCamera):
snap = c.snap()
return np.stack((snap, snap, snap), axis=2)


# create initial blank (placeholder) image
init_im = snap_mono(cam)

# create vispy canvas with initial image
view1 = Viewer(init_im)

for i in range(5):
im = snap_mono(cam)
view1.update(im)
view1.process() # introduces a delay between snapping the images

# run the vispy event loop
view1.run()

# SECOND OPTION: get all images and then cycle them through the viewer
# create vispy canvas with initial image
view2 = Viewer(init_im)

ims = cam.snap(10)
for i in range(10):
ima = np.stack((ims[i], ims[i], ims[i]), axis=2)
view2.update(ima)
view2.process()

view2.run()

cam.close()
38 changes: 37 additions & 1 deletion copylot/gui/viewer/viewer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import numpy as np
from vispy import scene
from vispy import app

Expand Down Expand Up @@ -28,8 +29,43 @@ def __init__(self, img_data=None):
self.view.camera.set_range()
self.view.camera.zoom(1, (250, 200))

def run(self):
# set parameters for contrast
self.img_data = img_data
self._contrast_limits = None
self.update_freq = 0

@staticmethod
def run():
"""
Start the vispy event loop
"""
app.run()

@staticmethod
def process():
"""
Update the vispy event loop
"""
app.process_events()

def update(self, data):
"""
Update the data layer of the image in the current viewbox

Parameters
----------
data: ndarray of the new image to be shown
"""
# input new image data
self.image.set_data(data)
# update the SceneCanvas object
self.canvas.update()

@property
def contrast_limits(self):
return self._contrast_limits

@contrast_limits.setter
def contrast_limits(self, factor):
# TODO: get tuple as argument, use vispy clim
pass
Empty file.
Empty file.
66 changes: 66 additions & 0 deletions copylot/hardware/cameras/flir/demo/demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from copylot.hardware.cameras.flir.flir_camera import FlirCamera

if __name__ == '__main__':
cam = FlirCamera()

# open the system
cam.open()

# serial number
print(cam.device_id)
# list of cameras
print(cam.list_available_cameras())

# Return 10 frames and save output arrays as .csv files (this can be changed)

# Option 1: take multiple frames in a single acquisition
# Can control timeout (wait_time) for grabbing images from the camera buffer
snap1 = cam.snap(n_images=5, wait_time=1000)
cam.save_image(snap1)
# Option 2: iterate over snap()
# Saving in each iteration causes a delay between beginning/ending camera acquisition
# Could also collect the snap2 outputs and then save outside the loop to avoid delays
# (which is just what Option 1 does implicitly)
for i in range(0, 5):
snap2 = cam.snap()
cam.save_image(snap2)

# open again
cam.open()

# cam bit depth
print('Default bit depth', cam.bitdepth)
cam.bitdepth = 3
assert cam.bitdepth == 3

# cam shutter mode
print('Default shutter mode', cam.shutter_mode)
cam.shutter_mode = 'rolling'
assert cam.shutter_mode == 'rolling'

# cam binning - THERE ARE SOME SPECIFIC MULTIPLES
print('Default binsize', cam.binning)
cam.binning = (2, 2)
assert cam.binning == (2, 2)

# cam image size
print('Default image size', cam.image_size) # set to the max by default
print('Limit image size', cam.image_size_limits)
cam.image_size = (1000, 2000)
assert cam.image_size == (1000, 2000)

# cam gain methods
print('Default AutoGain', cam.gain, cam.gain_limits)
cam.gain = 0.8
assert cam.gain == 0.8

# cam exposure methods
print('Default AutoExposure', cam.exposure, cam.exposure_limits)
cam.exposure = 100.0
assert cam.exposure == 100.0

# cam frame rate methods
print('Default frame rate', cam.framerate)
# set method might be removed

cam.close()
Loading