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

se corrigio homografia y recorte, la apk suma homografia mas ecualizacion

parent 2c859fd0
No related branches found
No related tags found
No related merge requests found
......@@ -72,9 +72,6 @@ public class ChessTrackActivity extends Activity implements CvCameraViewListener
mOpenCvCameraView.setCvCameraViewListener(this);
calibrar = new Calibracion();
isUsed = false;
isCalibrada =false;
addListenerOnButton();
......@@ -96,6 +93,7 @@ public class ChessTrackActivity extends Activity implements CvCameraViewListener
toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 200); // 200 is duration in ms
adq = new Adquisicion(calibrar);
}else{
ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_ALARM, 50);
toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 700); // 200 is duration in ms
......@@ -138,21 +136,14 @@ public class ChessTrackActivity extends Activity implements CvCameraViewListener
@Override
public Mat onCameraFrame(Mat inputFrame) {
// TODO Auto-generated method stub
//return adq.processFrame(inputFrame);
// TODO MANEJAR ESTADOS
if (!isUsed){
frame = inputFrame;
}
if(isCalibrada){
/*
Core.circle(inputFrame, calibrar.getVertices().toList().get(0), 10, new Scalar(0,0 , 255, 255),-25);
Core.circle(inputFrame, calibrar.getVertices().toList().get(6), 10, new Scalar(0,255 , 255, 0),-25);
Core.circle(inputFrame, calibrar.getVertices().toList().get(42), 10, new Scalar(0,0 , 0, 255),-25)
Core.circle(inputFrame, calibrar.getVertices().toList().get(48), 10, new Scalar(0,0 , 128, 255),-25);
return inputFrame ;
*/
Log.i(TAG, "calibrada");
return adq.processFrame(inputFrame);
}
......
......@@ -7,6 +7,7 @@ import java.util.List;
import org.opencv.core.Mat;
import uy.edu.fing.chesstrack.modulovision.imgproc.EcualizarImagen;
import uy.edu.fing.chesstrack.modulovision.imgproc.Homografia;
import uy.edu.fing.chesstrack.modulovision.imgproc.ImgProcInterface;
import android.util.Log;
......@@ -23,8 +24,9 @@ public class Adquisicion {
super();
Log.i(TAG, "Cargado....");
listProc = new ArrayList<ImgProcInterface>();
//listProc.add( new EcualizarImagen());
listProc.add( new Homografia(cal.getVertices()));
listProc.add( new EcualizarImagen());
}
/**
......@@ -37,34 +39,10 @@ public class Adquisicion {
public synchronized Mat processFrame(Mat inputPicture) {
Log.i(TAG, "processFrame inicia");
Mat salida = inputPicture;
//
// // Core.line(salida, new Point(0, 5), new Point(salida.cols()/2,salida.rows()/2), new Scalar(0, 255, 0, 255), 3);
//
// // Core.circle(salida, new Point(salida.cols()/2,salida.rows()/2), 120, new Scalar(0,0 , 255, 255));
//
// MatOfPoint2f pointBuf;
// boolean found = Calib3d.findChessboardCorners( salida, salida.size(), pointBuf,
// Calib3d.CALIB_CB_ADAPTIVE_THRESH |Calib3d.CALIB_CB_FAST_CHECK | Calib3d.CALIB_CB_NORMALIZE_IMAGE);
// if (found){
// Mat viewGray;
// Imgproc.cvtColor(salida, viewGray, Imgproc.COLOR_BGR2GRAY);
// cornerSubPix( viewGray, pointBuf, new Size(11,11),
// new Size(-1,-1), TermCriteria( TermCriteria.TERMCRIT_EPS+TermCriteria.TERMCRIT_ITER, 30, 0.1 ));
//
//
//
// MatOfPoint2f corners = new MatOfPoint2f();
// Imgproc.cornerSubPix(image, corners , winSize, zeroZone, criteria);
// Calib3d.drawChessboardCorners(salida, new Size(5, 5), corners, patternWasFound);
// }
Mat prevImg = inputPicture;
for (ImgProcInterface proc: listProc){
prevImg = proc.procesarImagen(prevImg);
}
return prevImg;
}
......
......@@ -28,10 +28,7 @@ public class Calibracion {
Log.i(TAG, "Encontro = " + corners.size().toString());
Calib3d.drawChessboardCorners(imagenCalibrada, patternSize, corners, ret);
vertices = corners;
//
// for(Point p : vertices.toList()){
// Log.i(TAG, "Encontro = " + Math.round(p.x) + " " + Math.round(p.y));
// }
}
OK = ret;
......
......@@ -4,17 +4,21 @@ import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint2f;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.imgproc.Imgproc;
public class Homografia implements ImgProcInterface {
import android.util.Log;
public class Homografia implements ImgProcInterface {
private final Mat matrizTransformada;
private static final String TAG = "CHESSTRACK::Homografia";
private final Mat matrizTransformada;
private final Rect rectPOI;
public Homografia(MatOfPoint2f vertices) {
super();
int offset = 48*2;
int media = 48*6;
//int offset = 48*2;
//int media = 48*6;
Mat src = new Mat(4,1,CvType.CV_32FC2);
Mat dst = new Mat(4,1,CvType.CV_32FC2);
Point p1,p2,p3,p4;
......@@ -22,19 +26,37 @@ public class Homografia implements ImgProcInterface {
p2 = vertices.toList().get(6);
p3 = vertices.toList().get(42);
p4 = vertices.toList().get(48);
src.put((int)p1.y,(int)p1.x, (int)p2.y,(int)p2.x, (int)p4.y,(int)p4.x, (int)p3.y,(int)p3.x);
dst.put( offset,offset ,offset+media,offset , offset,offset+media , offset+media,offset+media );
double d17 = Math.sqrt(Math.pow((p1.x- p2.x),2) + Math.pow((p1.y- p2.y),2));
double d749 = Math.sqrt(Math.pow((p2.x- p4.x),2) + Math.pow((p2.y- p4.y),2));
double d143 = Math.sqrt(Math.pow((p1.x- p3.x),2) + Math.pow((p1.y- p3.y),2));
double d4349 = Math.sqrt(Math.pow((p3.x- p4.x),2) + Math.pow((p3.y- p4.y),2));
matrizTransformada = Imgproc.getPerspectiveTransform(src,dst);
}
int media = (int) Math.floor( Math.round((d17+d749+d143+d4349)/4));
int offset = 2*(media/7);
src.put(0,0 ,(int)p1.x,(int)p1.y, (int)p2.x,(int)p2.y, (int)p3.x,(int)p3.y, (int)p4.x,(int)p4.y);
dst.put(0,0, offset,offset ,offset+media,offset , offset,offset+media , offset+media,offset+media );
Log.i(TAG, "offset= " + offset);
Log.i(TAG, "media = " + media);
// EL offset es casi el tamaño de una celda
rectPOI = new Rect(new Point(0,0), new Point(2*offset+media,2*offset+media));
matrizTransformada = Imgproc.getPerspectiveTransform(src,dst);
}
/**
* Hace homografia y recorta la imagen
*/
@Override
public Mat procesarImagen(Mat inputFrame) {
Mat out = inputFrame.clone();
Imgproc.warpPerspective(inputFrame,out, matrizTransformada, out.size());
return inputFrame;
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);
return tmp;
}
......
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