7
7
8
8
import org .lasarobotics .vision .android .Camera ;
9
9
import org .lasarobotics .vision .android .Cameras ;
10
- import org .lasarobotics .vision .image .Drawing ;
11
- import org .lasarobotics .vision .util .FPS ;
12
10
import org .lasarobotics .vision .android .Util ;
11
+ import org .lasarobotics .vision .detection .ColorBlobDetector ;
12
+ import org .lasarobotics .vision .detection .Contour ;
13
13
import org .lasarobotics .vision .detection .ObjectDetection ;
14
- import org .lasarobotics .vision .util .Color ;
14
+ import org .lasarobotics .vision .ftc .resq .Beacon ;
15
+ import org .lasarobotics .vision .image .Drawing ;
16
+ import org .lasarobotics .vision .util .FPS ;
17
+ import org .lasarobotics .vision .util .color .ColorGRAY ;
18
+ import org .lasarobotics .vision .util .color .ColorHSV ;
19
+ import org .lasarobotics .vision .util .color .ColorRGBA ;
15
20
import org .opencv .android .BaseLoaderCallback ;
16
21
import org .opencv .android .CameraBridgeViewBase ;
17
22
import org .opencv .android .CameraBridgeViewBase .CvCameraViewFrame ;
24
29
import org .opencv .highgui .Highgui ;
25
30
26
31
import java .io .File ;
32
+ import java .util .List ;
27
33
28
34
public class CameraTestActivity extends Activity implements CvCameraViewListener2 {
29
35
30
36
private Mat mRgba ; //RGBA scene image
31
37
private Mat mGray ; //Grayscale scene image
38
+ private CameraBridgeViewBase mOpenCvCameraView ;
32
39
33
40
private float focalLength ; //Camera lens focal length
34
41
35
- private CameraBridgeViewBase mOpenCvCameraView ;
36
-
37
- private ObjectDetection .ObjectAnalysis objectAnalysis ;
42
+ //private ObjectDetection.ObjectAnalysis objectAnalysis;
38
43
private FPS fpsCounter ;
39
44
40
45
private void initialize ()
@@ -48,7 +53,7 @@ private void initialize()
48
53
49
54
//GET OBJECT IMAGE
50
55
//Read the target image file
51
- String dir = Util .getDCIMDirectory ();
56
+ /* String dir = Util.getDCIMDirectory();
52
57
File file = new File(dir + "/beacon.png");
53
58
54
59
if (!file.exists())
@@ -63,13 +68,13 @@ private void initialize()
63
68
// print error and abort execution
64
69
Log.e("CameraTester", "FAILED TO LOAD IMAGE FILE!");
65
70
System.exit(1);
66
- }
71
+ }*/
67
72
68
73
//ANALYZE OBJECT
69
- ObjectDetection detection = new ObjectDetection (ObjectDetection .FeatureDetectorType .GFTT ,
70
- ObjectDetection .DescriptorExtractorType .BRIEF ,
71
- ObjectDetection .DescriptorMatcherType .BRUTEFORCE_HAMMING );
72
- objectAnalysis = detection .analyzeObject (mTarget );
74
+ // ObjectDetection detection = new ObjectDetection(ObjectDetection.FeatureDetectorType.GFTT,
75
+ // ObjectDetection.DescriptorExtractorType.ORB ,
76
+ // ObjectDetection.DescriptorMatcherType.BRUTEFORCE_HAMMING);
77
+ // objectAnalysis = detection.analyzeObject(mTarget);
73
78
74
79
//UPDATE COUNTER
75
80
fpsCounter = new FPS ();
@@ -83,7 +88,7 @@ public void onManagerConnected(int status) {
83
88
{
84
89
// OpenCV loaded successfully!
85
90
// Load native library AFTER OpenCV initialization
86
-
91
+
87
92
initialize ();
88
93
89
94
mOpenCvCameraView .enableView ();
@@ -135,9 +140,22 @@ public void onDestroy() {
135
140
mOpenCvCameraView .disableView ();
136
141
}
137
142
143
+ private ColorBlobDetector detectorRed ;
144
+ private ColorBlobDetector detectorBlue ;
145
+ private static final ColorHSV colorRadius = new ColorHSV (50 , 75 , 127 );
146
+
147
+ private static final ColorHSV lowerBoundRed = new ColorHSV ( (int )(305 / 360.0 * 255.0 ), (int )(0.200 * 255.0 ), (int )(0.300 * 255.0 ));
148
+ private static final ColorHSV upperBoundRed = new ColorHSV ( (int )((360.0 +5.0 ) / 360.0 * 255.0 ), 255 , 255 );
149
+
150
+ private static final ColorHSV lowerBoundBlue = new ColorHSV ((int )(187.0 / 360.0 * 255.0 ), (int )(0.750 * 255.0 ), (int )(0.750 * 255.0 ));
151
+ private static final ColorHSV upperBoundBlue = new ColorHSV ((int )(227.0 / 360.0 * 255.0 ), 255 , 255 );
152
+
138
153
public void onCameraViewStarted (int width , int height ) {
139
154
mRgba = new Mat (height , width , CvType .CV_8UC4 );
140
155
mGray = new Mat (height , width , CvType .CV_8UC1 );
156
+
157
+ detectorRed = new ColorBlobDetector (lowerBoundRed , upperBoundRed );
158
+ detectorBlue = new ColorBlobDetector (lowerBoundBlue , upperBoundBlue );
141
159
}
142
160
143
161
public void onCameraViewStopped () {
@@ -146,31 +164,46 @@ public void onCameraViewStopped() {
146
164
}
147
165
148
166
public Mat onCameraFrame (CvCameraViewFrame inputFrame ) {
149
- // input frame has RBGA format
167
+ // input frame has RGBA format
150
168
mRgba = inputFrame .rgba ();
151
169
mGray = inputFrame .gray ();
152
170
153
171
fpsCounter .update ();
154
172
155
- ObjectDetection detection = new ObjectDetection (ObjectDetection .FeatureDetectorType .FAST_DYNAMIC ,
156
- ObjectDetection .DescriptorExtractorType .BRIEF ,
157
- ObjectDetection .DescriptorMatcherType .BRUTEFORCE_HAMMING );
173
+ // ObjectDetection detection = new ObjectDetection(ObjectDetection.FeatureDetectorType.ORB ,
174
+ // ObjectDetection.DescriptorExtractorType.ORB ,
175
+ // ObjectDetection.DescriptorMatcherType.BRUTEFORCE_HAMMING);
158
176
159
177
try {
160
- ObjectDetection .SceneAnalysis sceneAnalysis = detection .analyzeScene (mGray , objectAnalysis , mRgba );
161
- ObjectDetection .drawKeypoints (mRgba , sceneAnalysis );
162
- ObjectDetection .drawDebugInfo (mRgba , sceneAnalysis );
163
- ObjectDetection .drawObjectLocation (mRgba , objectAnalysis , sceneAnalysis );
178
+ //ObjectDetection.SceneAnalysis sceneAnalysis = detection.analyzeScene(mGray, objectAnalysis, mRgba);
179
+ //ObjectDetection.drawKeypoints(mRgba, sceneAnalysis);
180
+ //ObjectDetection.drawDebugInfo(mRgba, sceneAnalysis);
181
+ //ObjectDetection.drawObjectLocation(mRgba, objectAnalysis, sceneAnalysis);
182
+
183
+ mRgba = inputFrame .rgba ();
184
+
185
+ //Process the frame for the color blobs
186
+ detectorRed .process (mRgba );
187
+ detectorBlue .process (mRgba );
188
+
189
+ //Get the list of contours
190
+ List <Contour > contoursRed = detectorRed .getContours ();
191
+ List <Contour > contoursBlue = detectorBlue .getContours ();
192
+
193
+ Beacon .BeaconColorAnalysis colorAnalysis = Beacon .analyzeColor (contoursRed , contoursBlue , mRgba );
194
+
195
+ Drawing .drawContours (mRgba , contoursRed , new ColorRGBA (255 , 0 , 0 ), 3 );
196
+ Drawing .drawContours (mRgba , contoursBlue , new ColorRGBA (0 , 0 , 255 ), 3 );
197
+ Drawing .drawText (mRgba , colorAnalysis .getStateLeft ().toString () + ", " + colorAnalysis .getStateRight ().toString (),
198
+ new Point (0 , 8 ), 1.0f , new ColorGRAY (255 ), Drawing .Anchor .BOTTOMLEFT );
164
199
}
165
200
catch (Exception e )
166
201
{
167
- Drawing .drawText (mRgba , "Analysis Error" , new Point (0 , 8 ), 1.0f , new Color ("#F44336" ), Drawing .Anchor .BOTTOMLEFT );
202
+ Drawing .drawText (mRgba , "Analysis Error" , new Point (0 , 8 ), 1.0f , new ColorRGBA ("#F44336" ), Drawing .Anchor .BOTTOMLEFT );
168
203
e .printStackTrace ();
169
204
}
170
205
171
- Drawing .drawText (mRgba , "FPS: " + fpsCounter .getFPSString (), new Point (0 , 24 ), 1.0f , new Color ("#2196F3" ));
172
-
173
- //Features.highlightFeatures(mGray.getNativeObjAddr(), mRgba.getNativeObjAddr());
206
+ Drawing .drawText (mRgba , "FPS: " + fpsCounter .getFPSString (), new Point (0 , 24 ), 1.0f , new ColorRGBA ("#2196F3" ));
174
207
175
208
return mRgba ;
176
209
}
0 commit comments