Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: FIRST-Tech-Challenge/FtcRobotController
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: MiddletonRobotics/FTCMasquerade2023
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 4 commits
  • 7 files changed
  • 1 contributor

Commits on Sep 13, 2022

  1. Setup repo

    webbgamers committed Sep 13, 2022
    Copy the full SHA
    adaaf6d View commit details
  2. OpenCV test setup

    webbgamers committed Sep 13, 2022
    Copy the full SHA
    2266f05 View commit details
  3. Copy the full SHA
    dbd1c5c View commit details

Commits on Sep 15, 2022

  1. Copy the full SHA
    7296cdb View commit details
Showing with 150 additions and 2 deletions.
  1. +3 −0 .idea/.gitignore
  2. +6 −0 .idea/compiler.xml
  3. +25 −0 .idea/jarRepositories.xml
  4. +9 −0 .idea/misc.xml
  5. +4 −0 TeamCode/build.gradle
  6. +101 −0 TeamCode/src/main/java/org/firstinspires/ftc/teamcode/OpenCVTest.java
  7. +2 −2 build.common.gradle
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions TeamCode/build.gradle
Original file line number Diff line number Diff line change
@@ -23,3 +23,7 @@ dependencies {
implementation project(':FtcRobotController')
annotationProcessor files('lib/OpModeAnnotationProcessor.jar')
}

dependencies {
implementation 'org.openftc:easyopencv:1.5.2'
}
101 changes: 101 additions & 0 deletions TeamCode/src/main/java/org/firstinspires/ftc/teamcode/OpenCVTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package org.firstinspires.ftc.teamcode;

import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.exception.RobotCoreException;
import com.qualcomm.robotcore.hardware.Gamepad;
import com.qualcomm.robotcore.util.ElapsedTime;

import org.firstinspires.ftc.robotcore.external.hardware.camera.WebcamName;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;
import org.openftc.easyopencv.OpenCvCamera;
import org.openftc.easyopencv.OpenCvCameraFactory;
import org.openftc.easyopencv.OpenCvPipeline;

@Autonomous
public class OpenCVTest extends LinearOpMode {
private final ElapsedTime runtime = new ElapsedTime();
private int renderMode = 0;
private Gamepad prevGamepad1 = new Gamepad();

OpenCvCamera webcam;

@Override
public void runOpMode() {
int cameraMonitorViewId = hardwareMap.appContext.getResources().getIdentifier("cameraMonitorViewId", "id", hardwareMap.appContext.getPackageName());
webcam = OpenCvCameraFactory.getInstance().createWebcam(hardwareMap.get(WebcamName.class, "Webcam1"), cameraMonitorViewId);
webcam.openCameraDeviceAsync(new OpenCvCamera.AsyncCameraOpenListener()
{
@Override
public void onOpened()
{
webcam.setViewportRenderer(OpenCvCamera.ViewportRenderer.GPU_ACCELERATED);
webcam.startStreaming(640, 480);
webcam.setPipeline(new ChannelSwitchingPipeline());

waitForStart();

while (opModeIsActive()) {

if (gamepad1.left_bumper && !prevGamepad1.left_bumper) {
renderMode--;
}
if (gamepad1.right_bumper && !prevGamepad1.right_bumper) {
renderMode++;
}

if (renderMode < 0) {
renderMode = 6;
}
else if (renderMode > 6) {
renderMode = 0;
}

try { prevGamepad1.copy(gamepad1); } catch (RobotCoreException ignored) {}
telemetry.addData("Time:", runtime);
telemetry.addData("Render mode:", renderMode);
telemetry.update();
sleep(20);
}
}
@Override
public void onError(int errorCode)
{
telemetry.addData("Error opening camera. Code:", errorCode);
telemetry.update();
}
});
}

class ChannelSwitchingPipeline extends OpenCvPipeline {
Mat redMat = new Mat();
Mat greenMat = new Mat();
Mat blueMat = new Mat();
Mat redThreshMat = new Mat();
Mat greenThreshMat = new Mat();
Mat blueThreshMat = new Mat();

@Override
public Mat processFrame(Mat input) {
Core.extractChannel(input, redMat, 0);
Core.extractChannel(input, greenMat, 1);
Core.extractChannel(input, blueMat, 2);

Imgproc.threshold(redMat, redThreshMat, 100, 255, Imgproc.THRESH_BINARY_INV);
Imgproc.threshold(greenMat, greenThreshMat, 100, 255, Imgproc.THRESH_BINARY_INV);
Imgproc.threshold(blueMat, blueThreshMat, 100, 255, Imgproc.THRESH_BINARY_INV);

switch (renderMode) {
case 1: { return redMat; }
case 2: { return greenMat; }
case 3: { return blueMat; }
case 4: { return redThreshMat; }
case 5: { return greenThreshMat; }
case 6: { return blueThreshMat; }
default: { return input; }
}
}
}
}
4 changes: 2 additions & 2 deletions build.common.gradle
Original file line number Diff line number Diff line change
@@ -94,14 +94,14 @@ android {
signingConfig signingConfigs.release

ndk {
abiFilters "armeabi-v7a", "arm64-v8a"
abiFilters "armeabi-v7a"
}
}
debug {
debuggable true
jniDebuggable true
ndk {
abiFilters "armeabi-v7a", "arm64-v8a"
abiFilters "armeabi-v7a"
}
}
}