Masters/src/main/java/org/firstinspires/ftc/masters/MultipleCameraCV.java
@RequiresApi(api = Build.VERSION_CODES.N)
        @Override
        public Mat processFrame(Mat input) {
            inputToLAB(input);

//            Declare list of regions
            ArrayList<Mat> region = new ArrayList<Mat>();


//            Put the necessary data from the frame to each region
            for (int i = 0; i<27; i++) {
                region.add(B.submat(new Rect(topLeftPoints.get(i), bottomRightPoints.get(i))));
            }

            ArrayList<Integer> regionAvgs = new ArrayList<Integer>();

            for (int i = 0; i<27; i++) {
                regionAvgs.add((int) Core.mean(region.get(i)).val[0]);
            }

//              This is what displays the rectangles to the camera stream on the drive hub
            for (int i = 0; i<27; i++) {
                Imgproc.rectangle(
                        input, // Buffer to draw on
                        topLeftPoints.get(i), // First point which defines the rectangle
                        bottomRightPoints.get(i), // Second point which defines the rectangle
                        BLUE, // The color the rectangle is drawn in
                        2); // Thickness of the rectangle lines

            }

//            The next several lines determine which region has the highest B average.
            int indexOfMaximumBAvg = 0;
            int maxIndexDistance = 2794;

            for (int i = 0; i<27; i++) {
                if (regionAvgs.get(i) >= regionAvgs.get(indexOfMaximumBAvg)) {
                    indexOfMaximumBAvg = i;
                }
            }

//            Display telemetry
            telemetry.addData("B Averages", regionAvgs);
            telemetry.addData("Index of highest likelihood.", indexOfMaximumBAvg);

//            Fix indexes (Regions are stacked 11 to a row)
//            if (regionAvgs.get(indexOfMaximumBAvg) >= DUCK_PRESENT_THRESHOLD) {
//                if (indexOfMaximumBAvg > 21) {
//                    indexOfMaximumBAvg -= 22;
//                    maxIndexDistance = 0;
//                } else if (indexOfMaximumBAvg > 10) {
//                    indexOfMaximumBAvg -= 11;
//                    maxIndexDistance = 1;
//                } else {
//                    maxIndexDistance = 0;
//                }
//                position = MultipleCameraCV.DuckDeterminationPipeline.DuckPosition.values()[indexOfMaximumBAvg];
//            } else {
//                position = MultipleCameraCV.DuckDeterminationPipeline.DuckPosition.SHRUG_NOISES; // Default enum result. Aptly named
//            }
            List<Integer> nearRow = (List<Integer>) regionAvgs.subList(18,27);
            List<Integer> middleRow = (List<Integer>) regionAvgs.subList(9,18);
            List<Integer> farRow = (List<Integer>) regionAvgs.subList(0,9);



            if (nearRow.stream().mapToInt(v -> v).max().orElseThrow(NoSuchElementException::new) > DUCK_PRESENT_THRESHOLD) {
                indexOfMaximumBAvg = 0;
                for (int i = 0; i<9; i++) {
                    if (nearRow.get(i) >= regionAvgs.get(indexOfMaximumBAvg)) {
                        indexOfMaximumBAvg = i;
                    }
                }
                freightPosition = WarehousePipeline.FreightPosition.values()[indexOfMaximumBAvg];
                freightDistance = WarehousePipeline.FreightLocation.NEAR;
            } else if (middleRow.stream().mapToInt(v -> v).max().orElseThrow(NoSuchElementException::new) > DUCK_PRESENT_THRESHOLD) {
                indexOfMaximumBAvg = 0;
                for (int i = 0; i<9; i++) {
                    if (middleRow.get(i) >= regionAvgs.get(indexOfMaximumBAvg)) {
                        indexOfMaximumBAvg = i;
                    }
                }
                freightPosition = WarehousePipeline.FreightPosition.values()[indexOfMaximumBAvg];
                freightDistance = WarehousePipeline.FreightLocation.MIDDLE;
            } else if (farRow.stream().mapToInt(v -> v).max().orElseThrow(NoSuchElementException::new) > DUCK_PRESENT_THRESHOLD) {
                indexOfMaximumBAvg = 0;
                for (int i = 0; i<9; i++) {
                    if (farRow.get(i) >= regionAvgs.get(indexOfMaximumBAvg)) {
                        indexOfMaximumBAvg = i;
                    }
                }
                freightPosition = WarehousePipeline.FreightPosition.values()[indexOfMaximumBAvg];
                freightDistance = WarehousePipeline.FreightLocation.FAR;
            } else {
                freightPosition = WarehousePipeline.FreightPosition.SHRUG_NOISES;
            }


            telemetry.addData("Freight Position", freightPosition);
            telemetry.addData("Freight Distance", freightDistance);

            telemetry.update();

            return input;
        }
