Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to get rgb values for specific pixels "interest points"
Java
for (int i = 0; i <=locations_original.size();i++)
 {

     System.out.println("x,y: " + locations_original.get(i).x + ", " +
     locations_original.get(i).y);
     Double x=locations_original.get(i).x;
     Double y=locations_original.get(i).y;
     int pixel = image.getRGB(x.intValue(),y.intValue());
     printPixelARGB(pixel);
 }


Java
 public static void printPixelARGB(int pixel) {
     int alpha = (pixel >> 24) & 0xff;
     int red = (pixel >> 16) & 0xff;
     int green = (pixel >> 8) & 0xff;
     int blue = (pixel) & 0xff;
     System.out.println("argb: " + alpha + ", " + red + ", " + green + ",
     " + blue);
}


but there is an error in this line
Java
System.out.println("x,y: " + locations_original.get(i).x + ", " +locations_original.get(i).y);


Quote:
as following
Java
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 8, Size: 8
	at java.util.ArrayList.rangeCheck(Unknown Source)
	at java.util.ArrayList.get(Unknown Source)
	at boofcv.ExampleInterestPoint.main(ExampleInterestPoint.java:555)

How can I fix this?

Regards!
Posted

Most likely, the line
Java
for (int i = 0; i <= locations_original.size(); i++)

should be replaced with
Java
for (int i = 0; i < locations_original.size(); i++)

Do I even have to explain why? This is elementary mathematics; and most developers catch this bug from the first glance, at the level of reflexes, because right code is a very common pattern: a range of N elements is indexed from 0 to N−1.

—SA
 
Share this answer
 
Comments
Bebo_1 28-May-14 9:14am    
Thanks!
Sergey Alexandrovich Kryukov 28-May-14 11:53am    
You are very welcome.
Good luck, call again.
—SA
there is a problem in your loop initialization ....
it should be like ....
Java
for (int i = 0; i <locations_original.size();i++){...}
 
Share this answer
 
v2
Comments
Bebo_1 28-May-14 9:14am    
Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900