Skip to content

Commit

Permalink
Fixed color density maybe
Browse files Browse the repository at this point in the history
  • Loading branch information
acastellar committed Feb 15, 2022
1 parent b16be98 commit 63f4068
Showing 1 changed file with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;
import org.openftc.easyopencv.OpenCvCamera;
import org.openftc.easyopencv.OpenCvCameraFactory;
import org.openftc.easyopencv.OpenCvCameraRotation;
import org.openftc.easyopencv.OpenCvPipeline;
import org.tensorflow.lite.Interpreter;

import java.util.ArrayList;
import java.util.Arrays;

@Autonomous(name = "Color Density", group = "Concept")

Expand Down Expand Up @@ -77,6 +82,7 @@ class ColorDensityPipeline extends OpenCvPipeline
// Constants
private final int threshold = 30;
private final int levelCount = 3;
private final double thresholdConfirm = 0.7;
// Instance Variables
private Telemetry telemetry;

Expand All @@ -102,37 +108,31 @@ public Mat processFrame(Mat input)
// Get image size for splitting the image later.
Size imageSize = thresholdMat.size();

// TO DO: COMBINE BRIGHTNESS DETECTION AND HIGHEST BRIGHTNESS
double brightestValue = 0;
int brightestLevel = 2;
double sum = 0;

//Split the image into 3 parts, and get their brightnesses.
double[] levelBrightnesses = new double[levelCount];
for (int level = 0; level < levelCount; level++) {
Rect rectCrop = new Rect((int)(imageSize.width/levelCount) * level, 0, (int)(imageSize.width/levelCount), (int)imageSize.height);
Rect rectCrop = new Rect((int)(imageSize.width/levelCount) * level, 0, (int)(imageSize.width/levelCount) * (level + 1), (int)imageSize.height);
Mat matCropped = new Mat(thresholdMat, rectCrop);
double brightness = Core.mean(matCropped).val[0];
levelBrightnesses[level] = brightness;
}
telemetry.update();

// Get which one is brightest and how bright.
double brightestValue = 0;
int brightestLevel = 2;
for (int level = 0; level < levelCount; level++) {
if (levelBrightnesses[level] > brightestValue) {
brightestValue = levelBrightnesses[level];
sum += brightness;
if (brightness > brightestValue) {
brightestValue = brightness;
brightestLevel = level;
}
}

telemetry.addData("HIGHEST BRIGHTNESS: ", brightestValue);
telemetry.addData("RESULT: ", brightestLevel);
telemetry.addData("Memory: ",(Runtime.getRuntime().freeMemory())/1048576);

}

// print data
telemetry.addData("Max Color: ", max);
telemetry.addData("Min Color: ", min);
telemetry.addData("Mean Color: ", meanColor);
if (sum * thresholdConfirm < brightestValue) {
telemetry.addData("RESULT: ", brightestLevel);
} else {
telemetry.addData("Failed, with sum:", sum);
telemetry.addData("Failed, with brightest value of:", brightestValue);
telemetry.addData("Failed, brightest level: ", brightestLevel);
}
telemetry.update();

telemetry.update();
System.out.println("Exiting Pipeline");
Expand Down

0 comments on commit 63f4068

Please sign in to comment.