Skip to content
This repository was archived by the owner on Dec 31, 2022. It is now read-only.

Commit 7ed5c08

Browse files
committed
DogeCV 2018.2 Release
1 parent 980e375 commit 7ed5c08

32 files changed

Lines changed: 1111 additions & 484 deletions

DogeCV/src/main/java/com/disnodeteam/dogecv/ActivityViewDisplay.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
*/
3838

3939
public class ActivityViewDisplay implements ViewDisplay {
40+
41+
//There should only be one instance of this class, so make a static reference to it
4042
private static ActivityViewDisplay instance;
4143
private static View main = null;
4244

@@ -48,6 +50,11 @@ public static ActivityViewDisplay getInstance() {
4850
return instance;
4951
}
5052

53+
/**
54+
* Sets this display to be the current one in use, and starts it on the UI thread (as opposed to the robot controller thread)
55+
* @param context The context of the OpMode, can be obtained via hardwaremap.appContext;
56+
* @param view The view upon which this activity is to be displayed
57+
*/
5158
public void setCurrentView(final Context context, final View view) {
5259
final Activity activity = (Activity) context;
5360
activity.runOnUiThread(new Runnable() {

DogeCV/src/main/java/com/disnodeteam/dogecv/CustomCameraView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class CustomCameraView extends JavaCameraView {
5050

5151
public CustomCameraView(Context context, int cameraId) {
5252
super(context, cameraId);
53+
enableFpsMeter();
5354
}
5455

5556
@Override

DogeCV/src/main/java/com/disnodeteam/dogecv/DogeCV.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
package com.disnodeteam.dogecv;
22

3-
import android.util.Log;
4-
5-
import org.opencv.core.Core;
6-
import org.opencv.core.Mat;
7-
import org.opencv.core.Scalar;
8-
import org.opencv.core.Size;
9-
import org.opencv.imgproc.Imgproc;
10-
11-
import java.util.ArrayList;
12-
import java.util.List;
13-
3+
/**
4+
* Contains global enumerated types
5+
*/
146
public class DogeCV {
157
public enum DetectionSpeed {
168
VERY_FAST,
@@ -22,7 +14,8 @@ public enum DetectionSpeed {
2214

2315
public enum AreaScoringMethod {
2416
MAX_AREA,
25-
PERFECT_AREA
17+
PERFECT_AREA,
18+
COLOR_DEVIATION
2619
}
2720

2821

DogeCV/src/main/java/com/disnodeteam/dogecv/Dogeforia.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import static com.vuforia.Vuforia.setFrameFormat;
4747

4848
/**
49-
* Created by Victo on 9/12/2018.
49+
* An implementation of Vuforia intended to be cross-compatible with OpenCV (and DogeCV by extension)
5050
*/
5151

5252
public class Dogeforia extends VuforiaLocalizerImpl {
@@ -63,9 +63,6 @@ public class Dogeforia extends VuforiaLocalizerImpl {
6363
BlockingQueue<CloseableFrame> frames;
6464
public Dogeforia(Parameters parameters) {
6565
super(parameters);
66-
67-
68-
6966
}
7067

7168
public void setDogeCVDetector(DogeCVDetector detector){
@@ -126,6 +123,9 @@ public void processFrame(Frame frame){
126123
VuforiaTrackablesImpl trackables = loadedTrackableSets.get(0);
127124
int count = 0;
128125
for(VuforiaTrackable trackable : trackables){
126+
if(trackable == null || ((VuforiaTrackableDefaultListener)trackable.getListener()) == null){
127+
continue;
128+
}
129129
if(((VuforiaTrackableDefaultListener)trackable.getListener()).isVisible()){
130130
Imgproc.putText(outMat,"Vuforia: " + trackable.getName(), new Point(10,50 * count + 50),0,2,new Scalar(0,255,0),3);
131131
count++;

DogeCV/src/main/java/com/disnodeteam/dogecv/DrawViewSource.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,21 @@ public class DrawViewSource extends View {
3333
private Bitmap bitmap;
3434

3535
public DrawViewSource(Context context) {
36-
// TODO Auto-generated constructor stub
3736
super(context);
3837
init(context, null, 0);
3938
}
4039

4140
public DrawViewSource(Context context, AttributeSet attrs) {
42-
// TODO Auto-generated constructor stub
4341
super(context, attrs);
4442
init(context, attrs, 0);
4543
}
4644

4745
public DrawViewSource(Context context, AttributeSet attrs, int defStyleAttr) {
48-
// TODO Auto-generated constructor stub
4946
super(context, attrs, defStyleAttr);
5047
init(context, attrs, defStyleAttr);
5148
}
5249

5350
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
54-
// TODO Auto-generated method stub
5551
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
5652

5753

@@ -66,7 +62,6 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr) {
6662
public DrawViewSource(Context context, AttributeSet attrs,
6763
int defStyleAttr, int defStyleRes) {
6864
super(context, attrs, defStyleAttr, defStyleRes);
69-
// TODO Auto-generated constructor stub
7065
}
7166

7267
/*
@@ -80,7 +75,6 @@ public void onFrame(Bitmap map){
8075

8176
@Override
8277
protected void onDraw(Canvas canvas) {
83-
// TODO Auto-generated method stub
8478
super.onDraw(canvas);
8579

8680
canvas.drawColor(0, android.graphics.PorterDuff.Mode.CLEAR);

DogeCV/src/main/java/com/disnodeteam/dogecv/OpenCVLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.disnodeteam.dogecv;
22

3-
import android.content.Context;
43
import android.os.Environment;
54
import android.util.Log;
65

@@ -45,6 +44,7 @@ public class OpenCVLoader {
4544
// This path may need to be changed for Samsung S5 phones;
4645
// its hardcoded because idk how else to get the path without a Context.
4746
// Feel free to change the value to fit the phone you are using.
47+
4848
private static String filesDir = "/data/user/0/com.qualcomm.ftcrobotcontroller/files";
4949
public static void setFilesDir(String path) {
5050
filesDir = path;

DogeCV/src/main/java/com/disnodeteam/dogecv/OpenCVPipeline.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
* copy or use the software.
4040
* -------------------------------------------------------------------------------------
4141
* This is a base class for an OpenCV pipeline loop. In most cases, one would want to override processFrame() with their own function.
42-
* TODO: consider more functionality in here, relating to camera parameter manipulation? For most cases it's not needed.
4342
*/
4443

4544
public abstract class OpenCVPipeline implements CameraBridgeViewBase.CvCameraViewListener2 {
@@ -84,6 +83,7 @@ public void init(Context context, ViewDisplay viewDisplay, final int cameraIndex
8483
final Activity activity = (Activity) context;
8584
final Context finalContext = context;
8685
final CameraBridgeViewBase.CvCameraViewListener2 self = this;
86+
8787
activity.runOnUiThread(new Runnable() {
8888
@Override
8989
public void run() {
@@ -94,12 +94,13 @@ public void run() {
9494
cameraView = new CustomCameraView(finalContext, cameraIndex);
9595
cameraView.setCameraIndex(cameraIndex);
9696
cameraView.setCvCameraViewListener(self);
97+
cameraView.enableFpsMeter();
98+
9799
}
98100
inited = true;
99101
}
100102
});
101103
}
102-
//TODO: allow other JavaCameraViews to be used, with the stipulation that they must already be instantiated from a UI thread
103104

104105
/**
105106
* Attaches the underlying JavaCameraView to the screen and the camera using the set {@link ViewDisplay} to do so, essentially starting OpenCV processing.

DogeCV/src/main/java/com/disnodeteam/dogecv/detectors/BlankDetector.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@
1010
* Created by Victo on 12/17/2017.
1111
*/
1212

13-
public class BlankDetector extends OpenCVPipeline {
13+
public class BlankDetector extends DogeCVDetector {
1414
@Override
15-
public Mat processFrame(Mat rgba, Mat gray) {
16-
return rgba;
15+
public Mat process(Mat input) {
16+
// Process frame
17+
return input;
18+
}
19+
20+
@Override
21+
public void useDefaults() {
22+
// Add in your scorers here.
1723
}
1824
}

DogeCV/src/main/java/com/disnodeteam/dogecv/detectors/DogeCVDetector.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
package com.disnodeteam.dogecv.detectors;
22

3-
import android.app.Activity;
4-
import android.view.Surface;
5-
import android.view.View;
6-
73
import com.disnodeteam.dogecv.DogeCV;
84
import com.disnodeteam.dogecv.OpenCVPipeline;
95
import com.disnodeteam.dogecv.scoring.DogeCVScorer;
106

11-
import org.opencv.core.Core;
127
import org.opencv.core.Mat;
138
import org.opencv.core.MatOfPoint;
149
import org.opencv.core.Point;
@@ -32,15 +27,17 @@ public abstract class DogeCVDetector extends OpenCVPipeline{
3227
private Size initSize;
3328
private Size adjustedSize;
3429
private Mat workingMat = new Mat();
35-
public double maxDiffrence = 10;
30+
public double maxDifference = 10;
3631

3732
public DogeCV.DetectionSpeed speed = DogeCV.DetectionSpeed.BALANCED;
3833
public double downscale = 0.5;
3934
public Size downscaleResolution = new Size(640, 480);
4035
public boolean useFixedDownscale = true;
4136
protected String detectorName = "DogeCV Detector";
4237

43-
public DogeCVDetector(){}
38+
public DogeCVDetector(){
39+
40+
}
4441

4542
public void setSpeed(DogeCV.DetectionSpeed speed){
4643
this.speed = speed;
@@ -50,11 +47,11 @@ public void addScorer(DogeCVScorer newScorer){
5047
scorers.add(newScorer);
5148
}
5249

53-
public double calculateScore(MatOfPoint contours){
50+
public double calculateScore(Mat input){
5451
double totalScore = 0;
5552

5653
for(DogeCVScorer scorer : scorers){
57-
totalScore += scorer.calculateDifference(contours);
54+
totalScore += scorer.calculateScore(input);
5855
}
5956

6057
return totalScore;
@@ -64,7 +61,7 @@ public double calculateScore(MatOfPoint contours){
6461

6562
@Override
6663
public Mat processFrame(Mat rgba, Mat gray) {
67-
initSize= rgba.size();
64+
initSize = rgba.size();
6865

6966
if(useFixedDownscale){
7067
adjustedSize = downscaleResolution;
@@ -77,10 +74,10 @@ public Mat processFrame(Mat rgba, Mat gray) {
7774
if(workingMat.empty()){
7875
return rgba;
7976
}
80-
Imgproc.resize(workingMat, workingMat,adjustedSize);
81-
82-
Imgproc.resize(process(workingMat),workingMat,getInitSize());
83-
Imgproc.putText(workingMat,"DogeCV 2018.1 " + detectorName + ": " + getAdjustedSize().toString() + " - " + speed.toString() ,new Point(5,30),0,0.5,new Scalar(0,255,255),2);
77+
Imgproc.resize(workingMat, workingMat,adjustedSize); // Downscale
78+
Imgproc.resize(process(workingMat),workingMat,getInitSize()); // Process and scale back to original size for viewing
79+
//Print Info
80+
Imgproc.putText(workingMat,"DogeCV 2018.2 " + detectorName + ": " + getAdjustedSize().toString() + " - " + speed.toString() ,new Point(5,30),0,0.5,new Scalar(0,255,255),2);
8481

8582
return workingMat;
8683
}
@@ -92,4 +89,6 @@ public Size getInitSize() {
9289
public Size getAdjustedSize() {
9390
return adjustedSize;
9491
}
92+
93+
public void setAdjustedSize(Size size) { this.adjustedSize = size; }
9594
}

0 commit comments

Comments
 (0)