77
88import org .lasarobotics .vision .android .Camera ;
99import org .lasarobotics .vision .android .Cameras ;
10- import org .lasarobotics .vision .image .Drawing ;
11- import org .lasarobotics .vision .util .FPS ;
1210import org .lasarobotics .vision .android .Util ;
11+ import org .lasarobotics .vision .detection .ColorBlobDetector ;
12+ import org .lasarobotics .vision .detection .Contour ;
1313import 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 ;
1520import org .opencv .android .BaseLoaderCallback ;
1621import org .opencv .android .CameraBridgeViewBase ;
1722import org .opencv .android .CameraBridgeViewBase .CvCameraViewFrame ;
2429import org .opencv .highgui .Highgui ;
2530
2631import java .io .File ;
32+ import java .util .List ;
2733
2834public class CameraTestActivity extends Activity implements CvCameraViewListener2 {
2935
3036 private Mat mRgba ; //RGBA scene image
3137 private Mat mGray ; //Grayscale scene image
38+ private CameraBridgeViewBase mOpenCvCameraView ;
3239
3340 private float focalLength ; //Camera lens focal length
3441
35- private CameraBridgeViewBase mOpenCvCameraView ;
36-
37- private ObjectDetection .ObjectAnalysis objectAnalysis ;
42+ //private ObjectDetection.ObjectAnalysis objectAnalysis;
3843 private FPS fpsCounter ;
3944
4045 private void initialize ()
@@ -48,7 +53,7 @@ private void initialize()
4853
4954 //GET OBJECT IMAGE
5055 //Read the target image file
51- String dir = Util .getDCIMDirectory ();
56+ /* String dir = Util.getDCIMDirectory();
5257 File file = new File(dir + "/beacon.png");
5358
5459 if (!file.exists())
@@ -63,13 +68,13 @@ private void initialize()
6368 // print error and abort execution
6469 Log.e("CameraTester", "FAILED TO LOAD IMAGE FILE!");
6570 System.exit(1);
66- }
71+ }*/
6772
6873 //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);
7378
7479 //UPDATE COUNTER
7580 fpsCounter = new FPS ();
@@ -83,7 +88,7 @@ public void onManagerConnected(int status) {
8388 {
8489 // OpenCV loaded successfully!
8590 // Load native library AFTER OpenCV initialization
86-
91+
8792 initialize ();
8893
8994 mOpenCvCameraView .enableView ();
@@ -135,9 +140,22 @@ public void onDestroy() {
135140 mOpenCvCameraView .disableView ();
136141 }
137142
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+
138153 public void onCameraViewStarted (int width , int height ) {
139154 mRgba = new Mat (height , width , CvType .CV_8UC4 );
140155 mGray = new Mat (height , width , CvType .CV_8UC1 );
156+
157+ detectorRed = new ColorBlobDetector (lowerBoundRed , upperBoundRed );
158+ detectorBlue = new ColorBlobDetector (lowerBoundBlue , upperBoundBlue );
141159 }
142160
143161 public void onCameraViewStopped () {
@@ -146,31 +164,46 @@ public void onCameraViewStopped() {
146164 }
147165
148166 public Mat onCameraFrame (CvCameraViewFrame inputFrame ) {
149- // input frame has RBGA format
167+ // input frame has RGBA format
150168 mRgba = inputFrame .rgba ();
151169 mGray = inputFrame .gray ();
152170
153171 fpsCounter .update ();
154172
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);
158176
159177 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 );
164199 }
165200 catch (Exception e )
166201 {
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 );
168203 e .printStackTrace ();
169204 }
170205
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" ));
174207
175208 return mRgba ;
176209 }
0 commit comments