//        Process frame, takes a matrix input and processes it. I still have no idea WHERE this is called, but it is absolutely essential to CV functioning
Process frame, takes a matrix input and processes it. I still have no idea WHERE this is called, but it is absolutely essential to CV functioning
Process frame takes a matrix input and processes it . I still have no idea WHERE this is called but it is absolutely essential to CV functioning
@RequiresApi(api = Build.VERSION_CODES.N)
        @Override
        public Mat processFrame(Mat input) {
            inputToLAB(input);
            ArrayList<Mat> region = new ArrayList<Mat>();
            for (int i = 0; i<27; i++) {
                region.add(B.submat(new Rect(topLeftPoints.get(i), bottomRightPoints.get(i))));
            }
            ArrayList<Integer> regionAvgs = new ArrayList<Integer>();
            for (int i = 0; i<27; i++) {
                regionAvgs.add((int) Core.mean(region.get(i)).val[0]);
            }
            for (int i = 0; i<27; i++) {
                Imgproc.rectangle(
                        input, 
                        topLeftPoints.get(i), 
                        bottomRightPoints.get(i), 
                        BLUE, 
                        2); 
            }
            int indexOfMaximumBAvg = 0;
            int maxIndexDistance = 2794;
            for (int i = 0; i<27; i++) {
                if (regionAvgs.get(i) >= regionAvgs.get(indexOfMaximumBAvg)) {
                    indexOfMaximumBAvg = i;
                }
            }
            telemetry.addData("B Averages", regionAvgs);
            telemetry.addData("Index of highest likelihood.", indexOfMaximumBAvg);
            List<Integer> nearRow = (List<Integer>) regionAvgs.subList(18,27);
            List<Integer> middleRow = (List<Integer>) regionAvgs.subList(9,18);
            List<Integer> farRow = (List<Integer>) regionAvgs.subList(0,9);
            if (nearRow.stream().mapToInt(v -> v).max().orElseThrow(NoSuchElementException::new) > DUCK_PRESENT_THRESHOLD) {
                indexOfMaximumBAvg = 0;
                for (int i = 0; i<9; i++) {
                    if (nearRow.get(i) >= regionAvgs.get(indexOfMaximumBAvg)) {
                        indexOfMaximumBAvg = i;
                    }
                }
                freightPosition = WarehousePipeline.FreightPosition.values()[indexOfMaximumBAvg];
                freightDistance = WarehousePipeline.FreightLocation.NEAR;
            } else if (middleRow.stream().mapToInt(v -> v).max().orElseThrow(NoSuchElementException::new) > DUCK_PRESENT_THRESHOLD) {
                indexOfMaximumBAvg = 0;
                for (int i = 0; i<9; i++) {
                    if (middleRow.get(i) >= regionAvgs.get(indexOfMaximumBAvg)) {
                        indexOfMaximumBAvg = i;
                    }
                }
                freightPosition = WarehousePipeline.FreightPosition.values()[indexOfMaximumBAvg];
                freightDistance = WarehousePipeline.FreightLocation.MIDDLE;
            } else if (farRow.stream().mapToInt(v -> v).max().orElseThrow(NoSuchElementException::new) > DUCK_PRESENT_THRESHOLD) {
                indexOfMaximumBAvg = 0;
                for (int i = 0; i<9; i++) {
                    if (farRow.get(i) >= regionAvgs.get(indexOfMaximumBAvg)) {
                        indexOfMaximumBAvg = i;
                    }
                }
                freightPosition = WarehousePipeline.FreightPosition.values()[indexOfMaximumBAvg];
                freightDistance = WarehousePipeline.FreightLocation.FAR;
            } else {
                freightPosition = WarehousePipeline.FreightPosition.SHRUG_NOISES;
            }
            telemetry.addData("Freight Position", freightPosition);
            telemetry.addData("Freight Distance", freightDistance);
            telemetry.update();
            return input;
        }
