sgoldenlab / simba

SimBA (Simple Behavioral Analysis), a pipeline and GUI for developing supervised behavioral classifiers
https://simba-uw-tf-dev.readthedocs.io/
GNU General Public License v3.0
287 stars 140 forks source link

Remapping keyboard shortcuts for behavior annotation. #371

Open hdsliu opened 2 months ago

hdsliu commented 2 months ago

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] The keyboard shortcuts for video navigation when annotating behaviors make little sense. Describe the solution you'd like A clear and concise description of what you want to happen. Add a setting that allow us to change the shortcuts. Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered. A guide on how to change the package/code so I can do it without using the GUI. Additional context Add any other context or screenshots about the feature request here.

sronilsson commented 2 months ago

Thanks @hdsliu - one possibility to start, is that I can change it to read in the keyboard shortcuts from a text file that comes with SimBA, and then you can change that text file to change the shortcuts. I can include a few comment examples in the text file for how you can change it. Would that work?

hdsliu commented 2 months ago

@sronilsson , that sounds exactly like what I wanted. Thank you!

sronilsson commented 2 months ago

Thanks @hdsliu - I appreciate the help.

I will try to insert the update within the next couple of days and get back to you.

Just a PS .. if you prefer to use a dedicated annotation tool like Ethovision or BORIS which may be easier for annotating for longer times, might be worth going for that and I can help if any issues.

sronilsson commented 2 months ago

@hdsliu

If you update simba though pip with pip install simba-uw-tf-dev --upgrade there will be a function in simba.utils.lookups called get_labelling_img_kbd_bindings, you can see it HERE

The top looks like this:

{'frame+1': # MOVE FORWARD 1 FRAME
             {'label': 'Right Arrow = +1 frame',
              'kbd': "<Right>"},
         'frame-1': # MOVE BACK 1 FRAME
             {'label': 'Left Arrow = -1 frame',
              'kbd': "<Left>"},
         'save': # SAVE CURRENT ANNOTATIONS STATS TO DISK
             {'label': 'Ctrl + s = Save annotations file',
              'kbd': "<Control-s>"},
....

You can change the keyboard shortcut by changing the kbd value to whatever e.g., 'kbd': "" -> 'kbd': "".I did stick some examples in the docstring.

Some notes:

i) You can't insert completely new keyboard shortcut functions - let me know if you think something should be added and we can include it.

ii) I opted for this instead of creating a new file listing the bindings, if you think its better to list it in a specific file let me know and we can do that instead.

hdsliu commented 1 month ago

Hi @sronilsson thanks for the change. I see that the instructions you made are for frame navigations. Is there a similar file for video navigation that I can change in the same way?

sronilsson commented 1 month ago

Thanks @hdsliu - good point! I will insert that too and let you know. Did the keyword mapping for the frames work OK?

hdsliu commented 1 month ago

@sronilsson Yes the mapping for frames works perfectly.

sronilsson commented 1 month ago

@sronilsson Yes the mapping for frames works perfectly.

Thanks then I will use the same method.

sronilsson commented 1 month ago

@hdsliu - I have added the customizable keys for the video in the labelling in version 2.0,1 - you can find them in simba.lookups.get_labelling_video_kbd_bindings:

def get_labelling_video_kbd_bindings() -> dict:
    """
    Returns dictionary of OpenCV keyboard bindings.

    .. note::
        Change ``kbd`` values to change keyboard shortcuts. Note that OpenCV keyboard bindings are different from tkinter
        keyboard bindings as used in ``get_labelling_img_kbd_bindings``.

        Use either letters as below, or integer ASCII code for non-letters. For example:
            - Space bar: 32
            - Left arrow: 81
            - Right arrow: 83

        e.g., {'Pause/Play': {'label': 'p = Pause/Play', 'kbd': 32} would remap the space-bar to pause.

    """

    return \
        {'Pause/Play': #
             {'label': 'p = Pause/Play',
              'kbd': 32},
         'forward_two_frames':  #
             {'label': 'o = +2 frames',
              'kbd': "o"},
         'forward_ten_frames':  #
             {'label': 'e = +10 frames',
              'kbd': "e"},
         'forward_one_second':  #
             {'label': 'w = +1 second',
              'kbd': "w"},
         'backwards_two_frames':  #
             {'label': 't = -2 frames',
              'kbd': "t"},
         'backwards_ten_frames':  #
             {'label': 's = -10 frames',
              'kbd': "s"},
         'backwards_one_second':  #
             {'label': 'x = -1 second',
              'kbd': "x"},
         'close_window':  #
             {'label': 'q = Close video window',
              'kbd': "q"},
         }

See the note, these keyboard binding are for OpenCV rather than tkinter, so uses ASCII codes for non-numerical shortcuts. So, for example, if you want to pause with space, set the kbd = 32.

PS. I have seen the other issue with the cumulative features. Have not had time to look at it yet but will ASAP.