Skip to content

Commit

Permalink
Merge pull request #22 from Pattonville-Robotics/opencv-fixes
Browse files Browse the repository at this point in the history
OpenCV Updates
  • Loading branch information
greg-bahr authored Nov 29, 2017
2 parents faa31b1 + 2bef2a5 commit cbe60c1
Show file tree
Hide file tree
Showing 8 changed files with 407 additions and 210 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import org.firstinspires.ftc.robotcore.external.navigation.AxesOrder;
import org.firstinspires.ftc.robotcore.external.navigation.VuforiaLocalizer;
import org.pattonvillerobotics.commoncode.robotclasses.opencv.ImageProcessor;
import org.pattonvillerobotics.commoncode.robotclasses.opencv.JewelColorDetector;
import org.pattonvillerobotics.commoncode.robotclasses.opencv.relicrecovery.jewels.JewelAnalysisMode;
import org.pattonvillerobotics.commoncode.robotclasses.opencv.relicrecovery.jewels.JewelColorDetector;
import org.pattonvillerobotics.commoncode.robotclasses.opencv.util.PhoneOrientation;
import org.pattonvillerobotics.commoncode.robotclasses.vuforia.VuforiaNavigation;
import org.pattonvillerobotics.commoncode.robotclasses.vuforia.VuforiaParameters;
Expand All @@ -31,16 +32,22 @@ public class OpenCVTest extends LinearOpMode {
public void runOpMode() throws InterruptedException {
ImageProcessor.initOpenCV(hardwareMap, this);

jewelColorDetector = new JewelColorDetector(PhoneOrientation.PORTRAIT);
jewelColorDetector = new JewelColorDetector(PhoneOrientation.LANDSCAPE_INVERSE, JewelAnalysisMode.FAST, true);
vuforia = new VuforiaNavigation(VUFORIA_PARAMETERS);

JewelColorDetector.Analysis analysis;
JewelColorDetector.AnalysisResult analysis;

long startTime, endTime;

waitForStart();

while (opModeIsActive()) {
startTime = System.currentTimeMillis();
jewelColorDetector.process(vuforia.getImage());
analysis = jewelColorDetector.getAnalysis();
endTime = System.currentTimeMillis();

telemetry.addData("Time: ", endTime - startTime);

telemetry.addData("Left: ", analysis.leftJewelColor);
telemetry.addData("Right: ", analysis.rightJewelColor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;
import org.pattonvillerobotics.commoncode.enums.ColorSensorColor;
import org.pattonvillerobotics.commoncode.robotclasses.opencv.util.Contour;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -51,19 +51,28 @@ public void setHSVBounds(ColorSensorColor color) {
}

public void process(Mat rgbaMat) {
Imgproc.blur(rgbaMat, blurMat, new Size(10, 10));
Imgproc.pyrDown(rgbaMat, blurMat);
Imgproc.pyrDown(blurMat, blurMat);

Imgproc.cvtColor(blurMat, hsvMat, Imgproc.COLOR_RGB2HSV);
Core.inRange(hsvMat, lowerBoundHSV, upperBoundHSV, thresholdMat);
Imgproc.dilate(thresholdMat, thresholdMat, new Mat());

List<MatOfPoint> tmp = new ArrayList<>();

Imgproc.findContours(thresholdMat, tmp, hierarchyMat, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

MatOfPoint largest = Contour.findLargestContour(tmp);
double maxArea = 0;
if (largest != null) {
maxArea = Imgproc.contourArea(largest);
}

// filters out super small contours
contours.clear();
for (MatOfPoint contour : tmp) {
if (Imgproc.contourArea(contour) > 500) {
if (Imgproc.contourArea(contour) > maxArea * .1) {
Core.multiply(contour, new Scalar(4, 4), contour);
contours.add(contour);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public void onManagerConnected(int status) {
}
}

public static boolean isInitialized() {
return initialized;
}

/**
* Converts the Bitmap to a Mat and then rotates the image based off of the phone's orientation.
*
Expand All @@ -88,8 +92,6 @@ public static Mat processBitmap(Bitmap bitmap, PhoneOrientation orientation) {
Mat rotated = new Mat();
Imgproc.warpAffine(tmp, rotated, rotMat, tmp.size());

Log.i("Jewel", "Rotated.");

return rotated;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.pattonvillerobotics.commoncode.robotclasses.opencv.relicrecovery.jewels;

/**
* Created by gregbahr on 11/28/17.
*/

public enum JewelAnalysisMode {
FAST, COMPLEX
}
Loading

0 comments on commit cbe60c1

Please sign in to comment.