FTC++
  • Home
  • 📷Vision
    • Introduction
    • AprilTags
    • Bitmaps
    • Custom Algorithms
  • 🔢Data
    • Introduction
    • Moving Average Filter
    • Kalman Filter
    • Sensor Fusion
    • Multi-Variable Kalman Filter
  • 🎮Control Theory
    • Introduction
    • State Space Control
    • Linear Quadratic Regulator
    • Model Predictive Control
    • Odometry
  • 🧊3D Modelling
    • Odometry pods
    • Sensors
    • Turrets
  • 📚Resources
    • Resources
Powered by GitBook
On this page
  1. Vision

Custom Algorithms

continuation of bitmaps

PreviousBitmapsNextIntroduction

Last updated 1 year ago

this is the continuation of Now we want to count the pixels and divide them in 3 areas and find which ones are orange...

 public static int getconepos(List<int[]> rgbValues) {
        String[] possiblePos = {"left", "middle", "right"};
        List<int[]> rgb = rgbValues;
        int size = rgb.size();
        int section = size/3;

        List<Integer> sum = new ArrayList<Integer>(3);
        sum.add(0);
        sum.add(0);
        sum.add(0);
        int indx = 0;

        while(indx < size)
        {
            int[] pixel = rgb.get(indx);
//			System.out.println(pixel[0] + " " + pixel[1] + " " + pixel[2]);
            if(pixel[0] > 145 && pixel[0] < 254 && pixel[1] > 60 && pixel[1] < 127 && pixel[2] >= 0 && pixel[2] <= 20)
            {
                //adds one to the certain section number
                int exSum = sum.get(indx/section);
                exSum++;
                sum.set(indx/section, exSum);
            }
            indx++;
        }

//		System.out.println(sum.get(0) + " " + sum.get(1) + " " + sum.get(2));

        int maxIndx = sum.indexOf(Collections.max(sum));
        if(sum.get(0) == 0 && sum.get(1) == 0 && sum.get(2) == 0)
        {
            System.out.println("Don't fool me! There's no cone there!");
            return -1;
        }
        else
        {
            System.out.println("The cone is in the " + possiblePos[maxIndx] + " position");
        }
        return maxIndx;
    }
}
  1. String[] possiblePos = {"left", "middle", "right"};: This array holds the possible positions of the cone, assuming there are three positions: left, middle, and right.

  2. List<int[]> rgb = rgbValues;: This line creates a new List (rgb) and initializes it with the provided rgbValues list, which contains RGB values of pixels from an image.

  3. int size = rgb.size();: It calculates the total number of RGB values (pixels) in the rgb list.

  4. int section = size/3;: This variable section determines the number of pixels that belong to each possible position (left, middle, right). The size of rgb is divided by 3 because we are assuming three possible positions.

  5. List<Integer> sum = new ArrayList<Integer>(3);: This creates a new List (sum) to store the count of pixels that belong to each possible position (left, middle, right).

  6. sum.add(0); sum.add(0); sum.add(0);: It initializes the sum list with three elements, all set to 0. Each element represents the count of pixels for the corresponding position.

  7. int indx = 0;: This variable indx is used to iterate through the rgb list.

  8. The while loop iterates through all the RGB values in the rgb list.

  9. int[] pixel = rgb.get(indx);: This line retrieves the RGB values of a pixel from the rgb list.

  10. The if condition checks if the RGB values of the pixel fall within specific color ranges, suggesting the presence of a cone. If the conditions are met, it increments the corresponding section's pixel count in the sum list.

  11. After the loop, maxIndx is calculated, which represents the index of the position (left, middle, right) with the highest pixel count in the sum list.

  12. If all pixel counts in the sum list are 0, it indicates that there is no cone detected, and the method returns -1. Otherwise, it prints the detected cone's position and returns the index of the cone's position (maxIndx).

In summary, this method processes RGB values of pixels from an image and determines the position of a cone based on certain color ranges in the RGB values. The position with the highest number of pixels falling within the specified color ranges is considered the cone's position. If no cone is detected, it returns -1.

📷
bitmaps