@@ -0,0 +1,3504 @@
+package com.qualcomm.ftcrobotcontroller.opmodes;%0A%0Aimport android.graphics.Bitmap;%0Aimport android.hardware.Camera;%0A%0Aimport com.qualcomm.robotcore.hardware.DcMotor;%0A%0A/**%0A * TeleOp Mode%0A * %3Cp/%3E%0A * Enables control of the robot via the gamepad%0A */%0Apublic class LinearDetectColor extends LinearOpModeCamera %7B%0A%0A    DcMotor motorRight;%0A    DcMotor motorLeft;%0A%0A    int ds2 = 2;  // additional downsampling of the image%0A    // set to 1 to disable further downsampling%0A%0A    @Override%0A    public void runOpMode() throws InterruptedException %7B%0A        Camera camera;%0A%0A        boolean testCam;%0A%0A        String colorString = %22NONE%22;%0A%0A        // linear OpMode, so could do stuff like this too.%0A        /*%0A        motorLeft = hardwareMap.dcMotor.get(%22motor_1%22);%0A        motorRight = hardwareMap.dcMotor.get(%22motor_2%22);%0A        motorLeft.setDirection(DcMotor.Direction.REVERSE);%0A        */%0A%0A        if (isCameraAvailable()) %7B%0A%0A            setCameraDownsampling(8);%0A            // parameter determines how downsampled you want your images%0A            // 8, 4, 2, or 1.%0A            // higher number is more downsampled, so less resolution but faster%0A            // 1 is original resolution, which is detailed but slow%0A            // must be called before super.init sets up the camera%0A%0A            startCamera();  // can take a while.%0A                            // best started before waitForStart%0A                            // or in a separate thread.%0A%0A            waitForStart();%0A%0A            stopCameraInSecs(30);   // set independent thread to kill the camera%0A                                    // when the mode is done%0A                                    // use 30 for auto, 120 for teleop%0A%0A            // LinearOpMode, so could do stuff like this too.%0A        /*%0A        motorLeft.setPower(1);  // drive forward%0A        motorRight.setPower(1);%0A%0A        sleep(1000);            // for a second.%0A%0A        motorLeft.setPower(0);  // stop drive motors.%0A        motorRight.setPower(0);%0A%0A        sleep(1000);            // wait a second.%0A        */%0A%0A            while (opModeIsActive()) %7B%0A                if (imageReady()) %7B // only do this if an image has been returned from the camera%0A                    int redValue = 0;%0A                    int blueValue = 0;%0A                    int greenValue = 0;%0A%0A                    Bitmap rgbImage;%0A                    rgbImage = convertYuvImageToRgb(yuvImage, width, height, ds2);%0A                    for (int x = 0; x %3C width / ds2; x++) %7B%0A                        for (int y = 0; y %3C height / ds2; y++) %7B%0A                            int pixel = rgbImage.getPixel(x, y);%0A                            redValue += red(pixel);%0A                            blueValue += blue(pixel);%0A                            greenValue += green(pixel);%0A                        %7D%0A                    %7D%0A                    int color = highestColor(redValue, greenValue, blueValue);%0A%0A                    switch (color) %7B%0A                        case 0:%0A                            colorString = %22RED%22;%0A                            break;%0A                        case 1:%0A                            colorString = %22GREEN%22;%0A                            break;%0A                        case 2:%0A                            colorString = %22BLUE%22;%0A                    %7D%0A%0A                %7D else %7B%0A                    colorString = %22NONE%22;%0A                %7D%0A%0A                telemetry.addData(%22Color:%22, %22Color detected is: %22 + colorString);%0A                waitOneHardwareCycle();%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

Create LinearDetectColor.java