def uiTest(): app = QtWidgets.QApplication(sys.argv) main_window = QtWidgets.QMainWindow() playback_manager = PlaybackManager(app, main_window) # playback_manager.openTestFile() fish_manager = FishManager(None, None) fish_manager.testPopulate(500) #info_w = InfoWidget(playback_manager, fish_manager) fish_list = FishList(fish_manager, playback_manager) main_window.setCentralWidget(fish_list) main_window.show() sys.exit(app.exec_())
def loadTest(): app = QtWidgets.QApplication(sys.argv) main_window = QtWidgets.QMainWindow() playback_manager = PlaybackManager(app, main_window) fish_manager = FishManager(None, None) file = playback_manager.selectLoadFile() fish_manager.loadFromFile(file) fish_list = FishList(fish_manager, playback_manager) main_window.setCentralWidget(fish_list) main_window.show() sys.exit(app.exec_())
def saveTest(): def startDetector(): detector.initMOG() detector.computeAll() tracker.trackAll(detector.detections) app = QtWidgets.QApplication(sys.argv) main_window = QtWidgets.QMainWindow() playback_manager = PlaybackManager(app, main_window) detector = Detector(playback_manager) tracker = Tracker(detector) fish_manager = FishManager(playback_manager, tracker) save_manager = SaveManager(playback_manager, detector, tracker, fish_manager) fish_manager.updateContentsSignal.connect( lambda: save_manager.saveFile(path, True)) playback_manager.openTestFile() detector._show_detections = True playback_manager.mapping_done.connect(startDetector) main_window.show() sys.exit(app.exec_())
def launch_ui(): app = QtWidgets.QApplication(sys.argv) main_window = MainWindow() #QtWidgets.QMainWindow() playback_manager = PlaybackManager(app, main_window) detector = Detector(playback_manager) tracker = Tracker(detector) fish_manager = FishManager(playback_manager, tracker) save_manager = SaveManager(playback_manager, detector, tracker, fish_manager) detector.all_computed_event.append(playback_manager.refreshFrame) tracker.all_computed_signal.connect(playback_manager.refreshFrame) playback_manager.mapping_done.connect( lambda: playback_manager.runInThread(lambda: detector.initMOG(False))) playback_manager.frame_available_early.connect(detector.compute_from_event) playback_manager.file_opened.connect(lambda x: fish_manager.clear()) playback_manager.file_opened.connect(lambda x: detector.clearDetections()) ui_manager = UIManager(main_window, playback_manager, detector, tracker, fish_manager, save_manager) sys.exit(app.exec_())
def __init__(self, app, display, file, save_directory, connection=None, testFile=False): super().__init__() self.app = app self.display = display self.figure = None self.file = file self.save_directory = os.path.abspath(save_directory) self.connection = connection self.testFile = testFile self.alive = True self.save_detections = True self.save_tracks = True if display: self.main_window = QtWidgets.QMainWindow() else: self.main_window = None self.playback_manager = PlaybackManager(self.app, self.main_window) self.detector = Detector(self.playback_manager) self.tracker = Tracker(self.detector) self.fish_manager = FishManager(self.playback_manager, self.tracker) self.playback_manager.fps = 100 self.playback_manager.runInThread(self.listenConnection) log = LogObject() log.disconnectDefault() #log.connect(writeToFile) log.connect(self.writeToConnection) log.print("Process created for file: ", self.file)
def loadTest(): app = QtWidgets.QApplication(sys.argv) main_window = QtWidgets.QMainWindow() playback_manager = PlaybackManager(app, main_window) detector = Detector(playback_manager) tracker = Tracker(detector) fish_manager = FishManager(playback_manager, tracker) save_manager = SaveManager(playback_manager, detector, tracker, fish_manager) save_manager.loadFile(path) main_window.show() sys.exit(app.exec_())
def dataTest(): def startDetector(): detector.initMOG() detector.computeAll() tracker.trackAll(detector.detections) app = QtWidgets.QApplication(sys.argv) main_window = Window() playback_manager = PlaybackManager(app, main_window) detector = Detector(playback_manager) tracker = Tracker(detector) fish_manager = FishManager(playback_manager, tracker) fish_list = FishList(fish_manager, playback_manager) playback_manager.openTestFile() detector.mog_parameters.nof_bg_frames = 500 detector._show_detections = True playback_manager.mapping_done.connect(startDetector) main_window.setCentralWidget(fish_list) main_window.show() sys.exit(app.exec_())
self.FWdigetLayout.addStretch() self.FWdiget.setLayout(self.FWdigetLayout) self.listItem.setSizeHint(self.FWdiget.sizeHint()) if __name__ == "__main__": import sys from playback_manager import PlaybackManager def startDetector(): detector.initMOG() detector.setShowDetections(True) def test(): LogObject().print("Polars loaded test print") app = QtWidgets.QApplication(sys.argv) main_window = QtWidgets.QMainWindow() playback_manager = PlaybackManager(app, main_window) detector = Detector(playback_manager) detector.nof_bg_frames = 100 tracker = Tracker(detector) fish_manager = FishManager(playback_manager, tracker) playback_manager.mapping_done.connect(test) playback_manager.mapping_done.connect(startDetector) playback_manager.frame_available_early.connect(detector.compute_from_event) sonar_viewer = SonarViewer(main_window, playback_manager, detector, tracker, fish_manager) main_window.setCentralWidget(sonar_viewer) main_window.show() playback_manager.openTestFile() sys.exit(app.exec_())
self.fish_manager.setShowEchogramFish(value) self.playback_manager.refreshFrame() def toggleMeasureBtn(self, value): if self.measure_btn.isChecked() == value: self.measure_btn.toggle() if __name__ == "__main__": import sys from playback_manager import PlaybackManager from fish_manager import FishManager from detector import Detector from tracker import Tracker app = QtWidgets.QApplication(sys.argv) main_window = QtWidgets.QMainWindow() playback_manager = PlaybackManager(app, main_window) #playback_manager.openTestFile() fish_manager = FishManager(None, None) #fish_manager.testPopulate(100) #info_w = InfoWidget(playback_manager, fish_manager) sonar_processor = ImageProcessor() detector = Detector(playback_manager) tracker = Tracker(detector) parameter_list = ParameterList(playback_manager, sonar_processor, None, fish_manager, detector, tracker) main_window.setCentralWidget(parameter_list) main_window.show() sys.exit(app.exec_())
import sys from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QApplication, QMainWindow, QGraphicsScene, QGraphicsView from fish_manager import FishManager WIDTH = 1600 HEIGHT = 800 app = QApplication(sys.argv) w = QMainWindow() w.setWindowTitle("Poissons Rouges") w.setFixedSize(WIDTH, HEIGHT) scene = QGraphicsScene() scene.setSceneRect(0, 0, WIDTH, HEIGHT) view = QGraphicsView(scene) view.setFixedSize(WIDTH, HEIGHT) view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) w.setCentralWidget(view) w.show() quentin = FishManager(scene) app.exec()
class TrackProcess(QtCore.QObject): """ TrackProcess launches individual PlaybackManager, Detector and Tracker, separate from the ones associated with the UI. These are used for the tracking process of the file provided in the track method. Each file are intended to be processed with their own TrackProcess instances. """ exit_signal = QtCore.pyqtSignal() def __init__(self, app, display, file, save_directory, connection=None, testFile=False): super().__init__() self.app = app self.display = display self.figure = None self.file = file self.save_directory = os.path.abspath(save_directory) self.connection = connection self.testFile = testFile self.alive = True self.save_detections = True self.save_tracks = True if display: self.main_window = QtWidgets.QMainWindow() else: self.main_window = None self.playback_manager = PlaybackManager(self.app, self.main_window) self.detector = Detector(self.playback_manager) self.tracker = Tracker(self.detector) self.fish_manager = FishManager(self.playback_manager, self.tracker) self.playback_manager.fps = 100 self.playback_manager.runInThread(self.listenConnection) log = LogObject() log.disconnectDefault() #log.connect(writeToFile) log.connect(self.writeToConnection) log.print("Process created for file: ", self.file) def writeToConnection(self, value): if self.connection: self.connection.send(value) def forwardImage(self, tuple): """ Default function for forwarding the image, does not visualize the result. """ ind, frame = tuple detections = self.detector.getDetection(ind) def forwardImageDisplay(self, tuple): """ If the progress is visualized, this is used to forward the image. """ ind, frame = tuple detections = self.detector.getDetection(ind) image = cv2.applyColorMap(frame, cv2.COLORMAP_OCEAN) image = self.tracker.visualize(image, ind) self.figure.displayImage((ind, image)) def startTrackingProcess(self): """ Initiates detecting and tracking. Called from an event (mapping_done) when the playback_manager is ready to feed frames. """ self.detector.initMOG() self.detector.computeAll() self.tracker.trackAll(self.detector.detections) if self.display: self.playback_manager.play() def track(self): """ Handles the tracking process. Opens file and connects detection and tracking calls to the appropriate signals, so that they can be started when the file has been loaded. """ if self.testFile: self.playback_manager.openTestFile() else: self.playback_manager.loadFile(self.file) LogObject().print("Frame count:", self.playback_manager.getFrameCount()) if self.display: self.playback_manager.frame_available.connect( self.forwardImageDisplay) else: self.playback_manager.frame_available.connect(self.forwardImage) self.detector.mog_parameters.nof_bg_frames = 500 self.detector._show_detections = True self.playback_manager.mapping_done.connect(self.startTrackingProcess) self.tracker.all_computed_signal.connect(self.onAllComputed) if self.display: self.figure = TestFigure(self.playback_manager.togglePlay) self.main_window.setCentralWidget(self.figure) LogObject().print(self.detector.parameters) LogObject().print(self.detector.parameters.mog_parameters) LogObject().print(self.tracker.parameters) if self.display: self.main_window.show() def listenConnection(self): """ Listens the connection for messages. Currently, only terminate message (-1) is supported, but others should be easy to add when needed. """ while self.alive: if self.connection.poll(): id, msg = self.connection.recv() if id == -1: self.connection.send((-1, "Terminating")) self.quit() else: time.sleep(0.5) def getSaveFilePath(self, end_string): """ Formats the save file path. Detections and tracks are separated based on end_string. """ base_name = os.path.basename(self.file) file_name = os.path.splitext(base_name)[0] file_path = os.path.join(self.save_directory, "{}_{}".format(file_name, end_string)) return file_path def saveResults(self): """ Saves both detections and tracks to the directory provided earlier. """ file_name = os.path.splitext(self.file)[0] if self.save_detections: det_path = self.getSaveFilePath("dets.txt") self.detector.saveDetectionsToFile(det_path) if self.save_tracks: track_path = self.getSaveFilePath("tracks.txt") self.fish_manager.saveToFile(track_path) def onAllComputed(self): """ Saves and quits the process. """ self.saveResults() self.quit() def quit(self): self.alive = False self.app.quit()