Newer
Older
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import android.media.AudioManager;
import android.media.ToneGenerator;
import android.util.Log;
import uy.edu.fing.chesstrack.communication.Client;
private static final String TAG = "CHESSTRACK::MANAGER";
private static final int ARMANDO_TABLERO = 0;
private static final int JUGANDO = 1;
private static final int OK = 1;
private static final int NOT = 0;
private static final String WELCOME_MSG = ""
+ "--------------------------------------------------------------------------\n"
+ " .:: CHESSTRACK ::. seguimiento de una partida de Ajedrez\n"
+ "\n"
+ " TImag 2014\n"
+ " Nicolas Furquez - Aylen Ricca\n"
+ "--------------------------------------------------------------------------\n";
private static int _salida;
private static Adquisicion _adquisicion;
private static Client _client;
private boolean _debug;
_estado = ARMANDO_TABLERO;
_salida = NOT;
_adquisicion = null;
_client = null;
_debug = true;
}
public static Manager getInstance() {
if (_instance == null) {
_instance = new Manager();
}
return _instance;
}
public static int get_estado() {
return _estado;
}
public static void set_estado(int _estado) {
Manager._estado = _estado;
}
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
public void setConnection(String ip, int port) {
Log.i(TAG, "Setting connection");
_client = Client.getInstance();
_client.EstablishConnection(ip, port);
_client.SendData(WELCOME_MSG);
_salida = OK;
}
public Mat processFrame(Mat inputFrame) {
Log.i(TAG, "Acondicionamiento");
Mat region = _adquisicion.processFrame(inputFrame);
Log.i(TAG, "TYPE=" + (inputFrame.type()==CvType.CV_8UC4));
Log.i(TAG, "CHANNEL=" + (inputFrame.channels()==4));
switch (_estado) {
case ARMANDO_TABLERO:
Log.i(TAG, "Armando Tablero");
// respuesta: {PRONTO - NOPRONTO}
// SI pornto --> beep + estado JUGANDO
// SINO --> nada
// Modelador -> genera la imagen 0-1 y se la pasa al manager
// Modelador.Validar
//
// cuando paso a estado jugando mando al socket si salida==OK
break;
case JUGANDO:
Log.i(TAG, "Jugando");
// respuesta: {MANO - NO MANO}
// SI mano --> nada
// SINO matriz-0-1
// BackgoundSupress -> busca la mano y retorna si o no
// Modelador -> genera la imagen 0-1 y se la pasa al manager
// mando al cliente la MATRIZ !!
break;
}
if (_debug) {
Mat tmp = Mat.zeros(inputFrame.size(), CvType.CV_8UC4);
Mat matTMP = tmp.submat(Calibracion.getRectROI());
region.copyTo(matTMP);
return tmp;
}
return inputFrame;
}
public boolean calibrar(Mat frame) {
Log.i(TAG, "Calibrando");
if (Calibracion.getInstance().calibrar(frame)) {
ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_ALARM,
50);
toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 200); // ms
if (_salida == OK) {
_client.SendData("FIN calibrar\n . . . armando tablero!");
}
try {
_adquisicion = new Adquisicion();
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
Log.i(TAG, "No calibrado");
ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_ALARM, 50);
toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 700);
return false;
}
public void destroy() {
if (_client != null) {
_client.Stop();
}
}