Custom Algorithms
continuation of bitmaps
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;
}
}Last updated