Пример #1
0
def demo_confmaps(confmaps,
                  video,
                  scale=None,
                  standalone=False,
                  callback=None):
    """Demo function."""
    from PySide2 import QtWidgets
    from sleap.gui.widgets.video import QtVideoPlayer

    if standalone:
        app = QtWidgets.QApplication([])

    win = QtVideoPlayer(video=video)
    win.setWindowTitle("confmaps")
    win.show()

    def plot_confmaps(parent, frame_idx):
        if frame_idx < confmaps.shape[0]:
            frame_conf_map = ConfMapsPlot(confmaps[frame_idx, ...],
                                          show_box=not scale)
            if scale:
                frame_conf_map.setScale(scale)
            win.view.scene.addItem(frame_conf_map)

    win.changedPlot.connect(plot_confmaps)
    if callback:
        win.changedPlot.connect(callback)
    win.plot()

    if standalone:
        app.exec_()

    return win
Пример #2
0
def test_gui_conf_maps(qtbot, hdf5_confmaps):

    vp = QtVideoPlayer()
    vp.show()
    conf_maps = ConfMapsPlot(hdf5_confmaps.get_frame(1), show_box=False)
    vp.view.scene.addItem(conf_maps)

    # make sure we're showing all the channels
    assert len(conf_maps.childItems()) == 6

    assert vp.close()
Пример #3
0
def test_gui_quiver(qtbot, hdf5_affinity):

    vp = QtVideoPlayer()
    vp.show()
    affinity_fields = MultiQuiverPlot(
        frame=hdf5_affinity.get_frame(0)[265:275, 238:248],
        show=[0, 1],
        decimation=1)
    vp.view.scene.addItem(affinity_fields)

    # make sure we're showing all the channels we selected
    assert len(affinity_fields.childItems()) == 2
    # make sure we're showing all arrows in first channel
    assert len(affinity_fields.childItems()[0].points) == 480

    assert vp.close()
Пример #4
0
def demo_pafs(pafs, video, decimation=4, scale=None, standalone=False):
    from sleap.gui.widgets.video import QtVideoPlayer

    if standalone:
        app = QtWidgets.QApplication([])

    win = QtVideoPlayer(video=video)
    win.setWindowTitle("pafs")

    decimation_size_bar = QtWidgets.QSlider(QtCore.Qt.Horizontal)
    decimation_size_bar.valueChanged.connect(lambda e: win.plot())
    decimation_size_bar.setValue(decimation)
    decimation_size_bar.setMinimum(1)
    decimation_size_bar.setMaximum(10)
    decimation_size_bar.setEnabled(True)
    win.layout.addWidget(decimation_size_bar)

    win.show()

    def plot_fields(parent, frame_idx):
        if frame_idx < pafs.shape[0]:
            frame_pafs = pafs[frame_idx, ...]
            decimation = decimation_size_bar.value()
            aff_fields_item = MultiQuiverPlot(
                frame_pafs, show=None, decimation=decimation
            )
            if scale:
                aff_fields_item.setScale(scale)
            win.view.scene.addItem(aff_fields_item)

    win.changedPlot.connect(plot_fields)
    win.plot()

    if standalone:
        app.exec_()

    return win
Пример #5
0
def test_gui_video_instances(qtbot, small_robot_mp4_vid, centered_pair_labels):
    vp = QtVideoPlayer(small_robot_mp4_vid)
    qtbot.addWidget(vp)

    test_frame_idx = 63
    labeled_frames = centered_pair_labels.labeled_frames

    def plot_instances(vp, idx):
        for instance in labeled_frames[test_frame_idx].instances:
            vp.addInstance(instance=instance)

    vp.changedPlot.connect(plot_instances)
    vp.view.updatedViewer.emit()

    vp.show()
    vp.plot()

    # Check that all instances are included in viewer
    assert len(vp.instances) == len(labeled_frames[test_frame_idx].instances)

    # All instances should be selectable
    assert vp.selectable_instances == vp.instances

    vp.zoomToFit()

    # Check that we zoomed correctly
    assert vp.view.zoomFactor > 1

    vp.instances[0].updatePoints(complete=True)

    # Check that node is marked as complete
    nodes = [
        item for item in vp.instances[0].childItems()
        if hasattr(item, "point")
    ]
    assert all((node.point.complete for node in nodes))

    # Check that selection via keyboard works
    assert vp.view.getSelectionIndex() is None
    qtbot.keyClick(vp, QtCore.Qt.Key_1)
    assert vp.view.getSelectionIndex() == 0
    qtbot.keyClick(vp, QtCore.Qt.Key_2)
    assert vp.view.getSelectionIndex() == 1

    # Check that updatedSelection signal is emitted
    with qtbot.waitSignal(vp.view.updatedSelection, timeout=10):
        qtbot.keyClick(vp, QtCore.Qt.Key_1)

    # Check that selection by Instance works
    for inst in labeled_frames[test_frame_idx].instances:
        vp.view.selectInstance(inst)
        assert vp.view.getSelectionInstance() == inst

    # Check that sequence selection works
    with qtbot.waitCallback() as cb:
        vp.view.selectInstance(None)
        vp.onSequenceSelect(2, cb)
        qtbot.keyClick(vp, QtCore.Qt.Key_2)
        qtbot.keyClick(vp, QtCore.Qt.Key_1)

    inst_1 = vp.selectable_instances[1].instance
    inst_0 = vp.selectable_instances[0].instance
    assert cb.args[0] == [inst_1, inst_0]

    assert vp.close()
Пример #6
0
def test_gui_video(qtbot):
    vp = QtVideoPlayer()
    vp.show()
    qtbot.addWidget(vp)

    assert vp.close()