Beispiel #1
0
    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_())
Beispiel #2
0
    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_())
Beispiel #3
0
    def defaultTest():
        app = QtWidgets.QApplication(sys.argv)
        main_window = QtWidgets.QMainWindow()
        playback_manager = PlaybackManager(app, main_window)
        playback_manager.fps = 1
        playback_manager.openTestFile()

        detector = Detector(playback_manager)
        detector.mog_parameters.nof_bg_frames = 100

        playback_manager.mapping_done.connect(
            lambda: startDetector(playback_manager, detector))
        playback_manager.frame_available.connect(
            lambda t: handleFrame(detector, t))

        data_model = DetectionDataModel(detector)
        detection_list = DetectionList(data_model)
        main_window.setCentralWidget(detection_list)
        main_window.show()
        sys.exit(app.exec_())
Beispiel #4
0
    def playbackTest():
        """
        Test code to assure tracker works with detector.
        """
        def forwardImage(tuple):
            ind, frame = tuple
            detections = detector.getDetection(ind)

            image = cv2.applyColorMap(frame, cv2.COLORMAP_OCEAN)
            image = tracker.visualize(image, ind)

            figure.displayImage((ind, image))

        def startDetector():
            detector.initMOG()
            detector.computeAll()
            tracker.trackAll(detector.detections)
            playback_manager.play()

        app = QtWidgets.QApplication(sys.argv)
        main_window = QtWidgets.QMainWindow()
        playback_manager = PlaybackManager(app, main_window)
        detector = Detector(playback_manager)
        tracker = Tracker(detector)

        playback_manager.fps = 10
        playback_manager.openTestFile()
        playback_manager.frame_available.connect(forwardImage)
        detector.mog_parameters.nof_bg_frames = 500
        detector._show_detections = True
        playback_manager.mapping_done.connect(startDetector)

        figure = TestFigure(playback_manager.togglePlay)
        main_window.setCentralWidget(figure)

        LogObject().print(detector.parameters)
        LogObject().print(detector.parameters.mog_parameters)
        LogObject().print(tracker.parameters)

        main_window.show()
        sys.exit(app.exec_())
Beispiel #5
0
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_())
Beispiel #6
0
    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_())
Beispiel #7
0
    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_())
Beispiel #8
0
    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)
Beispiel #9
0
    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_())
Beispiel #10
0
def playbackTest():
    def forwardImage(tuple):
        ind, frame = tuple
        # detections = detector.compute(ind, frame)
        detections = detector.getCurrentDetection()

        image = cv2.applyColorMap(frame, cv2.COLORMAP_OCEAN)
        image = detector.overlayDetections(image, detections)

        figure.displayImage((ind, image))

    def startDetector():
        detector.initMOG()
        playback_manager.play()

    #LogObject().disconnectDefault()
    #LogObject().connect(LogObject().defaultPrint)

    app = QtWidgets.QApplication(sys.argv)
    main_window = QtWidgets.QMainWindow()
    playback_manager = PlaybackManager(app, main_window)
    playback_manager.fps = 10
    playback_manager.openTestFile()
    playback_manager.frame_available.connect(forwardImage)
    detector = Detector(playback_manager)
    detector.mog_parameters.nof_bg_frames = 100
    detector._show_detections = True
    detector._show_echogram_detections = True
    playback_manager.mapping_done.connect(startDetector)
    playback_manager.frame_available_early.connect(detector.compute_from_event)

    figure = TestFigure(playback_manager.togglePlay)
    main_window.setCentralWidget(figure)

    main_window.show()
    sys.exit(app.exec_())
Beispiel #11
0
    def loadTest():
        app = QtWidgets.QApplication(sys.argv)
        main_window = QtWidgets.QMainWindow()
        playback_manager = PlaybackManager(app, main_window)
        playback_manager.fps = 1

        detector = Detector(playback_manager)
        detector.mog_parameters.nof_bg_frames = 100

        file = playback_manager.selectLoadFile()

        playback_manager.openTestFile()
        playback_manager.mapping_done.connect(
            lambda: startDetector(playback_manager, detector))

        detector.loadDetectionsFromFile(file)
        LogObject().print([d for d in detector.detections if d is not None])

        data_model = DetectionDataModel(detector)
        detection_list = DetectionList(data_model)
        main_window.setCentralWidget(detection_list)
        main_window.show()
        sys.exit(app.exec_())
Beispiel #12
0
            self.vertical_detections = [
                [d.center[0] for d in dets
                 if d.center is not None] if dets is not None else []
                for dets in self.detections
            ]

        def parametersDirty(self):
            return False

    class TestFishManager(QtCore.QAbstractTableModel):

        updateContentsSignal = QtCore.pyqtSignal()

        def __init__(self):
            super().__init__()
            self.show_fish = True
            self.show_echogram_fish = True

    app = QtWidgets.QApplication(sys.argv)
    main_window = QtWidgets.QMainWindow()
    playback_manager = PlaybackManager(app, main_window)
    playback_manager.openTestFile()
    detector = TestDetector(playback_manager.getFrameCount(),
                            playback_manager.sonar.samplesPerBeam)
    fish_manager = TestFishManager()
    echogram = EchogramViewer(playback_manager, detector, fish_manager)
    echogram.onFileOpen(playback_manager.sonar)
    main_window.setCentralWidget(echogram)
    main_window.show()
    main_window.resize(900, 300)
    sys.exit(app.exec_())
Beispiel #13
0
import sys
import cv2
from PyQt5 import QtCore, QtGui, QtWidgets
from playback_manager import PlaybackManager

# Save frames using playback_manager


def saveImage(tuple):
    ind, frame = tuple
    print("ASD")
    cv2.imwrite("out/frame_{:06}.png".format(ind), frame)


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    main_window = QtWidgets.QMainWindow()
    playback_manager = PlaybackManager(app, main_window)
    playback_manager.fps = 1000
    playback_manager.openTestFile()

    playback_manager.playback_thread.signals.mapping_done_signal.connect(
        lambda: playback_manager.play())
    playback_manager.frame_available.append(saveImage)

    main_window.show()
    sys.exit(app.exec_())
    #main()
Beispiel #14
0

class EmptyOrIntValidator(QtGui.QIntValidator):
    def __init__(self, *args, **kwargs):
        super(EmptyOrIntValidator, self).__init__(*args, **kwargs)

    def validate(self, text, pos):
        state, text, pos = super(EmptyOrIntValidator, self).validate(text, pos)
            
        if state != QtGui.QValidator.Acceptable and text == "":
            state = QtGui.QValidator.Acceptable
        return state, text, pos


if __name__ == "__main__":
    def showDialog():
        dialog = BatchDialog(playback_manager)
        dialog.exec_()

    app = QtWidgets.QApplication(sys.argv)
    w = QtWidgets.QMainWindow()
    playback_manager = PlaybackManager(app, w)

    b = QtWidgets.QPushButton(w)
    b.setText("Show dialog")
    b.move(50,50)
    b.clicked.connect(showDialog)
    w.setWindowTitle("BatcDialog test")
    w.show()
    showDialog()
    sys.exit(app.exec_())
Beispiel #15
0
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()
Beispiel #16
0
        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_())
Beispiel #17
0
        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_())