Skip to content
Snippets Groups Projects
Commit 9c9b3609 authored by Aylen Ricca's avatar Aylen Ricca
Browse files

reubicated clases

parent 462f2df5
No related branches found
No related tags found
No related merge requests found
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);
if (_serverSocket != null) {
// 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) {
if (this._serverSocket != null && this._output != null) {
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();
}
}
}
......@@ -21,7 +21,6 @@ public class Adquisicion {
_listProc.add(new Homografia());
//_listProc.add(new EcualizarImagen());
//_listProc.add(new BackgroundSupress());
}
/**
......
......@@ -7,7 +7,6 @@ import android.media.AudioManager;
import android.media.ToneGenerator;
import android.util.Log;
import uy.edu.fing.chesstrack.communication.Client;
import uy.edu.fing.chesstrack.modulovision.imgproc.DetectorOclusion;
public class Manager {
......
package uy.edu.fing.chesstrack.modulovision.imgproc;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.imgproc.*;
import org.opencv.video.BackgroundSubtractorMOG2;
import android.util.Log;
public class DetectorOclusion {
private static final String TAG = "CHESSTRACK::BackgroundSupress";
private static final int OCLUSION = 1;
private static final int ESTABLE = 2;
private static final int TRANSICION = 0;
private static final int START = -1;
private Mat _fgMaskMOG2;
private BackgroundSubtractorMOG2 _pMOG2;
private final Mat _morphKernel;
private int _estadoANTERIOR;
private int _estadoACTUAL;
//private final List<MatOfPoint> contours;
public DetectorOclusion() {
super();
Log.i(TAG, "constructor INI");
_morphKernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(3,3));
_fgMaskMOG2 = new Mat(4,1,CvType.CV_8UC1);
_pMOG2 = new BackgroundSubtractorMOG2();
_estadoACTUAL = START;
_estadoANTERIOR = START;
//_communicator = Client.getInstance();
//contours = new ArrayList<MatOfPoint>();
Log.i(TAG, "constructor FIN");
}
public Mat procesarImagen(Mat inputFrame) {
Log.i(TAG, "Procesar!");
//Mat ret = Mat.zeros(Calibracion.getInstance().get_sizeFrame(), CvType.CV_8UC4);
//Rect roi = Calibracion.getRectROI();
Log.i(TAG, "Region SIZE=" + inputFrame.size());
//Mat region = ret.submat(roi);
//Mat working = inputFrame.submat(roi);
// Mat copy = new Mat(submat.size(),CvType.CV_8UC3);;
// submat.convertTo(copy, CvType.CV_8UC3);
//Mat copy = new Mat(inputFrame.size(),CvType.CV_8UC3);
//inputFrame.convertTo(copy, CvType.CV_8UC3);
//Imgproc.cvtColor(inputFrame, copy, Imgproc.COLOR_BGRA2BGR);
_pMOG2.apply(inputFrame, _fgMaskMOG2);
//Log.i(TAG, "Apply pMOG2" + _fgMaskMOG2.size());
Imgproc.erode(_fgMaskMOG2, _fgMaskMOG2, _morphKernel);
Log.i(TAG, "Apply erode");
Imgproc.threshold(_fgMaskMOG2, _fgMaskMOG2, 200, 255, Imgproc.THRESH_BINARY);
Log.i(TAG, "Apply threshold");
//Imgproc.dilate(_fgMaskMOG2, _fgMaskMOG2, _morphKernel);
//Log.i(TAG, "Apply dilate");
Scalar suma = Core.sumElems(_fgMaskMOG2);
Log.i(TAG, "SUMA = " + suma);
_estadoANTERIOR = _estadoACTUAL;
if (suma.val[0] > 1250000){
Log.i(TAG, "MANO !!!");
_estadoACTUAL = OCLUSION;
Core.putText(_fgMaskMOG2, "MANO !!!", new Point(20, 20),Core.FONT_HERSHEY_SIMPLEX, 0.8 , new Scalar(255,255,0));
} else {
Log.i(TAG, "ESTABLE !!!");
if (_estadoANTERIOR == OCLUSION){
Core.putText(_fgMaskMOG2, "TRANSI !!!", new Point(20, 20),Core.FONT_HERSHEY_SIMPLEX, 0.8 , new Scalar(255,255,0));
_estadoACTUAL = TRANSICION;
}
if (_estadoANTERIOR == TRANSICION){
Core.putText(_fgMaskMOG2, "ESTABLE !!!", new Point(20, 20),Core.FONT_HERSHEY_SIMPLEX, 0.8 , new Scalar(255,255,0));
_estadoACTUAL = ESTABLE;
_pMOG2 = new BackgroundSubtractorMOG2(); //MOG2 approach
//Manager.set_estado(ESTABLE);
}
//_communicator.SendData("ESTABLE\n");
}
/*double maxArea = 0;
MatOfPoint largestContour = null;
Imgproc.findContours(_fgMaskMOG2, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_TC89_L1);
for (MatOfPoint contour : contours) {
double area = Imgproc.contourArea(contour);
if (area > maxArea) {
maxArea = area;
largestContour = contour;
}
}
Log.i(TAG, "ESTABLE !!!" + maxArea);
if ((largestContour != null) && (maxArea > 10000)){
Log.i(TAG, "MANO !!!" + maxArea);
Rect boundingRect = Imgproc.boundingRect(largestContour);
ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_ALARM, 50);
toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 200); // 200 is duration in ms
}*/
/*Imgproc.findContours(_fgMaskMOG2, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_NONE);
for(int idx = 0; idx < contours.size(); idx++)
{
double area = Imgproc.contourArea(contours.get(idx));
Log.i(TAG, "CONTOUR = AREA: " + area);
if ((area > 15000) && (area < 70000)){
Log.i(TAG, "DRAW !!! : " + area);
Scalar color = new Scalar(255,127,127);
Rect r = Imgproc.boundingRect(contours.get(idx));
Log.i(TAG, "3 at backgroundS "+(_fgMaskMOG2.type() == CvType.CV_8UC1));
Core.rectangle(_fgMaskMOG2, r.tl(), r.br(), color, 2, 8, 0);
//Imgproc.drawContours(_fgMaskMOG2, contours, idx, color);
}
}
contours.clear();*/
Log.i(TAG, "END");
Mat region = new Mat();
Imgproc.cvtColor(_fgMaskMOG2, region, Imgproc.COLOR_GRAY2RGBA,4);
return region;
}
}
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