001package org.openimaj.demos.sandbox.tldcpp.videotld;
002
003import java.awt.event.KeyEvent;
004import java.awt.event.KeyListener;
005
006public class TLDKeyListener implements KeyListener {
007        private TLDMain tldMain;
008
009        public TLDKeyListener(TLDMain tldMain) {
010                this.tldMain = tldMain;
011        }
012
013        @Override
014        public void keyTyped(KeyEvent e) {
015                handle(e.getKeyChar());
016        }
017
018        private void handle(char key) {
019                if (key == 'q') {
020                        System.exit(0);
021                }
022
023                if (key == 'b') {
024
025                        // ForegroundDetector* fg = tld.detectorCascade.foregroundDetector;
026                        //
027                        // if(fg.bgImg.empty()) {
028                        // fg.bgImg = cvCloneImage(grey);
029                        // } else {
030                        // fg.bgImg.release();
031                        // }
032                }
033
034                if (key == 'c') {
035                        tldMain.queueClear();
036                }
037
038                if (key == 'l') {
039                        tldMain.toggleLearning();
040                        // tld.learningEnabled = !tld.learningEnabled;
041                        // System.out.printf("LearningEnabled: %d\n", tld.learningEnabled);
042                }
043
044                if (key == 'a') {
045                        tldMain.toggleAlternating();
046                        // tld.alternating = !tld.alternating;
047                        // System.out.printf("alternating: %d\n", tld.alternating);
048                }
049
050                if (key == 'e') {
051                        // tld.writeToFile(modelExportFile);
052                }
053
054                if (key == 'i') {
055                        // tld.readFromFile(modelPath);
056                }
057
058                if (key == 'r') {
059                        tldMain.initiateObjectSelect();
060                }
061                if (key == 'm') {
062                        tldMain.toggleMarkerMode();
063                }
064        }
065
066        @Override
067        public void keyPressed(KeyEvent e) {
068                // TODO Auto-generated method stub
069
070        }
071
072        @Override
073        public void keyReleased(KeyEvent e) {
074                // TODO Auto-generated method stub
075
076        }
077
078}