@ RequiresApi ( api = Build . VERSION_CODES . N ) @ Override public Mat processFrame ( Mat input ) { inputToLAB ( input ) ; ArrayList < Mat > region = new ArrayList < Mat > ( ) ; for ( int i = 0 ; i < 27 ; i ++ ) { region . add ( B . submat ( new Rect ( topLeftPoints . get ( i ) , bottomRightPoints . get ( i ) ) ) ) ; } ArrayList < Integer > regionAvgs = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < 27 ; i ++ ) { regionAvgs . add ( ( int ) Core . mean ( region . get ( i ) ) . val [ 0 ] ) ; } for ( int i = 0 ; i < 27 ; i ++ ) { Imgproc . rectangle ( input , topLeftPoints . get ( i ) , bottomRightPoints . get ( i ) , BLUE , 2 ) ; } int indexOfMaximumBAvg = 0 ; int maxIndexDistance = 2794 ; for ( int i = 0 ; i < 27 ; i ++ ) { if ( regionAvgs . get ( i ) >= regionAvgs . get ( indexOfMaximumBAvg ) ) { indexOfMaximumBAvg = i ; } } telemetry . addData ( "B Averages" , regionAvgs ) ; telemetry . addData ( "Index of highest likelihood." , indexOfMaximumBAvg ) ; List < Integer > nearRow = ( List < Integer > ) regionAvgs . subList ( 18 , 27 ) ; List < Integer > middleRow = ( List < Integer > ) regionAvgs . subList ( 9 , 18 ) ; List < Integer > farRow = ( List < Integer > ) regionAvgs . subList ( 0 , 9 ) ; if ( nearRow . stream ( ) . mapToInt ( v -> v ) . max ( ) . orElseThrow ( NoSuchElementException :: new ) > DUCK_PRESENT_THRESHOLD ) { indexOfMaximumBAvg = 0 ; for ( int i = 0 ; i < 9 ; i ++ ) { if ( nearRow . get ( i ) >= regionAvgs . get ( indexOfMaximumBAvg ) ) { indexOfMaximumBAvg = i ; } } freightPosition = WarehousePipeline . FreightPosition . values ( ) [ indexOfMaximumBAvg ] ; freightDistance = WarehousePipeline . FreightLocation . NEAR ; } else if ( middleRow . stream ( ) . mapToInt ( v -> v ) . max ( ) . orElseThrow ( NoSuchElementException :: new ) > DUCK_PRESENT_THRESHOLD ) { indexOfMaximumBAvg = 0 ; for ( int i = 0 ; i < 9 ; i ++ ) { if ( middleRow . get ( i ) >= regionAvgs . get ( indexOfMaximumBAvg ) ) { indexOfMaximumBAvg = i ; } } freightPosition = WarehousePipeline . FreightPosition . values ( ) [ indexOfMaximumBAvg ] ; freightDistance = WarehousePipeline . FreightLocation . MIDDLE ; } else if ( farRow . stream ( ) . mapToInt ( v -> v ) . max ( ) . orElseThrow ( NoSuchElementException :: new ) > DUCK_PRESENT_THRESHOLD ) { indexOfMaximumBAvg = 0 ; for ( int i = 0 ; i < 9 ; i ++ ) { if ( farRow . get ( i ) >= regionAvgs . get ( indexOfMaximumBAvg ) ) { indexOfMaximumBAvg = i ; } } freightPosition = WarehousePipeline . FreightPosition . values ( ) [ indexOfMaximumBAvg ] ; freightDistance = WarehousePipeline . FreightLocation . FAR ; } else { freightPosition = WarehousePipeline . FreightPosition . SHRUG_NOISES ; } telemetry . addData ( "Freight Position" , freightPosition ) ; telemetry . addData ( "Freight Distance" , freightDistance ) ; telemetry . update ( ) ; return input ; }
Process frame, takes a matrix input and processes it.
Process frame takes a matrix input and processes it .
//            Declare list of regions //            Put the necessary data from the frame to each region //              This is what displays the rectangles to the camera stream on the drive hub // Buffer to draw on // First point which defines the rectangle // Second point which defines the rectangle // The color the rectangle is drawn in // Thickness of the rectangle lines //            The next several lines determine which region has the highest B average. //            Display telemetry //            Fix indexes (Regions are stacked 11 to a row) //            if (regionAvgs.get(indexOfMaximumBAvg) >= DUCK_PRESENT_THRESHOLD) { //                if (indexOfMaximumBAvg > 21) { //                    indexOfMaximumBAvg -= 22; //                    maxIndexDistance = 0; //                } else if (indexOfMaximumBAvg > 10) { //                    indexOfMaximumBAvg -= 11; //                    maxIndexDistance = 1; //                } else { //                    maxIndexDistance = 0; //                } //                position = MultipleCameraCV.DuckDeterminationPipeline.DuckPosition.values()[indexOfMaximumBAvg]; //            } else { //                position = MultipleCameraCV.DuckDeterminationPipeline.DuckPosition.SHRUG_NOISES; // Default enum result. Aptly named //            }