Skip to content
This repository was archived by the owner on Dec 31, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added ..gitignore.un~
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
*.iml
.idea
2 changes: 2 additions & 0 deletions .gitignore~
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
*.iml
13 changes: 13 additions & 0 deletions DogeCV/src/main/java/com/disnodeteam/dogecv/DogeCV.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* Contains global values and types
*/
public class DogeCV {
/**
* The possible speeds for detection, the faster the less accurate and the
* slower the more accurate
*/
public enum DetectionSpeed {
VERY_FAST,
FAST,
Expand All @@ -12,18 +16,27 @@ public enum DetectionSpeed {
VERY_SLOW
}

/**
* The possible ways to score
*/
public enum AreaScoringMethod {
MAX_AREA,
PERFECT_AREA,
COLOR_DEVIATION
}

/**
* The different cameras that can be used
*/
public enum CameraMode {
BACK,
FRONT,
WEBCAM
}

/**
* The different VuMarks for the Rover Ruckus challenge
*/
public enum VuMark {
NONE,
BLUE_ROVER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@

/**
* Created by Victo on 12/17/2017.
*
* An empty detector
*/

public class BlankDetector extends DogeCVDetector {
/**
* Returns the input mat
* @param input the mat to return
* @return the input mat
*/
@Override
public Mat process(Mat input) {
// Process frame
return input;
}

/**
* Does nothing; in a real detector it would add the scorers
*/
@Override
public void useDefaults() {
// Add in your scorers here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@

/**
* Created by Victo on 9/10/2018.
*
* A base class for detectors
*/

public abstract class DogeCVDetector extends OpenCVPipeline{

/**
* Processes the input mat
* @param input the mat to be processed
* @return the processed mat
*/
public abstract Mat process(Mat input);

/**
* Should set the defaults, typically just the scorer
*/
public abstract void useDefaults();

private List<DogeCVScorer> scorers = new ArrayList<>();
Expand All @@ -43,14 +53,28 @@ public DogeCVDetector(){

}

/**
* Sets the speed of the detector
* @param speed the speed to set
*/
public void setSpeed(DogeCV.DetectionSpeed speed){
this.speed = speed;
}

/**
* Gives the detector a new scorer
*
* @param newScorer
*/
public void addScorer(DogeCVScorer newScorer){
scorers.add(newScorer);
}

/**
* Calculates the score for a given input mat
* @param input the mat to calculate the score for
* @return the score of the input mat
*/
public double calculateScore(Mat input){
double totalScore = 0;

Expand All @@ -62,7 +86,10 @@ public double calculateScore(Mat input){
}



/**
* Returns a frame to display on the RC phone
* @return the altered frame with version, speed, etc
*/
@Override
public Mat processFrame(Mat rgba, Mat gray) {
initSize = rgba.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

/**
* Created by Victo on 9/10/2018.
*
* A generic detector that works on many situations with many configuration
* options
*/

public class GenericDetector extends DogeCVDetector {
Expand All @@ -35,13 +38,31 @@ public class GenericDetector extends DogeCVDetector {
private Point screenPosition = new Point(); // Screen position of the mineral
private Rect foundRect = new Rect(); // Found rect

/**
* The AreaScoringMethod to use (defaults to MAX_AREA)
*/
public DogeCV.AreaScoringMethod areaScoringMethod = DogeCV.AreaScoringMethod.MAX_AREA; // Setting to decide to use MaxAreaScorer or PerfectAreaScorer

//Create the default filters and scorers
/**
* The DogeCVColorFilter to use (defaults to LeviColorFilter on RED)
*/
public DogeCVColorFilter colorFilter = new LeviColorFilter(LeviColorFilter.ColorPreset.RED); //Default Yellow filter

/**
* The default RatioScorer which finds perfect squares
*/
public RatioScorer ratioScorer = new RatioScorer(1.0, 3); // Used to find perfect squares

/**
* The default MaxAreaScorer which finds perfect squares
*/
public MaxAreaScorer maxAreaScorer = new MaxAreaScorer( 0.01); // Used to find largest objects

/**
* The default RatioScorer which finds objects that have an area closest to
* 5000 pixels
*/
public PerfectAreaScorer perfectAreaScorer = new PerfectAreaScorer(5000,0.05); // Used to find objects near a tuned area value

/**
Expand All @@ -52,7 +73,11 @@ public GenericDetector() {
detectorName = "Generic Detector"; // Set the detector name
}


/**
* Processes the frame by using the specified options
* @param input the Mat to process
* @return the processed Mat
*/
@Override
public Mat process(Mat input) {

Expand Down Expand Up @@ -112,6 +137,9 @@ public Mat process(Mat input) {

}

/**
* Runs the appropriate scorer, based on areaScoringMethod
*/
@Override
public void useDefaults() {
addScorer(ratioScorer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,46 @@ public class GoldAlignDetector extends DogeCVDetector {
private double goldYPos = 0; // Y Position (in pixels) of the gold element

// Detector settings
/**
* Determines whether or not debug lines should be shown
*/
public boolean debugAlignment = true; // Show debug lines to show alignment settings

/**
* How far from the center frame the gold is
*/
public double alignPosOffset = 0; // How far from center frame is aligned

/**
* The margin for error on alignment
*/
public double alignSize = 100; // How wide is the margin of error for alignment

/**
* The wanted AreaScoringMethod
*/
public DogeCV.AreaScoringMethod areaScoringMethod = DogeCV.AreaScoringMethod.MAX_AREA; // Setting to decide to use MaxAreaScorer or PerfectAreaScorer


//Create the default filters and scorers
/**
* The wanted DogeCVColorFilter
*/
public DogeCVColorFilter yellowFilter = new LeviColorFilter(LeviColorFilter.ColorPreset.YELLOW); //Default Yellow filter

/**
* The wanted RatioScorer
*/
public RatioScorer ratioScorer = new RatioScorer(1.0, 3); // Used to find perfect squares

/**
* The wanted MaxAreaScorer
*/
public MaxAreaScorer maxAreaScorer = new MaxAreaScorer( 0.01); // Used to find largest objects

/**
* The wanted PerfectAreaScorer
*/
public PerfectAreaScorer perfectAreaScorer = new PerfectAreaScorer(5000,0.05); // Used to find objects near a tuned area value

/**
Expand All @@ -60,7 +88,11 @@ public GoldAlignDetector() {
detectorName = "Gold Align Detector"; // Set the detector name
}


/**
* Processes the input mat
* @param input the mat to process
* @return the processed mat
*/
@Override
public Mat process(Mat input) {

Expand Down Expand Up @@ -153,6 +185,9 @@ public Mat process(Mat input) {

}

/**
* Sets the scorer based on areaScoringMethod
*/
@Override
public void useDefaults() {
addScorer(ratioScorer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

/**
* Created by Victo on 9/10/2018.
*
* Detects Gold
*/

public class GoldDetector extends DogeCVDetector {
Expand All @@ -39,13 +41,30 @@ public class GoldDetector extends DogeCVDetector {
private Point screenPosition = new Point(); // Screen position of the mineral
private Rect foundRect = new Rect(); // Found rect

/**
* The wanted AreaScoringMethod
*/
public DogeCV.AreaScoringMethod areaScoringMethod = DogeCV.AreaScoringMethod.MAX_AREA; // Setting to decide to use MaxAreaScorer or PerfectAreaScorer

//Create the default filters and scorers
/**
* The wanted DogeCVFilter
*/
public DogeCVColorFilter yellowFilter = new LeviColorFilter(LeviColorFilter.ColorPreset.YELLOW); //Default Yellow filter

/**
* The wanted RatioScorer
*/
public RatioScorer ratioScorer = new RatioScorer(1.0, 3); // Used to find perfect squares

/**
* The wanted MaxAreaScorer
*/
public MaxAreaScorer maxAreaScorer = new MaxAreaScorer( 0.01); // Used to find largest objects

/**
* The wanted PerfectAreaScorer
*/
public PerfectAreaScorer perfectAreaScorer = new PerfectAreaScorer(5000,0.05); // Used to find objects near a tuned area value

/**
Expand All @@ -56,7 +75,11 @@ public GoldDetector() {
detectorName = "Gold Detector"; // Set the detector name
}


/**
* Processes the input mat
* @param input the mat to process
* @return the processed mat
*/
@Override
public Mat process(Mat input) {

Expand Down Expand Up @@ -116,6 +139,9 @@ public Mat process(Mat input) {

}

/**
* Sets the scorer based on areaScoringMethod
*/
@Override
public void useDefaults() {
addScorer(ratioScorer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,19 @@ public class HoughSilverDetector extends DogeCVDetector {

//The scorer used for this class. Based upon minimizing the standard deviation of color within each mineral,
//I.e, if the region is actually a mineral it should be fairly flat. (Levi is op AF - Alex)
/**
* The scorer, defaulted to ColorDevScorer
*/
public DogeCVScorer stdDevScorer = new ColorDevScorer();

/**
* The sensitivity of the circle detector
*/
public double sensitivity = 1.4; //Sensitivity of circle detector; between about 1.2 and 2.1;

/**
* The minimum distance between circles
*/
public double minDistance = 60; //Adjust with frame size! This is the minimum distance between circles

private Mat workingMat = new Mat(); //The working mat used for internal calculations, single object to avoid memory leak
Expand All @@ -46,6 +56,11 @@ public HoughSilverDetector() {
this.detectorName = "Hough Silver Detector";
}

/**
* Processes the input mat
* @param input the mat to process
* @return the processed mat
*/
@Override
public Mat process(Mat input) {
if(input.channels() < 0 || input.cols() <= 0){
Expand Down Expand Up @@ -105,6 +120,9 @@ public Mat process(Mat input) {
return displayMat;
}

/**
* Adds a ColorDevScorer as a scorer
*/
@Override
public void useDefaults() {
addScorer(stdDevScorer);
Expand Down
Loading