Commit d66fceff authored by Andy Regensky's avatar Andy Regensky
Browse files

Implement preliminary background processing for perspective interpolation

parent ab06e8e3
import json
from PySide2.QtCore import QObject, Signal
from PySide2.QtCore import QObject, Signal, QThreadPool
import numpy as np
import imageio
from fishui import projections
from fishui import coordinate_conversion
from fishui.Worker import Worker
class MainViewModel(QObject):
......@@ -58,6 +59,7 @@ class MainViewModel(QObject):
self.updateProjections()
# Background images
self.threadpool = QThreadPool(self)
self._fisheye_images = []
self._perspective_images = []
self._current_idx = 0
......@@ -88,7 +90,7 @@ class MainViewModel(QObject):
raise Exception("Calibration file argument is valid for calibrated projection only.")
self.projection_key = projection_key
self.updateProjections()
self.updatePerspectiveImages()
self.updatePerspectiveImagesAsync()
def setOrigin(self, origin):
self.origin = origin
......@@ -264,7 +266,7 @@ class MainViewModel(QObject):
self._fisheye_images = images
self._current_idx = 0
self.blockSignals(True)
self.updatePerspectiveImages()
self.updatePerspectiveImagesAsync()
self.blockSignals(False)
self.didChange.emit()
......@@ -289,14 +291,20 @@ class MainViewModel(QObject):
return self._perspective_images[self._current_idx % len(self._perspective_images)][
self.perspective_scale - 1]
def updatePerspectiveImagesAsync(self):
worker = Worker(self.updatePerspectiveImages)
self.threadpool.start(worker)
def updatePerspectiveImages(self):
self._perspective_images = []
perspective_images = []
for fisheye_image in self._fisheye_images:
image = imageio.imread(fisheye_image)
scale_images = []
for scale in range(1, 11):
scale_images.append(self.interpolatePerspectiveImage(image, scale))
self._perspective_images.append(scale_images)
perspective_images.append(scale_images)
self._perspective_images = perspective_images
self.didChange.emit()
def interpolatePerspectiveImage(self, fisheye_image, scale):
......
from PySide2.QtCore import QObject, QRunnable, Slot, Signal
class Worker(QRunnable):
"""Worker thread for running background tasks."""
def __init__(self, fn, *args, **kwargs):
super().__init__()
# Store constructor arguments (re-used for processing)
self.fn = fn
self.args = args
self.kwargs = kwargs
self.signals = WorkerSignals()
@Slot()
def run(self):
result = self.fn(
*self.args, **self.kwargs,
)
self.signals.result.emit(result)
self.signals.finished.emit()
class WorkerSignals(QObject):
"""
Defines the signals available from a running worker thread.
Supported signals are:
finished
No data
error
`tuple` (exctype, value, traceback.format_exc() )
result
`object` data returned from processing, anything
"""
finished = Signal()
error = Signal(tuple)
result = Signal(object)
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