Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ChessTrack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Aylen Ricca
ChessTrack
Commits
739a2435
Commit
739a2435
authored
10 years ago
by
Aylen Ricca
Browse files
Options
Downloads
Patches
Plain Diff
new class
parent
9c9b3609
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ProyectoAndroid/ChessTrack/src/uy/edu/fing/chesstrack/modulovision/DetectorOclusion.java
+124
-0
124 additions, 0 deletions
...uy/edu/fing/chesstrack/modulovision/DetectorOclusion.java
with
124 additions
and
0 deletions
ProyectoAndroid/ChessTrack/src/uy/edu/fing/chesstrack/modulovision/DetectorOclusion.java
0 → 100644
+
124
−
0
View file @
739a2435
package
uy.edu.fing.chesstrack.modulovision
;
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
;
//contours = new ArrayList<MatOfPoint>();
Log
.
i
(
TAG
,
"constructor FIN"
);
}
public
Mat
procesarImagen
(
Mat
inputFrame
)
{
Log
.
i
(
TAG
,
"Procesar!"
);
Log
.
i
(
TAG
,
"Region SIZE="
+
inputFrame
.
size
());
_pMOG2
.
apply
(
inputFrame
,
_fgMaskMOG2
);
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
}
}
/*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
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment