Skip to content
Snippets Groups Projects
Commit 3da089f0 authored by Nicolas Furquez's avatar Nicolas Furquez
Browse files

merge 2

parents fdd60c21 7eb3b3ad
No related branches found
No related tags found
No related merge requests found
Showing with 367 additions and 25 deletions
......@@ -3,8 +3,6 @@
android:versionCode="1"
android:versionName="1.0" >
<!-- <application -->
<!-- android:allowBackup="true" -->
<!-- android:icon="@drawable/ic_launcher" -->
......@@ -12,8 +10,6 @@
<!-- android:theme="@style/AppTheme" > -->
<!-- </application> -->
<application
android:allowBackup="true"
android:label="@string/app_name"
......@@ -30,22 +26,21 @@
</intent-filter>
</activity>
</application>
<supports-screens android:resizeable="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="true" />
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-feature android:name="android.hardware.camera.front" android:required="false"/>
......
package uy.edu.chesstrack.communication;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import android.util.Log;
public class Client {
private static final String TAG = "CLIENT";
private static Client _clientInstance;
private Socket serverSocket;
private int _serverPort;
private String _serverIp;
//private BufferedReader input;
private DataOutputStream output;
protected Client(){
}
public static Client getInstance(){
if(_clientInstance == null){
_clientInstance = new Client();
}
return _clientInstance;
}
public void EstablishConnection(String serverIp, int serverPort) {
Log.i(TAG, "init client-server communication");
this._serverIp = serverIp;
this._serverPort = serverPort;
try {
InetAddress serverAddr = InetAddress.getByName(this._serverIp);
serverSocket = new Socket(serverAddr, _serverPort);
Log.i(TAG, "Server on " + this._serverIp + ":" + _serverPort);
// get stream to send data
this.output = new DataOutputStream(this.serverSocket.getOutputStream());
// get stream to receive data
//this.input = new BufferedReader(new InputStreamReader(this.serverSocket.getInputStream()));
} catch (IOException e) {
e.printStackTrace();
}
}
public void SendData(String msg) {
try {
Log.i(TAG, "sending="+ msg);
this.output.writeBytes(msg);
} catch (IOException e) {
e.printStackTrace();
}
}
/*
public String ReceiveData() {
try {
String read = input.readLine();
Log.i(TAG, "received="+ read);
return read;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
*/
public void Stop() {
try {
//input.close();
output.close();
serverSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
......@@ -8,30 +8,44 @@ import org.opencv.android.JavaCameraView;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Mat;
import uy.edu.fing.chesstrack.communication.Client;
import uy.edu.fing.chesstrack.modulomodelador.Modelador;
import uy.edu.fing.chesstrack.modulovision.Adquisicion;
import uy.edu.fing.chesstrack.modulovision.Calibracion;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.media.AudioManager;
import android.media.ToneGenerator;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SurfaceView;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
public class ChessTrackActivity extends Activity implements CvCameraViewListener {
private static final String TAG = "CHESSTRACK::Activity";
private static final String IPV4_REGEX ="^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$";
private static final String PORT_REGEX ="^(\\d{4,5})$";
private static final String welcomeMSG = ""
+ "--------------------------------------------------------------------------\n"
+ " .:: CHESSTRACK ::. seguimiento de una partida de Ajedrez\n"
+ "\n"
+ " Aylen Ricca - Nicolas Furquez\n"
+ "--------------------------------------------------------------------------\n";
private CameraBridgeViewBase mOpenCvCameraView;
//private JavaCameraView mOpenCvCameraView;
private Adquisicion adq;
private Calibracion calibrar;
private Button btnCalibrar;
private Client ClientCommunication;
private MenuItem mItemCalibrar;
//TODO es chancho pero ver luego
private Mat frame;
......@@ -75,7 +89,6 @@ public class ChessTrackActivity extends Activity implements CvCameraViewListener
Modelador.getInstance();
try {
isUsed = false;
isCalibrada =false;
......@@ -83,9 +96,72 @@ public class ChessTrackActivity extends Activity implements CvCameraViewListener
// TODO Auto-generated catch block
e.printStackTrace();
}
getServerIp();
}
public void getServerIp(){
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Communication Setup");
alert.setMessage("Set server ip");
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Editable value = input.getText();
if (value == null || value.toString().equals("") || !value.toString().matches(IPV4_REGEX)) {
Log.i(TAG,"INPUT= not valid IP" + value.toString());
getServerIp();
} else {
Log.i(TAG,"INPUT=" + value.toString());
Log.i(TAG,"IP=" + value.toString());
getServerPort(value.toString());
}
}
});
/*
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// no server communication -- FIXME do not send info to client
}
});
*/
alert.show();
}
public void getServerPort(final String ip){
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Communication Setup");
alert.setMessage("Set server port");
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Editable value = input.getText();
Log.i(TAG,"INPUT=" + value.toString());
if (value == null || value.toString().equals("") || !value.toString().matches(PORT_REGEX)) {
Log.i(TAG,"INPUT= not valid PORT" + value.toString());
getServerPort(ip);
} else {
Log.i(TAG,"INPUT=" + value.toString());
int port = Integer.parseInt(value.toString());
Log.i(TAG,"PORT=" + port);
//ClientCommunication = Client.getInstance();
//ClientCommunication.EstablishConnection(ip, port);
//ClientCommunication.SendData(welcomeMSG);
}
}
});
alert.show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
Log.i(TAG, "called onCreateOptionsMenu");
......@@ -122,8 +198,6 @@ public class ChessTrackActivity extends Activity implements CvCameraViewListener
}
@Override
public void onPause()
{
......@@ -139,6 +213,9 @@ public class ChessTrackActivity extends Activity implements CvCameraViewListener
if (mOpenCvCameraView != null) {
mOpenCvCameraView.disableView();
}
if (this.ClientCommunication != null) {
this.ClientCommunication.Stop();
}
}
@Override
......
package uy.edu.fing.chesstrack.communication;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import android.util.Log;
public class Client {
private static final String TAG = "CLIENT";
private static Client _clientInstance;
private Socket serverSocket;
private int _serverPort;
private String _serverIp;
//private BufferedReader input;
private DataOutputStream output;
protected Client(){
}
public static Client getInstance(){
if(_clientInstance == null){
_clientInstance = new Client();
}
return _clientInstance;
}
public void EstablishConnection(String serverIp, int serverPort) {
Log.i(TAG, "init client-server communication");
this._serverIp = serverIp;
this._serverPort = serverPort;
try {
Log.i(TAG, "Server on " + this._serverIp + ":" + _serverPort);
InetAddress serverAddr = InetAddress.getByName(this._serverIp);
serverSocket = new Socket(serverAddr, _serverPort);
// get stream to send data
this.output = new DataOutputStream(this.serverSocket.getOutputStream());
// get stream to receive data
//this.input = new BufferedReader(new InputStreamReader(this.serverSocket.getInputStream()));
} catch (IOException e) {
e.printStackTrace();
}
}
public void SendData(String msg) {
try {
Log.i(TAG, "sending="+ msg);
this.output.writeBytes(msg);
} catch (IOException e) {
e.printStackTrace();
}
}
/*
public String ReceiveData() {
try {
String read = input.readLine();
Log.i(TAG, "received="+ read);
return read;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
*/
public void Stop() {
try {
//input.close();
output.close();
serverSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
......@@ -7,6 +7,7 @@ import java.util.List;
import org.opencv.core.Mat;
import uy.edu.fing.chesstrack.modulovision.imgproc.BackgroundSupress;
import uy.edu.fing.chesstrack.modulovision.imgproc.Homografia;
import uy.edu.fing.chesstrack.modulovision.imgproc.ImgProcInterface;
import android.util.Log;
......
......@@ -17,6 +17,7 @@ import org.opencv.video.BackgroundSubtractorMOG;
import org.opencv.video.BackgroundSubtractorMOG2;
import org.opencv.imgproc.*;
import uy.edu.fing.chesstrack.communication.Client;
import android.graphics.SumPathEffect;
import android.media.AudioManager;
import android.media.ToneGenerator;
......@@ -26,12 +27,16 @@ import android.util.Log;
public class BackgroundSupress implements ImgProcInterface {
private static final String TAG = "CHESSTRACK::BackgroundSupress";
private static int e = 0;
private final Mat fgMaskMOG;
private final Mat fgMaskMOG2;
private Mat fgMaskMOG2;
private final Mat morphKernel;
private final BackgroundSubtractorMOG pMOG;
private final BackgroundSubtractorMOG2 pMOG2;
private final List<MatOfPoint> contours;
private BackgroundSubtractorMOG2 pMOG2;
//private final List<MatOfPoint> contours;
private Client communicator;
private int estadoANTERIOR = 0;
private int estadoACTUAL = 0;
public BackgroundSupress() {
super();
......@@ -41,7 +46,9 @@ public class BackgroundSupress implements ImgProcInterface {
pMOG = new BackgroundSubtractorMOG(); //MOG approach
pMOG2 = new BackgroundSubtractorMOG2(); //MOG approach
Log.i(TAG, "at background supress constructor");
contours = new ArrayList<MatOfPoint>();
//contours = new ArrayList<MatOfPoint>();
communicator = Client.getInstance();
}
@Override
......@@ -62,8 +69,8 @@ public class BackgroundSupress implements ImgProcInterface {
Imgproc.threshold(fgMaskMOG2, fgMaskMOG2, 200, 255, Imgproc.THRESH_BINARY);
Log.i(TAG, "Apply threshold");
Imgproc.dilate(fgMaskMOG2, fgMaskMOG2, morphKernel);
Log.i(TAG, "Apply dilate");
//Imgproc.dilate(fgMaskMOG2, fgMaskMOG2, morphKernel);
//Log.i(TAG, "Apply dilate");
Scalar suma = Core.sumElems(fgMaskMOG2);
Log.i(TAG, "SUMA = " + suma);
......@@ -87,12 +94,28 @@ public class BackgroundSupress implements ImgProcInterface {
}*/
if (suma.val[0] > 100000){
estadoANTERIOR = estadoACTUAL;
estadoACTUAL = 1;
Log.i(TAG, "MANO !!!");
communicator.SendData("1\n");
Core.putText(fgMaskMOG2, "MANO !!!", new Point(50, 50),Core.FONT_HERSHEY_SIMPLEX, 0.8 , new Scalar(255,255,0));
// ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_ALARM, 50);
// toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 200); // 200 is duration in ms
} else {
estadoANTERIOR = estadoACTUAL;
if (estadoANTERIOR == 1){
// estado transicion
estadoACTUAL = 3;
}
if (estadoANTERIOR == 3){
// estado estable
estadoACTUAL = 2;
pMOG2 = new BackgroundSubtractorMOG2(); //MOG2 approach
}
Log.i(TAG, "ESTABLE !!!");
communicator.SendData("0\n");
Core.putText(fgMaskMOG2, "ESTABLE !!!", new Point(50, 50),Core.FONT_HERSHEY_SIMPLEX, 0.5 , new Scalar(255,255,0));
}
......
......@@ -57,11 +57,13 @@ public class Homografia implements ImgProcInterface {
@Override
public Mat procesarImagen(Mat inputFrame) {
Imgproc.warpPerspective(inputFrame,inputFrame, matrizTransformada, inputFrame.size(),(Imgproc.INTER_LINEAR | Imgproc.CV_WARP_FILL_OUTLIERS));
Log.i(TAG, "before");
Imgproc.warpPerspective(inputFrame,inputFrame, matrizTransformada, inputFrame.size());
Mat subMat = inputFrame.submat(rectPOI);
Mat tmp = Mat.zeros(inputFrame.size(), CvType.CV_8UC4);
Mat matTMP = tmp.submat(rectPOI);
subMat.copyTo(matTMP);
Log.i(TAG, "after");
return tmp;
}
......
import java.io.*;
import java.net.*;
class TCPClient {
public static void main(String argv[]) throws Exception
{
String sentence;
String modifiedSentence;
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new Socket("192.168.1.21", 5555);
DataOutputStream outToServer =
new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer =
new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
sentence = inFromUser.readLine();
outToServer.writeBytes(sentence + '\n');
modifiedSentence = inFromServer.readLine();
System.out.println("FROM SERVER: " + modifiedSentence);
clientSocket.close();
}
}
import java.io.*;
import java.net.*;
class TCPServer {
public static void main(String argv[]) throws Exception
{
String clientSentence;
String capitalizedSentence;
ServerSocket welcomeSocket = new ServerSocket(5556);
Socket connectionSocket = welcomeSocket.accept();
BufferedReader inFromClient =
new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient =
new DataOutputStream(connectionSocket.getOutputStream());
while(true) {
clientSentence = inFromClient.readLine();
//capitalizedSentence = clientSentence.toUpperCase() + '\n';
//outToClient.writeBytes(capitalizedSentence);
if (clientSentence != null){
System.out.println(clientSentence);
}
}
}
}
......@@ -66,7 +66,7 @@ int main(int argc, char* argv[])
//create GUI windows
namedWindow("Frame");
namedWindow("FG Mask MOG");
//namedWindow("FG Mask MOG");
namedWindow("FG Mask MOG 2");
//create Background Subtractor objects
......@@ -99,6 +99,10 @@ int main(int argc, char* argv[])
void processVideo(char* videoFilename) {
int estadoANTERIOR = 0;
int estadoACTUAL = 0;
int c = 0;
char buffer [15];
//create the capture object
VideoCapture capture(videoFilename);
if(!capture.isOpened()){
......@@ -142,7 +146,7 @@ void processVideo(char* videoFilename) {
// cerr << suma.val[0] << endl;
if (suma.val[0] > 1000000){
if (suma.val[0] > 1250000){
// estado oclusion
estadoANTERIOR = estadoACTUAL;
estadoACTUAL = 1;
......@@ -158,6 +162,12 @@ void processVideo(char* videoFilename) {
if (estadoANTERIOR == 3){
// estado estable
estadoACTUAL = 2;
imshow("ESTABLE", frame);
int b = sprintf (buffer, "tablero%d.png", c);
imwrite(buffer, frame);
c++;
pMOG= new BackgroundSubtractorMOG(); //MOG approach
pMOG2 = new BackgroundSubtractorMOG2(); //MOG2 approach
}
......@@ -184,7 +194,7 @@ void processVideo(char* videoFilename) {
//show the current frame and the fg masks
imshow("Frame", frame);
imshow("FG Mask MOG", fgMaskMOG);
// imshow("FG Mask MOG", fgMaskMOG);
imshow("FG Mask MOG 2", fgMaskMOG2);
//get the input from the keyboard
keyboard = waitKey( 30 );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment