Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8831097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:14:12+00:00 2026-06-14T08:14:12+00:00

I have a problem regarding an actual project using Java, Kinect (OpenNI) and Processing.

  • 0

I have a problem regarding an actual project using Java, Kinect (OpenNI) and Processing.
If I use just Processing and Java everything works fine nothing is stumbling and I get no exceptions.
But if I jail the processing Applet in a JFrame (to solve some problems with the Applet Style of Processing) I got the following problem:

  • Every 3 seconds the kinect images hangs shortly (looks like Java is clearing anything out of the memory using the garbage collector)
  • after 20 seconds the application stops and I get the following error:

    Exception in thread "Animation Thread" java.lang.OutOfMemoryError: Java heap space
    at java.awt.image.DataBufferInt.<init>(Unknown Source)
    at java.awt.image.Raster.createPackedRaster(Unknown Source)
    at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)
    at java.awt.image.BufferedImage.<init>(Unknown Source)
    

Here is my relevant Code regarding the visualization:

public boolean drawGrayscaleImage(){    

    //init PApplet and build JFrame
    GrayscalePApplet grayscalePApplet = new  GrayscalePApplet ();
    grayscalePApplet.init();        
    this.grayscaleJFrame = this.initFrame(grayscalePApplet);

    //Set Uplink for PApplet and begin drawing
    grayscalePApplet.setGraphicP(this);     

    return false;
}

Here the drawing function from the Processing PApplet Class

public void draw(){

    if(graphicP != null){
        //creat the relevant image Buffers for java and Processing
        BufferedImage image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_BYTE_GRAY);           
        PImage pimage = new PImage(image.getWidth(),image.getHeight(),PConstants.ARGB);

        //fill up the databuffer using a converted Kinect Grayscale Image
        DataBufferByte dataBuffer = new DataBufferByte(graphicP.getImage(ImageType.GRAYSCALE), this.imageWidth * this.imageHeight);
        Raster raster = Raster.createPackedRaster(dataBuffer,imageWidth, imageHeight, 8, null);
        image.setData(raster);

        //draw image to Processing
        image.getRGB(0, 0, pimage.width, pimage.height, pimage.pixels, 0, pimage.width);
        pimage.updatePixels();
        image(pimage, 0, 0);

        // null everything to get Garbagecollection to work (?)
        image = null;
        pimage = null;
        dataBuffer = null;
    }
}

How can I prevent that OutOfMemory Exception?
What may causes that exception?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:14:13+00:00Added an answer on June 14, 2026 at 8:14 am

    Since I can’t see the full code, I can’t make an accurate assumption but my guess is the problem is here:

    BufferedImage image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_BYTE_GRAY);           
            PImage pimage = new PImage(image.getWidth(),image.getHeight(),PConstants.ARGB);
    
            //fill up the databuffer using a converted Kinect Grayscale Image
            DataBufferByte dataBuffer = new DataBufferByte(graphicP.getImage(ImageType.GRAYSCALE), this.imageWidth * this.imageHeight);
            Raster raster = Raster.createPackedRaster(dataBuffer,imageWidth, imageHeight, 8, null);
            image.setData(raster);
    

    I’m not sure what Kinect API you’re using (OpenNI/libfreenect), but regardless, you probably shouldn’t create a new Image multiple times per frame( as you do in draw()). Images fill the memory quite quickly and you don’t need multiple images all the time, you simply need two images that you keep updating.
    For example you initialize the images once in setup() and then update the pixels of those images in draw()

    Also, if you’re using Processing I recommend having a look at Kinect Processing wrapper libraries like SimpleOpenNI for OpenNI or dLibs(Win)/OpenKinect for libfreenect. It’s a lot simpler to display the depth image with any of these:

    With SimpleOpenNI:

    import SimpleOpenNI.*;
    
    SimpleOpenNI  ni;
    
    void setup(){
      ni = new SimpleOpenNI(this);
      ni.enableDepth()
      size(ni.depthWidth(), ni.depthHeight()); 
    }
    
    void draw(){
      ni.update();
      image(context.depthImage(),0,0);
    }
    

    With dLibs freenect:

    import dLibs.freenect.toolbox.*;
    import dLibs.freenect.constants.*;
    import dLibs.freenect.interfaces.*;
    import dLibs.freenect.*;
    
    Kinect kinect;                     // main kinect-object
    KinectFrameDepth kinectDepth;     // depth frame
    PImage depthFrame;
    
    void setup(){
      size(640,480);
      kinect = new Kinect(0);
      kinectDepth = new KinectFrameDepth(DEPTH_FORMAT._11BIT_);// create a depth instance
      kinectDepth.connect(kinect);  //connect the created depth instance to the main kinect
      depthFrame = createImage(DEPTH_FORMAT._11BIT_.getWidth(), DEPTH_FORMAT._11BIT_.getHeight(), RGB);
    }
    void draw(){
      assignPixels(depthFrame, kinectDepth);
      image(depthFrame, 0, 0);
    }
    void assignPixels(PImage img, Pixelable kinectDev){
      img.loadPixels();
      img.pixels = kinectDev.getPixels();  // assign pixels of the kinect device to the image
      img.updatePixels();
    }
    void dispose(){
      Kinect.shutDown(); 
      super.dispose();
    }
    

    With OpenKinect P5:

    import org.openkinect.*;
    import org.openkinect.processing.*;
    
    Kinect kinect;
    
    void setup() {
      size(640,480);
      kinect = new Kinect(this);
      kinect.start();
      kinect.enableDepth(true);
    }
    
    void draw() {
      background(0);
      image(kinect.getDepthImage(),0,0);
    }
    
    void stop() {
      kinect.quit();
      super.stop();
    }
    

    It’s up to what OS and what features you need to pick the right Processing wrapper for you.

    simple openni
    SimpleOpenNI sample

    diwi dlibs
    dLibs_freenect

    OpenKinect P5
    OpenKinect P5

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem regarding the datediff MYSQL function, I can use it and
I have a problem regarding the ksoap2. My problem is that the project used
I have a cross-language problem regarding md5 :). I have this code in Java:
I have a problem regarding StartUp Url in WPF. I have a LoginView.xaml and
I have a problem regarding Android App. I have created an application that download
Description: I have a problem regarding DataGridView . I need to show a Client_Name
I have the following code, and i have a problem regarding changing the ringtone
Good day everyone! I have a problem regarding my date. It needs to be
I am new to jQueryMobile. I have one problem regarding fixed headers. I have
I have a simple problem regarding a loop in a Rails controller. Here's the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.