Kinect v2 Color Tracking Issue : ArrayIndexOutOfBoundsException

Hi everyone!

I’m currently working on a project to detect and track a color in the kinect image.
However when my program gets to the line:

color currentColor = img.pixels [loc];

It crashes and gives me the following error message:

ArrayIndexOutOfBoundsException: 825032704

I have tried everything and I am really stuck at how to fix this so any advice would be much appreciated. I’ve seen this line of code being used online in many examples so I cannot understand why it won’t work.

Many thanks!

My code is as follows:

import processing.video.*;
import org.openkinect.processing.*;

Kinect2 kinect2;
color trackColor;

void setup() {
  size(526,424);

  kinect2 = new Kinect2(this);
  kinect2.initVideo();
  kinect2.initRegistered();
  kinect2.initDevice();
}

void draw(){
  PImage img = kinect2.getRegisteredImage();
  image(img,0,0);
  int [] depth = kinect2.getRawDepth();
  
  int avgX = 0;
  int avgY = 0;
  int count = 0;
  
   for(int x =0; x <kinect2.depthWidth; x++) {
   for(int y=0; y <kinect2.depthWidth; y++){
     int loc = x +y*kinect2.depthWidth;
     
     color currentColor = img.pixels [loc];

   }
   }
}

I guess you have to same assignment: Video Processing with a Rasperry Pi

You should find the answer there.

Hi there,

thank you for your help!

So just to clarify do you mean that I should load the pixels before entering the for loops and then update the pixels within the loop?

Sorry I currently don’t have my kinect with me to check if this works!

Thanks!

In your case, you are just reading the pixels value so you don’t need to update them but otherwise yes: load the pixels before your for loop.

Hi There,

I added in that function but the program still freezes when I run that line of code.
img.loadPixels();

This is the message that I get in the console:

[Freenect2DeviceImpl] submitting usb transfers...
[RgbPacketStreamParser::onDataReceived] packetsize or sequence doesn't match!
[Freenect2DeviceImpl] started
Device Serial: 502554743142
Device Firmware: 4.3.3916.0.7
[DepthPacketStreamParser::onDataReceived] not all subsequences received 0
[TurboJpegRgbPacketProcessor::doProcess] Failed to decompress rgb image! TurboJPEG error: 'Corrupt JPEG data: premature end of data segment'
[DepthPacketStreamParser::onDataReceived] not all subsequences received 1022
[DepthPacketStreamParser::onDataReceived] not all subsequences received 512
[DepthPacketStreamParser::onDataReceived] not all subsequences received 959
Could not run the sketch (Target VM failed to initialize).
For more information, read revisions.txt and Help ? Troubleshooting.


But that has cleared up the ArrayIndexOutOfBoundsException error.

*****EDIT ***
Actually so I’m getting different error messages in the console each time but theyre something along the lines:

[TurboJpegRgbPacketProcessor::doProcess] Failed to decompress rgb image! TurboJPEG error: 'Corrupt JPEG data: 860 extraneous bytes before marker 0xd5'

or

[TurboJpegRgbPacketProcessor::doProcess] Failed to decompress rgb image! TurboJPEG error: 'Corrupt JPEG data: premature end of data segment'

The ArrayIndexOutOfBoundsException error is still coming up too.